1
|
|
|
#!/usr/bin/python |
|
|
|
|
2
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
import unittest |
4
|
|
|
|
5
|
|
|
from saucenao.files.constraint import Constraint |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class TestConstraint(unittest.TestCase): |
|
|
|
|
9
|
|
|
""" |
|
|
|
|
10
|
|
|
test cases for the constraints in the files submodule |
11
|
|
|
""" |
12
|
|
|
|
13
|
|
|
def test_constraint(self): |
|
|
|
|
14
|
|
|
"""Test the initializing function of Constraint |
|
|
|
|
15
|
|
|
|
16
|
|
|
:return: |
17
|
|
|
""" |
18
|
|
|
constraint = Constraint(value='Value', cmp_func=self) |
|
|
|
|
19
|
|
|
self.assertEqual(constraint.value, 'Value') |
|
|
|
|
20
|
|
|
self.assertEqual(constraint.cmp_func, self) |
|
|
|
|
21
|
|
|
|
22
|
|
|
def test_value_bigger(self): |
|
|
|
|
23
|
|
|
"""Test compare function cmp_value_bigger |
|
|
|
|
24
|
|
|
|
25
|
|
|
:return: |
26
|
|
|
""" |
27
|
|
|
self.assertEqual(Constraint.cmp_value_bigger(1, 2), False) |
|
|
|
|
28
|
|
|
self.assertEqual(Constraint.cmp_value_bigger(2, 2), False) |
|
|
|
|
29
|
|
|
self.assertEqual(Constraint.cmp_value_bigger(2, 1), True) |
|
|
|
|
30
|
|
|
|
31
|
|
|
def test_value_bigger_or_equal(self): |
|
|
|
|
32
|
|
|
"""Test compare function cmp_value_bigger |
|
|
|
|
33
|
|
|
|
34
|
|
|
:return: |
35
|
|
|
""" |
36
|
|
|
self.assertEqual(Constraint.cmp_value_bigger_or_equal(1, 2), False) |
|
|
|
|
37
|
|
|
self.assertEqual(Constraint.cmp_value_bigger_or_equal(2, 2), True) |
|
|
|
|
38
|
|
|
self.assertEqual(Constraint.cmp_value_bigger_or_equal(2, 1), True) |
|
|
|
|
39
|
|
|
|
40
|
|
|
def test_value_smaller(self): |
|
|
|
|
41
|
|
|
"""Test compare function cmp_value_bigger |
|
|
|
|
42
|
|
|
|
43
|
|
|
:return: |
44
|
|
|
""" |
45
|
|
|
self.assertEqual(Constraint.cmp_value_smaller(1, 2), True) |
|
|
|
|
46
|
|
|
self.assertEqual(Constraint.cmp_value_smaller(2, 2), False) |
|
|
|
|
47
|
|
|
self.assertEqual(Constraint.cmp_value_smaller(2, 1), False) |
|
|
|
|
48
|
|
|
|
49
|
|
|
def test_value_smaller_or_equal(self): |
|
|
|
|
50
|
|
|
"""Test compare function cmp_value_bigger |
|
|
|
|
51
|
|
|
|
52
|
|
|
:return: |
53
|
|
|
""" |
54
|
|
|
self.assertEqual(Constraint.cmp_value_smaller_or_equal(1, 2), True) |
|
|
|
|
55
|
|
|
self.assertEqual(Constraint.cmp_value_smaller_or_equal(2, 2), True) |
|
|
|
|
56
|
|
|
self.assertEqual(Constraint.cmp_value_smaller_or_equal(2, 1), False) |
|
|
|
|
57
|
|
|
|
58
|
|
|
def test_value_equals(self): |
|
|
|
|
59
|
|
|
"""Test compare function cmp_value_bigger |
|
|
|
|
60
|
|
|
|
61
|
|
|
:return: |
62
|
|
|
""" |
63
|
|
|
self.assertEqual(Constraint.cmp_value_equals(1, 2), False) |
|
|
|
|
64
|
|
|
self.assertEqual(Constraint.cmp_value_equals(2, 2), True) |
|
|
|
|
65
|
|
|
self.assertEqual(Constraint.cmp_value_equals(2, 1), False) |
|
|
|
|
66
|
|
|
|
67
|
|
|
def test_value_not_equals(self): |
|
|
|
|
68
|
|
|
"""Test compare function cmp_value_bigger |
|
|
|
|
69
|
|
|
|
70
|
|
|
:return: |
71
|
|
|
""" |
72
|
|
|
self.assertEqual(Constraint.cmp_value_not_equals(1, 2), True) |
|
|
|
|
73
|
|
|
self.assertEqual(Constraint.cmp_value_not_equals(2, 2), False) |
|
|
|
|
74
|
|
|
self.assertEqual(Constraint.cmp_value_not_equals(2, 1), True) |
|
|
|
|
75
|
|
|
|
76
|
|
|
|
77
|
|
|
if __name__ == '__main__': |
78
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestConstraint) |
|
|
|
|
79
|
|
|
unittest.TextTestRunner(verbosity=2).run(suite) |
|
|
|
|
80
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.