Update unit tests for Python 3 only use.

This commit is contained in:
Chris PeBenito 2017-09-19 20:58:03 -04:00
parent 9e9d9fec9d
commit 9fa55c25cb
13 changed files with 49 additions and 101 deletions

View File

@ -16,11 +16,7 @@
# along with SETools. If not, see <http://www.gnu.org/licenses/>.
#
import unittest
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock
from unittest.mock import Mock
from setools import SELinuxPolicy, PermissionMap, TERuletype
from setools.exception import PermissionMapParseError, RuleTypeError, \

View File

@ -16,11 +16,7 @@
# along with SETools. If not, see <http://www.gnu.org/licenses/>.
#
import unittest
try:
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock, patch
from unittest.mock import Mock, patch
from setools.policyrep.default import default_factory, validate_ruletype, validate_default_value, \
validate_default_range, DefaultRuletype, DefaultValue, \

View File

@ -16,11 +16,7 @@
# along with SETools. If not, see <http://www.gnu.org/licenses/>.
#
import unittest
try:
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock, patch
from unittest.mock import Mock, patch
from setools import SELinuxPolicy
from setools.policyrep import qpol

View File

@ -16,11 +16,7 @@
# along with SETools. If not, see <http://www.gnu.org/licenses/>.
#
import unittest
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock
from unittest.mock import Mock
from setools import SELinuxPolicy
from setools.policyrep import qpol

View File

@ -16,11 +16,7 @@
# along with SETools. If not, see <http://www.gnu.org/licenses/>.
#
import unittest
try:
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock, patch
from unittest.mock import Mock, patch
from setools import MLSRuletype as MRT
from setools.policyrep.qpol import qpol_policy_t, qpol_range_trans_t

View File

@ -16,11 +16,7 @@
# along with SETools. If not, see <http://www.gnu.org/licenses/>.
#
import unittest
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock
from unittest.mock import Mock
from setools import SELinuxPolicy
from setools.policyrep import qpol
@ -71,11 +67,11 @@ class CommonTest(unittest.TestCase):
def test_030_statment(self):
"""Common: statement."""
com = self.mock_common("test30", ["perm1", "perm2"])
self.assertRegexpMatches(com.statement(), "("
"common test30\n{\n\tperm1\n\tperm2\n}"
"|"
"common test30\n{\n\tperm2\n\tperm1\n}"
")")
self.assertRegex(com.statement(), "("
"common test30\n{\n\tperm1\n\tperm2\n}"
"|"
"common test30\n{\n\tperm2\n\tperm1\n}"
")")
def test_040_contains(self):
"""Common: contains"""
@ -137,29 +133,29 @@ class ObjClassTest(unittest.TestCase):
def test_030_statment(self):
"""ObjClass: statement, no common."""
cls = self.mock_class("test30", ["perm1", "perm2"])
self.assertRegexpMatches(cls.statement(), "("
"class test30\n{\n\tperm1\n\tperm2\n}"
"|"
"class test30\n{\n\tperm2\n\tperm1\n}"
")")
self.assertRegex(cls.statement(), "("
"class test30\n{\n\tperm1\n\tperm2\n}"
"|"
"class test30\n{\n\tperm2\n\tperm1\n}"
")")
def test_031_statment(self):
"""ObjClass: statement, with common."""
cls = self.mock_class("test31", ["perm1", "perm2"], com_perms=["perm3", "perm4"])
self.assertRegexpMatches(cls.statement(), "("
"class test31\ninherits test31_common\n{\n\tperm1\n\tperm2\n}"
"|"
"class test31\ninherits test31_common\n{\n\tperm2\n\tperm1\n}"
")")
self.assertRegex(cls.statement(), "("
"class test31\ninherits test31_common\n{\n\tperm1\n\tperm2\n}"
"|"
"class test31\ninherits test31_common\n{\n\tperm2\n\tperm1\n}"
")")
def test_032_statment(self):
"""ObjClass: statement, with common, no class perms."""
cls = self.mock_class("test32", [], com_perms=["perm3", "perm4"])
self.assertRegexpMatches(cls.statement(), "("
"class test32\ninherits test32_common"
"|"
"class test32\ninherits test32_common"
")")
self.assertRegex(cls.statement(), "("
"class test32\ninherits test32_common"
"|"
"class test32\ninherits test32_common"
")")
def test_040_contains(self):
"""ObjClass: contains"""

View File

