Пример #1
0
def main():
    try:
        parser = argparse.ArgumentParser()
        parser.add_argument('-v1', help='version 1')
        parser.add_argument('-v2', help='version 2')
        args = parser.parse_args()
        print(compare(args.v1, args.v2))
    except Exception:
        raise parser.error('Invalid arguments')
Пример #2
0
 def test_non_digit_input(self):
     with self.assertRaises(ValueError):
         compare('1.2.3', '1.2.#')
Пример #3
0
 def test_non_string_input(self):
     with self.assertRaises(TypeError):
         compare('1.2', 1.2)
Пример #4
0
 def test_diff_len_greater_with_space(self):
     self.assertEqual(compare(' 1.2.4.4 ', '1.2.3.4 '), 1)
Пример #5
0
 def test_diff_len_equal_with_space(self):
     self.assertEqual(compare(' 1.2.3.4 ', '1.2.3.4 '), 0)
Пример #6
0
 def test_diff_len_less_wish_space(self):
     self.assertEqual(compare(' 1.2.3.4 ', '1.2.4.4 '), -1)
Пример #7
0
 def test_diff_len_greater(self):
     self.assertEqual(compare('1.2.4', '1.2.3.4'), 1)
Пример #8
0
 def test_diff_len_equal(self):
     self.assertEqual(compare('1.2.3.0', '1.2.3'), 0)
Пример #9
0
 def test_diff_len_less(self):
     self.assertEqual(compare('1.2.3.4', '1.2.4'), -1)
Пример #10
0
 def test_same_len_greater(self):
     self.assertEqual(compare('1.2.4', '1.2.3'), 1)
Пример #11
0
 def test_same_len_equal(self):
     self.assertEqual(compare('1.2.3', '1.2.3'), 0)
Пример #12
0
 def test_same_len_less(self):
     self.assertEqual(compare('1.2.3', '1.2.4'), -1)
Пример #13
0
 def test_greater(self):
     v1, v2 = 4.5, 3.4
     self.assertEqual(
         compare(v1, v2),
         'version {} is greater than version {}'.format(v1, v2))
Пример #14
0
 def test_conv_ver_str(self):
     v1, v2 = '1.2', '2.3'
     self.assertEqual(compare(v1, v2),
                      'version {} is less than version {}'.format(1.2, 2.3))
Пример #15
0
 def test_equal(self):
     v1, v2 = 1.0, 1.0
     self.assertEqual(compare(v1, v2),
                      'version {} is equal to version {}'.format(v1, v2))
Пример #16
0
 def test_less_than(self):
     v1, v2 = 2.5, 4.4
     self.assertEqual(compare(v1, v2),
                      'version {} is less than version {}'.format(v1, v2))