Пример #1
0
 def test_is_triplet(self):
     res = Check([1, 2, 3]).is_triplet()
     self.assertIsInstance(res, Check)
     res2 = Check({'a': 1, 'b': 2, 'c': 3}).is_triplet()
     self.assertIsInstance(res, Check)
     with self.assertRaises(CheckError):
         Check([1, 2]).is_triplet()
Пример #2
0
    def test_is_number(self):
        # ints
        val = 123
        res = Check(val).is_number()
        self.assertIsInstance(res, Check)

        # floats
        val = float(123)
        res = Check(val).is_number()
        self.assertIsInstance(res, Check)

        # complexes
        val = complex(33.44, 55.66)
        res = Check(val).is_number()
        self.assertIsInstance(res, Check)

        # test failure
        val = 'not-a-number'
        self.assertTrue(
            all([not isinstance(val, kls) for kls in Check.NUMERIC_TYPES]))
        try:
            Check(val).is_number()
            self.fail()
        except CheckError:
            pass
Пример #3
0
 def test_is_couple(self):
     res = Check([1, 2]).is_couple()
     self.assertIsInstance(res, Check)
     res2 = Check(('1', '2')).is_couple()
     self.assertIsInstance(res2, Check)
     with self.assertRaises(CheckError):
         Check([1, 2, 3]).is_couple()
Пример #4
0
 def test_has_dimensionality(self):
     obj = [[1, 2], [3, 4]]
     res = Check(obj).has_dimensionality(2)
     self.assertIsInstance(res, Check)
     obj = [1, 2, 3]
     with self.assertRaises(CheckError):
         Check(obj).has_dimensionality(3)
Пример #5
0
 def test_is_tuple(self):
     res = Check(('a', 'b', 'c')).is_tuple()
     self.assertIsInstance(res, Check)
     res2 = Check((1, (1, 2), 2)).is_tuple()
     self.assertIsInstance(res2, Check)
     with self.assertRaises(CheckError):
         Check([]).is_tuple()
Пример #6
0
 def test_is_list(self):
     res = Check([10, 9, 8]).is_list()
     self.assertIsInstance(res, Check)
     res2 = Check([]).is_list()
     self.assertIsInstance(res2, Check)
     with self.assertRaises(CheckError):
         Check((1, 2)).is_list()
Пример #7
0
 def test_is_iterable(self):
     res = Check(range(6)).is_iterable()
     self.assertIsInstance(res, Check)
     res2 = Check([1, 2, 3]).is_iterable()
     self.assertIsInstance(res2, Check)
     with self.assertRaises(CheckError):
         Check(8).is_iterable()
Пример #8
0
 def test_has_opposite_truth_of(self):
     res = Check(BooleanObject(False)).has_opposite_truth_of(BooleanByLengthObject([1,]))
     self.assertIsInstance(res, Check)
     try:
         Check(BooleanObject(False)).has_opposite_truth_of(BooleanByLengthObject())
         self.fail()
     except CheckError:
         pass
Пример #9
0
 def test_not_contains_numbers(self):
     res = Check("Hello").not_contains_numbers()
     self.assertIsInstance(res, Check)
     try:
         Check("Hello123").not_contains_numbers()
         self.fail()
     except CheckError:
         pass
Пример #10
0
 def test_contains_chars_only(self):
     res = Check("abc").contains_chars_only()
     self.assertIsInstance(res, Check)
     try:
         Check("123").contains_chars_only()
         self.fail()
     except CheckError:
         pass
Пример #11
0
 def test_is_subtype_of_when_multiple_inheritance(self):
     res = Check(ChildOfMultipleParents()).is_subtype_of((ParentA, ParentB))
     self.assertIsInstance(res, Check)
     try:
         Check(ParentA()).is_subtype_of((ChildOfMultipleParents, ParentB))
         self.fail()
     except CheckError:
         pass
Пример #12
0
 def test_is_dict(self):
     res = Check({}).is_dict()
     self.assertIsInstance(res, Check)
     try:
         Check(123).is_dict()
         self.fail()
     except CheckError:
         pass
Пример #13
0
 def test_is_yaml(self):
     res = Check("hello").is_yaml()
     self.assertIsInstance(res, Check)
     try:
         Check(123).is_yaml()
         self.fail()
     except CheckError:
         pass