@ -16,11 +16,7 @@
# along with SETools. If not, see <http://www.gnu.org/licenses/>.
#
import unittest
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock
from unittest.mock import Mock
from setools.policyrep import qpol
from setools.policyrep.polcap import polcap_factory

View File

@ -16,11 +16,7 @@
# along with SETools. If not, see <http://www.gnu.org/licenses/>.
#
import unittest
try:
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock, patch
from unittest.mock import Mock, patch
from setools.policyrep.qpol import qpol_policy_t, qpol_role_allow_t, qpol_role_trans_t
from setools.policyrep.rbacrule import rbac_rule_factory, validate_ruletype, RBACRuletype

View File

@ -16,11 +16,7 @@
# along with SETools. If not, see <http://www.gnu.org/licenses/>.
#
import unittest
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock
from unittest.mock import Mock
from setools import SELinuxPolicy
from setools.policyrep import qpol

View File

@ -17,11 +17,7 @@
#
import copy
import unittest
try:
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock, patch
from unittest.mock import Mock, patch
from setools import SELinuxPolicy
from setools.policyrep import qpol

View File

@ -16,11 +16,7 @@
# along with SETools. If not, see <http://www.gnu.org/licenses/>.
#
import unittest
try:
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock, patch
from unittest.mock import Mock, patch
from setools import SELinuxPolicy
from setools.policyrep.qpol import qpol_policy_t, qpol_avrule_t, qpol_terule_t, \
@ -130,11 +126,11 @@ class AVRuleTest(unittest.TestCase):
rule = self.mock_avrule_factory("allow", "a", "b", "c", ['d1', 'd2'])
# permissions are stored in a set, so the order may vary
self.assertRegexpMatches(rule.statement(), "("
"allow a b:c { d1 d2 };"
"|"
"allow a b:c { d2 d1 };"
")")
self.assertRegex(rule.statement(), "("
"allow a b:c { d1 d2 };"
"|"
"allow a b:c { d2 d1 };"
")")
def test_102_statement_one_perm_cond(self):
"""AVRule statement, one permission, conditional."""
@ -146,11 +142,11 @@ class AVRuleTest(unittest.TestCase):
rule = self.mock_avrule_factory("allow", "a", "b", "c", ['d1', 'd2'], cond="cond103")
# permissions are stored in a set, so the order may vary
self.assertRegexpMatches(rule.statement(), "("
"allow a b:c { d1 d2 }; \[ cond103 ]"
"|"
"allow a b:c { d2 d1 }; \[ cond103 ]"
")")
self.assertRegex(rule.statement(), "("
"allow a b:c { d1 d2 }; \[ cond103 ]"
"|"
"allow a b:c { d2 d1 }; \[ cond103 ]"
")")
@patch('setools.policyrep.boolcond.condexpr_factory', lambda x, y: y)

View File

@ -16,11 +16,7 @@
# along with SETools. If not, see <http://www.gnu.org/licenses/>.
#
import unittest
try:
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock, patch
from unittest.mock import Mock, patch
from setools import SELinuxPolicy
from setools.policyrep import qpol

View File

@ -16,11 +16,7 @@
# along with SETools. If not, see <http://www.gnu.org/licenses/>.
#
import unittest
try:
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock, patch
from unittest.mock import Mock, patch
from setools import SELinuxPolicy
from setools.policyrep import qpol
@ -82,11 +78,11 @@ class UserTest(unittest.TestCase):
with patch('setools.policyrep.mls.enabled', return_value=False):
user = self.mock_user_factory("username", ['role20_r', 'role21a_r'])
# roles are stored in a set, so the role order may vary
self.assertRegexpMatches(user.statement(), "("
"user username roles { role20_r role21a_r };"
"|"
"user username roles { role21a_r role20_r };"
")")
self.assertRegex(user.statement(), "("
"user username roles { role20_r role21a_r };"
"|"
"user username roles { role21a_r role20_r };"
")")
def test_022_statement_one_role_mls(self):
"""User statement, one role, MLS."""
@ -98,7 +94,7 @@ class UserTest(unittest.TestCase):
user = self.mock_user_factory("username", ['role20_r', 'role21a_r'],
level="s0", range_="s0 - s2")
# roles are stored in a set, so the role order may vary
self.assertRegexpMatches(
self.assertRegex(
user.statement(), "("
"user username roles { role20_r role21a_r } level s0 range s0 - s2;"
"|"