diff options
Diffstat (limited to 'ipatests/test_ipapython/test_ipautil.py')
-rw-r--r-- | ipatests/test_ipapython/test_ipautil.py | 178 |
1 files changed, 91 insertions, 87 deletions
diff --git a/ipatests/test_ipapython/test_ipautil.py b/ipatests/test_ipapython/test_ipautil.py index ec9a3c947..50d5fe834 100644 --- a/ipatests/test_ipapython/test_ipautil.py +++ b/ipatests/test_ipapython/test_ipautil.py @@ -22,7 +22,6 @@ Test the `ipapython/ipautil.py` module. """ -import nose import pytest import six import tempfile @@ -32,6 +31,11 @@ from ipapython import ipautil pytestmark = pytest.mark.tier0 +def assert_equal(a, b): + __tracebackhide__ = True + assert a == b + + @pytest.mark.parametrize("addr,words,prefixlen", [ ('0.0.0.0/0', None, None), ('10.11.12.13', (10, 11, 12, 13), 8), @@ -92,30 +96,30 @@ class TestCIDict(object): assert dict(cidict.items()) == {'a': 2, 'b': 3, 'C': 4} def test_len(self): - nose.tools.assert_equal(3, len(self.cidict)) + assert_equal(3, len(self.cidict)) def test_getitem(self): - nose.tools.assert_equal("val1", self.cidict["Key1"]) - nose.tools.assert_equal("val1", self.cidict["key1"]) - nose.tools.assert_equal("val2", self.cidict["KEY2"]) - nose.tools.assert_equal("VAL3", self.cidict["key3"]) - nose.tools.assert_equal("VAL3", self.cidict["KEY3"]) - with nose.tools.assert_raises(KeyError): + assert_equal("val1", self.cidict["Key1"]) + assert_equal("val1", self.cidict["key1"]) + assert_equal("val2", self.cidict["KEY2"]) + assert_equal("VAL3", self.cidict["key3"]) + assert_equal("VAL3", self.cidict["KEY3"]) + with pytest.raises(KeyError): self.cidict["key4"] # pylint: disable=pointless-statement def test_get(self): - nose.tools.assert_equal("val1", self.cidict.get("Key1")) - nose.tools.assert_equal("val1", self.cidict.get("key1")) - nose.tools.assert_equal("val2", self.cidict.get("KEY2")) - nose.tools.assert_equal("VAL3", self.cidict.get("key3")) - nose.tools.assert_equal("VAL3", self.cidict.get("KEY3")) - nose.tools.assert_equal("default", self.cidict.get("key4", "default")) + assert_equal("val1", self.cidict.get("Key1")) + assert_equal("val1", self.cidict.get("key1")) + assert_equal("val2", self.cidict.get("KEY2")) + assert_equal("VAL3", self.cidict.get("key3")) + assert_equal("VAL3", self.cidict.get("KEY3")) + assert_equal("default", self.cidict.get("key4", "default")) def test_setitem(self): self.cidict["key4"] = "val4" - nose.tools.assert_equal("val4", self.cidict["key4"]) + assert_equal("val4", self.cidict["key4"]) self.cidict["KEY4"] = "newval4" - nose.tools.assert_equal("newval4", self.cidict["key4"]) + assert_equal("newval4", self.cidict["key4"]) def test_del(self): assert "Key1" in self.cidict @@ -127,9 +131,9 @@ class TestCIDict(object): assert "key2" not in self.cidict def test_clear(self): - nose.tools.assert_equal(3, len(self.cidict)) + assert_equal(3, len(self.cidict)) self.cidict.clear() - nose.tools.assert_equal(0, len(self.cidict)) + assert_equal(0, len(self.cidict)) assert self.cidict == {} assert list(self.cidict) == [] assert list(self.cidict.values()) == [] @@ -143,10 +147,10 @@ class TestCIDict(object): def test_copy(self): copy = self.cidict.copy() assert copy == self.cidict - nose.tools.assert_equal(3, len(copy)) + assert_equal(3, len(copy)) assert "Key1" in copy assert "key1" in copy - nose.tools.assert_equal("val1", copy["Key1"]) + assert_equal("val1", copy["Key1"]) @pytest.mark.skipif(not six.PY2, reason="Python 2 only") def test_haskey(self): @@ -165,7 +169,7 @@ class TestCIDict(object): def test_items(self): items = list(self.cidict.items()) - nose.tools.assert_equal(3, len(items)) + assert_equal(3, len(items)) items_set = set(items) assert ("Key1", "val1") in items_set assert ("key2", "val2") in items_set @@ -182,7 +186,7 @@ class TestCIDict(object): items = [] for (k,v) in self.cidict.iteritems(): items.append((k,v)) - nose.tools.assert_equal(3, len(items)) + assert_equal(3, len(items)) items_set = set(items) assert ("Key1", "val1") in items_set assert ("key2", "val2") in items_set @@ -192,7 +196,7 @@ class TestCIDict(object): keys = [] for k in self.cidict.iterkeys(): keys.append(k) - nose.tools.assert_equal(3, len(keys)) + assert_equal(3, len(keys)) keys_set = set(keys) assert "Key1" in keys_set assert "key2" in keys_set @@ -202,7 +206,7 @@ class TestCIDict(object): values = [] for k in self.cidict.itervalues(): values.append(k) - nose.tools.assert_equal(3, len(values)) + assert_equal(3, len(values)) values_set = set(values) assert "val1" in values_set assert "val2" in values_set @@ -210,7 +214,7 @@ class TestCIDict(object): def test_keys(self): keys = list(self.cidict.keys()) - nose.tools.assert_equal(3, len(keys)) + assert_equal(3, len(keys)) keys_set = set(keys) assert "Key1" in keys_set assert "key2" in keys_set @@ -220,7 +224,7 @@ class TestCIDict(object): def test_values(self): values = list(self.cidict.values()) - nose.tools.assert_equal(3, len(values)) + assert_equal(3, len(values)) values_set = set(values) assert "val1" in values_set assert "val2" in values_set @@ -232,10 +236,10 @@ class TestCIDict(object): newdict = { "KEY2": "newval2", "key4": "val4" } self.cidict.update(newdict) - nose.tools.assert_equal(4, len(self.cidict)) + assert_equal(4, len(self.cidict)) items = list(self.cidict.items()) - nose.tools.assert_equal(4, len(items)) + assert_equal(4, len(items)) items_set = set(items) assert ("Key1", "val1") in items_set # note the update "overwrites" the case of the key2 @@ -256,15 +260,15 @@ class TestCIDict(object): 'Key1': 'val1', 'key2': 'val2', 'KEY3': 'VAL3'} def test_update_duplicate_values_dict(self): - with nose.tools.assert_raises(ValueError): + with pytest.raises(ValueError): self.cidict.update({'a': 'va', 'A': None, 'b': 3}) def test_update_duplicate_values_list(self): - with nose.tools.assert_raises(ValueError): + with pytest.raises(ValueError): self.cidict.update([('a', 'va'), ('A', None), ('b', 3)]) def test_update_duplicate_values_kwargs(self): - with nose.tools.assert_raises(ValueError): + with pytest.raises(ValueError): self.cidict.update(a='va', A=None, b=3) def test_update_kwargs(self): @@ -273,45 +277,45 @@ class TestCIDict(object): 'b': 'vb', 'Key1': 'val1', 'key2': 'val2', 'KEY3': 'VAL3'} def test_setdefault(self): - nose.tools.assert_equal("val1", self.cidict.setdefault("KEY1", "default")) + assert_equal("val1", self.cidict.setdefault("KEY1", "default")) assert "KEY4" not in self.cidict - nose.tools.assert_equal("default", self.cidict.setdefault("KEY4", "default")) + assert_equal("default", self.cidict.setdefault("KEY4", "default")) assert "KEY4" in self.cidict - nose.tools.assert_equal("default", self.cidict["key4"]) + assert_equal("default", self.cidict["key4"]) assert "KEY5" not in self.cidict - nose.tools.assert_equal(None, self.cidict.setdefault("KEY5")) + assert_equal(None, self.cidict.setdefault("KEY5")) assert "KEY5" in self.cidict - nose.tools.assert_equal(None, self.cidict["key5"]) + assert_equal(None, self.cidict["key5"]) def test_pop(self): - nose.tools.assert_equal("val1", self.cidict.pop("KEY1", "default")) + assert_equal("val1", self.cidict.pop("KEY1", "default")) assert "key1" not in self.cidict - nose.tools.assert_equal("val2", self.cidict.pop("KEY2")) + assert_equal("val2", self.cidict.pop("KEY2")) assert "key2" not in self.cidict - nose.tools.assert_equal("default", self.cidict.pop("key4", "default")) - with nose.tools.assert_raises(KeyError): + assert_equal("default", self.cidict.pop("key4", "default")) + with pytest.raises(KeyError): self.cidict.pop("key4") def test_popitem(self): items = set(self.cidict.items()) - nose.tools.assert_equal(3, len(self.cidict)) + assert_equal(3, len(self.cidict)) item = self.cidict.popitem() - nose.tools.assert_equal(2, len(self.cidict)) + assert_equal(2, len(self.cidict)) assert item in items items.discard(item) item = self.cidict.popitem() - nose.tools.assert_equal(1, len(self.cidict)) + assert_equal(1, len(self.cidict)) assert item in items items.discard(item) item = self.cidict.popitem() - nose.tools.assert_equal(0, len(self.cidict)) + assert_equal(0, len(self.cidict)) assert item in items items.discard(item) @@ -326,55 +330,55 @@ class TestTimeParser(object): timestr = "20070803" time = ipautil.parse_generalized_time(timestr) - nose.tools.assert_equal(2007, time.year) - nose.tools.assert_equal(8, time.month) - nose.tools.assert_equal(3, time.day) - nose.tools.assert_equal(0, time.hour) - nose.tools.assert_equal(0, time.minute) - nose.tools.assert_equal(0, time.second) + assert_equal(2007, time.year) + assert_equal(8, time.month) + assert_equal(3, time.day) + assert_equal(0, time.hour) + assert_equal(0, time.minute) + assert_equal(0, time.second) def test_hour_min_sec(self): timestr = "20051213141205" time = ipautil.parse_generalized_time(timestr) - nose.tools.assert_equal(2005, time.year) - nose.tools.assert_equal(12, time.month) - nose.tools.assert_equal(13, time.day) - nose.tools.assert_equal(14, time.hour) - nose.tools.assert_equal(12, time.minute) - nose.tools.assert_equal(5, time.second) + assert_equal(2005, time.year) + assert_equal(12, time.month) + assert_equal(13, time.day) + assert_equal(14, time.hour) + assert_equal(12, time.minute) + assert_equal(5, time.second) def test_fractions(self): timestr = "2003092208.5" time = ipautil.parse_generalized_time(timestr) - nose.tools.assert_equal(2003, time.year) - nose.tools.assert_equal(9, time.month) - nose.tools.assert_equal(22, time.day) - nose.tools.assert_equal(8, time.hour) - nose.tools.assert_equal(30, time.minute) - nose.tools.assert_equal(0, time.second) + assert_equal(2003, time.year) + assert_equal(9, time.month) + assert_equal(22, time.day) + assert_equal(8, time.hour) + assert_equal(30, time.minute) + assert_equal(0, time.second) timestr = "199203301544,25" time = ipautil.parse_generalized_time(timestr) - nose.tools.assert_equal(1992, time.year) - nose.tools.assert_equal(3, time.month) - nose.tools.assert_equal(30, time.day) - nose.tools.assert_equal(15, time.hour) - nose.tools.assert_equal(44, time.minute) - nose.tools.assert_equal(15, time.second) + assert_equal(1992, time.year) + assert_equal(3, time.month) + assert_equal(30, time.day) + assert_equal(15, time.hour) + assert_equal(44, time.minute) + assert_equal(15, time.second) timestr = "20060401185912,8" time = ipautil.parse_generalized_time(timestr) - nose.tools.assert_equal(2006, time.year) - nose.tools.assert_equal(4, time.month) - nose.tools.assert_equal(1, time.day) - nose.tools.assert_equal(18, time.hour) - nose.tools.assert_equal(59, time.minute) - nose.tools.assert_equal(12, time.second) - nose.tools.assert_equal(800000, time.microsecond) + assert_equal(2006, time.year) + assert_equal(4, time.month) + assert_equal(1, time.day) + assert_equal(18, time.hour) + assert_equal(59, time.minute) + assert_equal(12, time.second) + assert_equal(800000, time.microsecond) def test_time_zones(self): # pylint: disable=no-member @@ -382,36 +386,36 @@ class TestTimeParser(object): timestr = "20051213141205Z" time = ipautil.parse_generalized_time(timestr) - nose.tools.assert_equal(0, time.tzinfo.houroffset) - nose.tools.assert_equal(0, time.tzinfo.minoffset) + assert_equal(0, time.tzinfo.houroffset) + assert_equal(0, time.tzinfo.minoffset) offset = time.tzinfo.utcoffset(time.tzinfo.dst()) - nose.tools.assert_equal(0, offset.seconds) + assert_equal(0, offset.seconds) timestr = "20051213141205+0500" time = ipautil.parse_generalized_time(timestr) - nose.tools.assert_equal(5, time.tzinfo.houroffset) - nose.tools.assert_equal(0, time.tzinfo.minoffset) + assert_equal(5, time.tzinfo.houroffset) + assert_equal(0, time.tzinfo.minoffset) offset = time.tzinfo.utcoffset(time.tzinfo.dst()) - nose.tools.assert_equal(5 * 60 * 60, offset.seconds) + assert_equal(5 * 60 * 60, offset.seconds) timestr = "20051213141205-0500" time = ipautil.parse_generalized_time(timestr) - nose.tools.assert_equal(-5, time.tzinfo.houroffset) - nose.tools.assert_equal(0, time.tzinfo.minoffset) + assert_equal(-5, time.tzinfo.houroffset) + assert_equal(0, time.tzinfo.minoffset) # NOTE - the offset is always positive - it's minutes # _east_ of UTC offset = time.tzinfo.utcoffset(time.tzinfo.dst()) - nose.tools.assert_equal((24 - 5) * 60 * 60, offset.seconds) + assert_equal((24 - 5) * 60 * 60, offset.seconds) timestr = "20051213141205-0930" time = ipautil.parse_generalized_time(timestr) - nose.tools.assert_equal(-9, time.tzinfo.houroffset) - nose.tools.assert_equal(-30, time.tzinfo.minoffset) + assert_equal(-9, time.tzinfo.houroffset) + assert_equal(-30, time.tzinfo.minoffset) offset = time.tzinfo.utcoffset(time.tzinfo.dst()) - nose.tools.assert_equal(((24 - 9) * 60 * 60) - (30 * 60), offset.seconds) + assert_equal(((24 - 9) * 60 * 60) - (30 * 60), offset.seconds) def test_run(): |