def _assert_version_correct(self, version_line, expected_major, expected_minor, expected_minor_letter): """ Assertion function used by tests in this class """ consumer = VersionConsumer() consumer(version_line) self.assertEqual( consumer.version, Version(expected_major, expected_minor, expected_minor_letter), )
class TestVersion(unittest.TestCase): """ Test the Version class. Test cases = (assert true, assert false) x (with letters, without letters, mixed) x number_of_operations Where number_of_operations = 1 for <, and 2 for <=, etc """ high_version_letter = Version(10, 5, "b") low_version_letter = Version(10, 5, "a") high_version_no_letter = Version(10, 6) low_version_no_letter = Version(10, 5) high_version_letter_for_mixed = Version(10, 6, "") def test_lt(self): # Test with letters self.assertTrue( TestVersion.low_version_letter < TestVersion.high_version_letter) self.assertFalse( TestVersion.high_version_letter < TestVersion.low_version_letter) # Test without letters self.assertTrue(TestVersion.low_version_no_letter < TestVersion.high_version_no_letter) self.assertFalse(TestVersion.high_version_no_letter < TestVersion.low_version_no_letter) # Both self.assertTrue( TestVersion.low_version_letter < TestVersion.high_version_no_letter ) self.assertFalse( TestVersion.high_version_letter < TestVersion.low_version_no_letter ) def test_le(self): # Test equal # Test with letters self.assertTrue( TestVersion.high_version_letter <= TestVersion.high_version_letter) self.assertFalse( TestVersion.high_version_letter <= TestVersion.low_version_letter) # Test without letters self.assertTrue(TestVersion.high_version_no_letter <= TestVersion.high_version_no_letter) self.assertFalse(TestVersion.high_version_no_letter <= TestVersion.low_version_no_letter) # Both self.assertTrue(TestVersion.high_version_letter <= TestVersion.high_version_no_letter) self.assertFalse(TestVersion.high_version_letter <= TestVersion.low_version_no_letter) # Test less than # Test with letters self.assertTrue( TestVersion.low_version_letter <= TestVersion.high_version_letter) self.assertFalse( TestVersion.high_version_letter <= TestVersion.low_version_letter) # Test without letters self.assertTrue(TestVersion.low_version_no_letter <= TestVersion.high_version_no_letter) self.assertFalse(TestVersion.high_version_no_letter <= TestVersion.low_version_no_letter) # Both self.assertTrue(TestVersion.low_version_letter <= TestVersion.high_version_no_letter) self.assertFalse(TestVersion.high_version_letter <= TestVersion.low_version_no_letter) def test_gt(self): # Test with letters self.assertTrue( TestVersion.high_version_letter > TestVersion.low_version_letter) self.assertFalse( TestVersion.low_version_letter > TestVersion.high_version_letter) # Test without letters self.assertTrue(TestVersion.high_version_no_letter > TestVersion.low_version_no_letter) self.assertFalse(TestVersion.low_version_no_letter > TestVersion.high_version_no_letter) # Both self.assertTrue( TestVersion.high_version_letter > TestVersion.low_version_no_letter ) self.assertFalse( TestVersion.low_version_letter > TestVersion.high_version_no_letter ) def test_ge(self): # Test equal # Test with letters self.assertTrue( TestVersion.high_version_letter >= TestVersion.high_version_letter) self.assertFalse( TestVersion.low_version_letter >= TestVersion.high_version_letter) # Test without letters self.assertTrue(TestVersion.high_version_no_letter >= TestVersion.high_version_no_letter) self.assertFalse(TestVersion.low_version_no_letter >= TestVersion.high_version_no_letter) # Both self.assertTrue(TestVersion.high_version_letter_for_mixed >= TestVersion.high_version_no_letter) self.assertFalse(TestVersion.low_version_letter >= TestVersion.high_version_no_letter) # Test greater than # Test with letters self.assertTrue( TestVersion.high_version_letter >= TestVersion.low_version_letter) self.assertFalse( TestVersion.low_version_letter >= TestVersion.high_version_letter) # Test without letters self.assertTrue(TestVersion.high_version_no_letter >= TestVersion.low_version_no_letter) self.assertFalse(TestVersion.low_version_no_letter >= TestVersion.high_version_no_letter) # Both self.assertTrue(TestVersion.high_version_letter >= TestVersion.low_version_no_letter) self.assertFalse(TestVersion.low_version_letter >= TestVersion.high_version_no_letter) def test_eq(self): # Test with letters self.assertTrue( TestVersion.high_version_letter == TestVersion.high_version_letter) self.assertFalse( TestVersion.high_version_letter == TestVersion.low_version_letter) # Test without letters self.assertTrue(TestVersion.high_version_no_letter == TestVersion.high_version_no_letter) self.assertFalse(TestVersion.high_version_no_letter == TestVersion.low_version_no_letter) # Both self.assertTrue(TestVersion.high_version_letter_for_mixed == TestVersion.high_version_no_letter) self.assertFalse(TestVersion.high_version_letter == TestVersion.low_version_no_letter) def test_ne(self): # Test with letters self.assertTrue( TestVersion.high_version_letter != TestVersion.low_version_letter) self.assertFalse( TestVersion.high_version_letter != TestVersion.high_version_letter) # Test without letters self.assertTrue(TestVersion.high_version_no_letter != TestVersion.low_version_no_letter) self.assertFalse(TestVersion.high_version_no_letter != TestVersion.high_version_no_letter) # Both self.assertTrue(TestVersion.high_version_letter != TestVersion.low_version_no_letter) self.assertFalse(TestVersion.high_version_letter_for_mixed != TestVersion.high_version_no_letter)