def test_valid_three_segments(self): for version in (Version(3, 11, 8), Version('3.11.8')): self.assertEqual("3.11.8", str(version)) self.assertEqual(3, version[0]) self.assertEqual(11, version[1]) self.assertEqual(8, version[2]) self.assertRaises(IndexError, version.__getitem__, 3)
def test_valid_four_segments(self): for version in (Version(7, 1, 26, 5), Version('7.1.26.5')): self.assertEqual("7.1.26.5", str(version)) self.assertEqual(7, version[0]) self.assertEqual(1, version[1]) self.assertEqual(26, version[2]) self.assertEqual(5, version[3]) self.assertRaises(IndexError, version.__getitem__, 4)
def test_lt_incompatible(self): if sys.version_info[0] < 3: # The complex type seems to have a comparison that does not raise a # TypeError exception and instead returns an actual boolean value # in Python 2 (complex instance less than any Version, it seems). self.assertFalse(Version(7, 5, 2) < complex(7.6, 2)) else: self.assertRaises(TypeError, operator.lt, Version(7, 5, 2), complex(7.6, 2))
def test_invalid_replacement_nonexistent(self): version = Version(1, 2, 3) self.assertRaises(KeyError, version.replace, something=8) self.assertEqual(1, version[0]) self.assertEqual(2, version[1]) self.assertEqual(3, version[2]) self.assertRaises(IndexError, version.__getitem__, 3)
def test_invalid_replacement_extra(self): version = Version(1, 2, 3) self.assertRaises(IndexError, version.replace, _0=5, _1=6, _2=7, _3=8) self.assertEqual(1, version[0]) self.assertEqual(2, version[1]) self.assertEqual(3, version[2]) self.assertRaises(IndexError, version.__getitem__, 3)
def test_lt_different_segment_definitions(self): class Version1(Version): SEGMENT_DEFINITIONS = (SegmentDefinition(default=1), ) version = Version(7) version1 = Version1(8) self.assertLess(version, version1) self.assertFalse(version1 < version) version1 = Version1(7) self.assertFalse(version < version1) self.assertFalse(version1 < version)
def test_eq_different_segment_definitions(self): class Version1(Version): SEGMENT_DEFINITIONS = (SegmentDefinition(default=1), ) self.assertEqual(Version(7), Version1(7))
def test_eq_incompatible(self): self.assertNotEqual(Version(8, 13, 21), complex(8.13, 21))
def test_eq_float(self): self.assertEqual(Version(8, 13), 8.13)
def test_eq_string(self): self.assertEqual(Version(8, 13, 21), '8.13.21')
def test_valid_two_segments(self): for version in (Version(8, 2), Version('8.2')): self.assertEqual("8.2", str(version)) self.assertEqual(8, version[0]) self.assertEqual(2, version[1]) self.assertRaises(IndexError, version.__getitem__, 2)
def test_lt_string(self): self.assertLess(Version(8, 13, 21), '8.2db')
def test_init_value_string_parsed(self): version = Version('1.2.3') self.assertEqual(1, version[0])
def test_valid_replacement_partial(self): version = Version(3, 11, 8) self.assertEqual("3.11.8", str(version)) version = version.replace(_1=735) self.assertEqual("3.735.8", str(version))
def test_valid_replacement(self): version = Version(3, 11, 8) self.assertEqual("3.11.8", str(version)) version = version.replace(_0=4, _1=735, _2=29) self.assertEqual("4.735.29", str(version))
def test_ne_value(self): self.assertNotEqual(Version(1), Version(2))
def test_lt_value(self): self.assertLess(Version(1), Version(2))
def test_invalid_attribute(self): version = Version(1, 2, 3) # Version objects are immutable and have no __dict__. self.assertRaises(AttributeError, getattr, version, '__dict__') self.assertRaises(AttributeError, setattr, version, 'nonexistent_attribute', 0)
def test_lt_float(self): self.assertLess(Version(8, 13), 9.0)
def test_repr(self): expected = 'verschemes.Version(3, 5, 8, 13)' self.assertEqual(expected, repr(Version(3, 5, 8, 13))) self.assertEqual(expected, repr(Version('3.5.8.13')))
def test_eq(self): self.assertEqual(Version(8, 13, 21), Version(8, 13, 21))
def test_valid_one_segment(self): for version in (Version(4), Version('4')): self.assertEqual("4", str(version)) self.assertEqual(4, version[0]) self.assertRaises(IndexError, version.__getitem__, 1) self.assertRaises(IndexError, version.__getitem__, 2)