Пример #14
0
 def test_is_not_xml(self):
     res = Check('[123]').is_not_xml()
     self.assertIsInstance(res, Check)
     try:
         Check("<Agenda>ok</Agenda>").is_not_xml()
         self.fail()
     except CheckError:
         pass
Пример #15
0
 def test_is_not_yaml(self):
     res = Check("xxx: {").is_not_yaml()
     self.assertIsInstance(res, Check)
     try:
         Check("valid_yaml").is_not_yaml()
         self.fail()
     except CheckError:
         pass
Пример #16
0
 def test_is_none(self):
     res = Check(None).is_none()
     self.assertIsInstance(res, Check)
     try:
         Check(123).is_none()
         self.fail()
     except CheckError:
         pass
Пример #17
0
 def test_is_not_dict(self):
     res = Check(set()).is_not_dict()
     self.assertIsInstance(res, Check)
     try:
         Check(dict()).is_not_dict()
         self.fail()
     except CheckError:
         pass
Пример #18
0
 def test_not_contains_char(self):
     res = Check("hello world").not_contains_char('z')
     self.assertIsInstance(res, Check)
     try:
         Check("goodbye").not_contains_char('g')
         self.fail()
     except CheckError:
         pass
Пример #19
0
 def test_contains_spaces(self):
     res = Check("hello world").contains_spaces()
     self.assertIsInstance(res, Check)
     try:
         Check("goodbye").contains_spaces()
         self.fail()
     except CheckError:
         pass
Пример #20
0
 def test_is_boolean(self):
     res = Check(1 == 2).is_boolean()
     self.assertIsInstance(res, Check)
     try:
         Check(1).is_boolean()
         self.fail()
     except CheckError:
         pass
Пример #21
0
 def test_is_not_false(self):
     res = Check(1 == 1).is_not_false()
     self.assertIsInstance(res, Check)
     try:
         Check(1 == 2).is_not_false()
         self.fail()
     except CheckError:
         pass
Пример #22
0
 def test_is_subtype_of_atleast_one_parent(self):
     res = Check(Child()).is_subtype_of((ParentA, ParentB))
     self.assertIsInstance(res, Check)
     try:
         Check(Child()).is_not_subtype_of((ParentA, ParentB))
         self.fail()
     except CheckError:
         pass
Пример #23
0
 def test_is_subtype_of_when_grandchild_is_subtype_of_parent(self):
     res = Check(GrandChild()).is_subtype_of(ParentA)
     self.assertIsInstance(res, Check)
     try:
         Check(ParentA()).is_subtype_of(GrandChild)
         self.fail()
     except CheckError:
         pass
Пример #24
0
 def test_is_not_between(self):
     res = Check(5.4).is_not_between(1, 2)
     self.assertIsInstance(res, Check)
     try:
         Check(5.4).is_not_between(5, 6)
         self.fail()
     except CheckError:
         pass
Пример #25
0
 def test_is_subtype_of_itself(self):
     res = Check(Child()).is_subtype_of(Child)
     self.assertIsInstance(res, Check)
     try:
         Check(Child()).is_not_subtype_of(Child)
         self.fail()
     except CheckError:
         pass
Пример #26
0
 def test_not_contains_chars(self):
     res = Check("123").not_contains_chars()
     self.assertIsInstance(res, Check)
     try:
         Check("012t3").not_contains_chars()
         self.fail()
     except CheckError:
         pass
Пример #27
0
 def test_is_not_zero(self):
     res = Check(1).is_not_zero()
     self.assertIsInstance(res, Check)
     try:
         Check(0).is_not_zero()
         self.fail()
     except CheckError:
         pass
Пример #28
0
 def test_has_not_length(self):
     res = Check("hello").has_not_length(2)
     self.assertIsInstance(res, Check)
     try:
         Check("good").has_not_length(4)
         self.fail()
     except CheckError:
         pass
Пример #29
0
 def test_is_longer_than(self):
     res = Check("hello").is_longer_than(2)
     self.assertIsInstance(res, Check)
     try:
         Check("good").is_longer_than(10)
         self.fail()
     except CheckError:
         pass
Пример #30
0
 def test_is_not_string(self):
     res = Check(123).is_not_string()
     self.assertIsInstance(res, Check)
     try:
         Check("Hello").is_not_string()
         self.fail()
     except CheckError:
         pass