Пример #1
0
    def test_has_no_nones(self):
        with Assertable(self.rock_bands) as in_rock_bands:
            in_rock_bands.every_existent("albums year").has_no_nones()
            in_rock_bands.every().has_no_nones()

        with Assertable(self.programming_languages) as in_languages:
            in_languages.every().has_no_nones()
Пример #2
0
    def test_is_ordered(self):
        with Assertable(self.rock_bands) as in_rock_bands:
            in_rock_bands.some("albums songs").is_(["Smoke on the water", "Space truckin'"])
            in_rock_bands.some("albums songs").is_(["Space truckin'", "Smoke on the water"])
            in_rock_bands.some("albums songs").is_ordered(["Space truckin'", "Smoke on the water"])
            self.assertRaises(AssertionError,
                              in_rock_bands.some("albums songs").is_ordered,
                              ["Smoke on the water", "Space truckin'"])

        with Assertable(self.numbers) as in_numbers:
            in_numbers("sequences primes").is_([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41])
            in_numbers("sequences Pell").is_([1, 2, 29, 5, 0, 12])
Пример #3
0
    def test_has_no_duplicates(self):
        with Assertable(self.rock_bands) as in_rock_bands:
            in_rock_bands.some("albums year").has_no_duplicates()
            in_rock_bands.every("genre").has_no_duplicates()
            self.assertRaises(AssertionError,
                              in_rock_bands.every_existent("albums year").has_no_duplicates)

            in_rock_bands.every("albums *").has_no_duplicates()
            self.assertRaises(AssertionError, in_rock_bands.every("albums **").has_no_duplicates)

        with Assertable([1, 1, 1, 1, 1]) as in_ones:
            in_ones.at_least(1).has_no_duplicates()
            self.assertRaises(AssertionError, in_ones.at_least(2).has_no_duplicates)
Пример #4
0
    def test_basic_numbers(self):
        with Assertable(101) as in_number:
            in_number.one().has(101)
            in_number.one().is_(101)
            in_number().is_(101)
            in_number.no().has(1)
            in_number.one("**").has(101)
            in_number.one("**").is_(101)

        with Assertable({"x": 101}) as in_number:
            for sel in ["x", "*", "**"]:
                in_number.one(sel).has(101)
                in_number.one(sel).is_(101)
                in_number.no(sel).has(1)
Пример #5
0
    def test_properties_comparators(self):
        with Assertable(self.rock_bands) as in_rock_bands:
            in_rock_bands.some("members").has(5, cmp=operator.eq, property=len)
            in_rock_bands.some("members").has_length(5)
            in_rock_bands.every("members").has(3, cmp=operator.ge, property=len)
            in_rock_bands.every("members").has_length(3, cmp=operator.ge)
            in_rock_bands.every("genre").has("Rock", cmp=str.__contains__)

        with Assertable(self.numbers) as in_numbers:
            in_numbers.every("**").has(50, cmp=operator.lt)
            in_numbers.one("sequences primes").has(0, cmp=operator.eq, property=lambda x: x % 2)
            in_numbers.every("sequences *").has(29, cmp=operator.ge, property=max)
            in_numbers.exactly(4, "sequences *").has(True,
                                                     cmp=operator.eq,
                                                     property=lambda x: x == sorted(x))
Пример #6
0
 def test_other_combinations_has(self):
     with Assertable(self.numbers) as in_numbers:
         in_numbers.one("sequences *").has(49)
         in_numbers.at_least(3, "sequences *").has(29)
         in_numbers.at_most(2, "sequences *").has(0)
         in_numbers.exactly(3, "sequences *").has(1)
         in_numbers.at_most(0, "**").has(42)
Пример #7
0
 def test_matches(self):
     with Assertable(self.rock_bands) as in_rock_bands:
         in_rock_bands.some("albums songs").matches("Pigs*", "Dogs*")
         self.assertRaises(AssertionError, in_rock_bands.some("albums songs").matches, "Horses*")
         in_rock_bands.every("genre").matches("\w\sRock")
         in_rock_bands.some("genre").matches("^Blues.*")
         self.assertRaises(AssertionError, in_rock_bands.every("genre").matches, "^Blues.*")
Пример #8
0
 def test_several_nested_dicts(self):
     with Assertable({'a': 1,
                      'b': 2,
                      'c': {'z': 10, 'x': 100},
                      'd': {'y': 60, 'w': 600}}) as in_several_nested_dicts:
         in_several_nested_dicts.no().has({'b': 2, 'c': {'z': 10}, 'd': {'y': 70}})
         in_several_nested_dicts.no().has({'b': 2, 'c': {'z': 20}, 'd': {'y': 60}})
         in_several_nested_dicts.no().has({'b': 1, 'c': {'z': 10}, 'd': {'y': 60}})
         in_several_nested_dicts.no().has({'b': 2, 'c': {'z': 20}, 'd': {'y': 60, 'w': 700}})
         in_several_nested_dicts.no().has({'b': 2, 'c': {'z': 20, 'x': 110}, 'd': {'y': 60}})
         in_several_nested_dicts.one().has({'b': 2, 'c': {'z': 10}, 'd': {'y': 60}})
         in_several_nested_dicts.one().has({'a': 1, 'c': {'x': 100}, 'd': {'y': 60, 'w': 600}})
         in_several_nested_dicts.one().is_({'a': 1,
                                            'b': 2,
                                            'c': {'z': 10, 'x': 100},
                                            'd': {'y': 60, 'w': 600}})
         in_several_nested_dicts.one().has_some_of({'b': 20, 'c': {'z': 10}, 'd': {'y': 70}})
         in_several_nested_dicts.one().has_some_of({'b': 20, 'c': {'z': 20}, 'd': {'y': 60}})
         in_several_nested_dicts.no().has_some_of({'b': 1, 'c': {'z': 13}, 'd': {'y': 63}})
         in_several_nested_dicts.one().has_some_of({'b': 2, 'c': {'z': 13}, 'd': {'y': 63}})
         in_several_nested_dicts.one().has_some_of({'b': 2, 'c': {'z': 20},
                                                    'd': {'y': 60, 'w': 700}})
         in_several_nested_dicts.one().has_some_of({'b': 1, 'c': {'z': 10},
                                                    'd': {'y': 70, 'w': 700}})
         in_several_nested_dicts.one().has_some_of({'b': 1, 'c': {'z': 20, 'x': 100},
                                                    'd': {'y': 80}})
Пример #9
0
    def test_programming(self):
        with Assertable(self.programming_languages) as in_programming:
            # Something equals something
            in_programming.one(["languages", "academical", "functional", ("name", "Lisp"), "year"]).is_(1958)
            in_programming.some("languages academical functional year").is_(1990)
            self.assertRaises(AssertionError,
                              in_programming.every(["languages", "*", "functional", "type system"]).is_, "static")
            # Throws:
            #         AssertionError:
            #         Selection on the object under test with path ['languages', '*', 'functional', 'type system'] --->
            #
            #                 ['dynamic', 'static', 'dynamic']
            #
            #         Compared with assertion input --->
            #
            #                 'static'
            #
            #         Not verified (expected = 3, got = 1)
            in_programming.at_least(2, ["languages", "*", "functional", "type system"]).is_("dynamic")

            # Something contains something
            object_oriented_features = ["languages", "*", "object oriented", "features"]
            in_programming.some(object_oriented_features).has("duck typing")
            in_programming.some(object_oriented_features).has("duck typing", "generics")
            in_programming.some(object_oriented_features).has(["duck typing", "GIL"])
            self.assertRaises(AssertionError,
                              in_programming.some(object_oriented_features).has, ["duck typing", "generics"])
            #Throws:
            #       AssertionError:
            #       Selection on the object under test with path ['languages', '*', 'object oriented', 'features'] --->
            #
            #                 [['duck typing', 'GIL', 'multiple inheritance'], ['JIT compiler', 'generics']]
            #
            #       Compared with assertion input --->
            #
            #                 ['duck typing', 'generics']
            #
            #       Not verified (expected = 1, got = 0)
            in_programming.every(["languages", "*", "*", "type system"]).has("ic")
            in_programming.one(["languages", "practical", "procedural", ("name", "Fortran")]).has(
                                                                                            {"year": 1957,
                                                                                             "type system": "static"})
            in_programming.one(["languages", "practical", "procedural", ("name", "Fortran")]).has_some_of(
                                                                                    {"year": 2042,
                                                                                     "type system": "static"})

            # More on something equals something
            in_programming.some(object_oriented_features).is_(["JIT compiler", "generics"])
            in_programming.some(object_oriented_features).is_(["generics", "JIT compiler"])
            in_programming.some(object_oriented_features).is_ordered(["JIT compiler", "generics"])
            self.assertRaises(AssertionError,
                              in_programming.some(object_oriented_features).is_ordered, ["generics", "JIT compiler"])

            # Something compares somehow with some property of something else
            in_programming.exactly(2, "languages * * year").has(1960, cmp=operator.lt)
            in_programming("languages * * year").has(1957, cmp=operator.eq, property=min)
            in_programming.every("languages * * features").has(2, cmp=operator.ge, property=len)

            in_programming.some("languages practical functional").is_not_none()
            in_programming.every("languages **").is_not_none()
Пример #10
0
    def test_object_to_dict(self):

        class Point:
            pass

        class Segment:
            def __init__(self, name):
                self.name = name

        p1 = Point()
        p1.x, p1.y = 1, 0

        p2 = Point()
        p2.x, p2.y = 3, 3

        segment = Segment("super-segment")
        segment.bounds = [p1, p2]

        with Assertable(segment) as in_segment:
            in_segment.one('bounds').has({'x': 1})
            in_segment('bounds *').has([[3, 4]],
                                       cmp=operator.eq,
                                       property=lambda (pt1, pt2): map(operator.add, pt1, pt2))
            in_segment.exactly(2, '**').is_(3)
            in_segment.one('bounds y').has_some_of([0, 8])
Пример #11
0
 def test_expanded(self):
     with Assertable(self.programming_languages) as in_languages:
         in_languages.one(["procedural", "Fortran", "type system"]).is_("static")
         in_languages.exactly(2, ["procedural", "*", "type system"]).is_("static")
         in_languages.at_least(2, "* * year").has(60, cmp=operator.lt)
         in_languages.some("* * * quote").matches("(?i)Unix")
         in_languages.every("**").has_no_nones()
         in_languages.every("functional **").has_no_duplicates()
         in_languages.every(["object oriented", "*", "*"]).has(4, cmp=operator.eq, property=len)
Пример #12
0
 def test_path_composition(self):
     with Assertable(self.programming_languages, ["functional"]) as in_functional:
         in_functional.one("Lisp", "year").is_(58)
         in_functional.one("Lisp", ["designer", "name"]).matches("John")
         in_functional.one(["Lisp", "designer"], "name").matches("John")
         in_functional.one("*",
                           [("type system", "static")],
                           ["designer", "name"]).matches("Simon")
         in_functional.one(["*", ("type system", "static")], "designer", "name").matches("Simon")
Пример #13
0
    def test_basic_strings(self):
        with Assertable("xyz") as in_str:
            in_str.one().has("xyz")
            in_str.one().has("x")
            in_str.one().is_("xyz")
            in_str().is_("xyz")
            in_str().has("xyz")
            in_str.no().is_("x")
            in_str.one("**").has("x")
            in_str.one("**").is_("xyz")
            self.assertRaises(AssertionError, in_str.one("*").has, "xyz")

        with Assertable({"x": "yz"}) as in_str:
            for sel in ["x", "*", "**"]:
                in_str.one(sel).has("y")
                in_str.one(sel).has("y", "z")
                in_str.one(sel).has("yz")
                in_str.one(sel).is_("yz")
                in_str.no(sel).has("zy")
Пример #14
0
 def test_deep_dict(self):
     with Assertable({"a": 1,
                      "m": {"n": 100},
                      "z": {"x": 10, "y": 20, "w": 30, "u": {"l": 1000}}}) as in_dict:
         in_dict.one().has({"z": {"x": 10}})
         in_dict.one().has({"a": 1, "z": {"x": 10}})
         in_dict.one().has({"a": 1, "z": {"x": 10}})
         in_dict.one().has({"m": {"n": 100}, "z": {"x": 10, "w": 30}})
         in_dict.one().has({"a": 1, "z": {"u": {"l": 1000}}})
         in_dict.no().has({"a": 15, "z": {"u": {"l": 1000}}})
         in_dict.no().has({"a": 1, "z": {"u": {"l": 1001}}})
Пример #15
0
    def test_skip_privates_and_callables(self):
        class X:
            pass

        x = X()
        x.a = 1
        x._b = 2
        x.c = list.__add__

        with Assertable(x) as xdict:
            xdict().is_({'a': 1})
Пример #16
0
 def test_one_filter(self):
     with Assertable(self.rock_bands) as in_rock_bands:
         in_rock_bands.one([("band", "Pink Floyd"), "periods", 1963]).has("Formation")
         in_rock_bands.one([("band", "Pink Floyd"),
                            "periods"]).has({1963: "Formation", 2005: "Reunion"})
         in_rock_bands.one(["albums", ("title", "The Wall"), "year"]).is_(1979)
         in_rock_bands.one(["albums", ("title", "The Wall")]).has({"uk chart": 3})
         in_rock_bands.one(
             ["albums",
              ("title", "The dark side of the moon"),
              "certifications",
              "United States"]).has("Diamond")
Пример #17
0
 def test_convenient_methods(self):
     with Assertable(self.programming_languages, "languages * *") as in_languages:
         in_languages.every("features").has_no_nones()
         in_languages.every("features").has_not("can fly")
         in_languages.every("features").has_not("can fly", "can drive")
         in_languages.every("year").has_not(datetime.now().year, cmp=operator.gt)
         in_languages.every("year").is_a(int)
         in_languages.no("designer name").is_("Jim Morrison")
         in_languages.at_most(1, "designer name").is_("Denis Ritchie")
         in_languages.at_most(1, "designer name").is_("Denis Ritchie", "James Gosling")
         in_languages.some("designer quote").matches("(?i)uNiX")
         in_languages.some("designer quote").matches("(?i)uNiX", "work.*lazy")
         in_languages.some(["designer"], "quote").matches("(?i)uNiX", "work.*lazy")
Пример #18
0
    def test_others(self):

        with Assertable([[1, 2, 3]]) as in_numbers:
            self.assertRaises(AssertionError, in_numbers.one().is_, [[1, 2, 3]])
            in_numbers.one().is_([1, 2, 3])
            in_numbers().is_([[1, 2, 3]])

        with Assertable([2, 3, 5, 7, 11, 13, 17, 19]) as in_primes:
            in_primes().has(True, cmp=operator.eq, property=lambda x: x == sorted(x))

            all_modulos = lambda x: [(n, x % n) for n in xrange(1, x + 1)]
            all_divisibles = lambda x: ([x for (x, m) in all_modulos(x) if m == 0], x)
            is_prime = lambda (div_set, x), _: len(div_set) == 2 and 1 in div_set and x in div_set
            in_primes.every().has("ignore this attribute", cmp=is_prime, property=all_divisibles)

        with Assertable([1, 2, 3, 3]) as in_some_duplicates:
            in_some_duplicates.at_least(3).has_no_duplicates()
            self.assertRaises(AssertionError,
                              in_some_duplicates.every().has_no_duplicates)
            self.assertRaises(AssertionError,
                in_some_duplicates().has, [1, 2, 3, 3], cmp=operator.eq, property=lambda x: list(set(x)))

        with Assertable({"programmers": [{"name": "Alice",
                                          "says": "I love functional programming!",
                                          "profession": "poet"},
                                         {"name": "Bob",
                                          "says": "I love monkey patching!",
                                          "profession": "plumber"},
                                         {"name": "Podio",
                                          "says": "I love agile!"}]}) as in_programmers:
            in_programmers.every_existent("programmers says").has("love")
            in_programmers.every("programmers says").has("love")
            self.assertRaises(AssertionError,
                              in_programmers.every, "programmers profession")
            # Throws:
            #   AssertionError: Attribute profession not found in path ['programmers', 'profession']
            in_programmers.every_existent("programmers profession").is_not_none()

            in_programmers.one(["programmers", ("name", "Bob"), "profession"]).is_("plumber")
Пример #19
0
    def test_to_dict_detect_cycles(self):
        class X:
            pass

        class Z:
            pass

        x = X()
        z = Z()
        x.z = z
        z.x = x

        with Assertable(x) as cyclic_graph:
            cyclic_graph.one('z').is_({'x': {}})
Пример #20
0
 def test_logical_booleans(self):
     with Assertable({'a': False,
                      'b': [],
                      'c': True,
                      'd': 0,
                      'e': 1,
                      'f': None,
                      'g': [2]}) as in_tricky_booleans:
         in_tricky_booleans.one('a').evals_false()
         in_tricky_booleans.one('b').evals_false()
         in_tricky_booleans.one('c').evals_true()
         in_tricky_booleans.one('d').evals_false()
         in_tricky_booleans.one('e').evals_true()
         in_tricky_booleans.one('f').evals_false()
         in_tricky_booleans.one('g').evals_true()
Пример #21
0
 def test_unicode(self):
     with Assertable({u'danske vokaler': "aeiouyåæø",
                      "español": {u'child': u'niño', "hello": "hola"},
                      u'øther': {u'utf-8': u'this_reads_utf-8',
                                u'spanish and danish': {u'beer': [u'øl', u'caña']}}}) as in_dict:
         in_dict.one("español").is_({"hello": "hola", "child": u'niño'})
         in_dict.one('espa\xc3\xb1ol').is_({"child": u'ni\xf1o', u'hello': u'hola'})
         in_dict.one(['danske vokaler']).is_('aeiouy\xc3\xa5\xc3\xa6\xc3\xb8')
         in_dict.one([u'danske vokaler']).is_('aeiouyåæø')
         in_dict.one([u'danske vokaler']).is_(u'aeiouy\xe5\xe6\xf8'.encode('utf8'))
         in_dict.one([u'\xf8ther',  "utf-8"]).is_("this_reads_utf-8")
         in_dict.one(u'øther utf-8').is_(u'this_reads_utf-8')
         in_dict(['øther'.decode('utf8'), "spanish and danish", 'beer']).is_([u'caña', u'øl'])
         in_dict([u'øther', "spanish and danish", u'beer']).is_(['caña'.decode('utf8'),
                                                                 'øl'.decode('utf8')])
Пример #22
0
    def test_some_has_some_of(self):
        with Assertable(self.rock_bands) as in_rock_bands:
            in_rock_bands.some("albums year").has_some_of([1972, 2045])
            in_rock_bands.some("members").has_some_of(["Clapton", "Page"])

            in_rock_bands.one([("band", "Pink Floyd"),
                               "periods", 1963]).has_some_of(["Formation", "Bazinga"])
            self.assertRaises(AssertionError,
                              in_rock_bands.one([("band", "Pink Floyd"),
                                                 "periods", 1963]).has_some_of, "Formation", "!")

            in_rock_bands.one([("band", "Pink Floyd"),
                               "periods"]).has_some_of({1963: "Formation", 2000: "!"})
            self.assertRaises(AssertionError,
                              in_rock_bands.one([("band", "Pink Floyd"),
                                                 "periods"]).has_some_of, {1968: "!", 2000: "!"})
Пример #23
0
    def test_obj_to_dict(self):
        class X:
            pass

        class Z:
            def __init__(self, arg):
                self.arg = arg

        x1 = X()
        x1.a = 1
        x1.b = "b"
        x1.c = [3, 4, 5]
        x1.d = {10: 100, 20: 200}

        x2 = X()
        x2.p = x1
        x2.q = [x1]
        x2.r = lambda _: _

        z = Z("z")
        z.u = {1: {10: {100: x1}, 20: x2}}
        z.v = [x1, x2, x1]
        z.w = Z("w")
        z.y = (0, x2, 0)
        z.z = set([x1, x1])

        dicts = to_dict([z, x1])

        with Assertable(dicts) as obj_as_dict:
            obj_as_dict.one(['u', 1, 10, 100, 'c']).has([4, 5, 3])
            obj_as_dict.one(['u', 1, 10, 100, 'c']).has([4, 5])
            obj_as_dict.one(['u', 1, 10, 100]).has({'c': [3, 4, 5]})
            obj_as_dict.one(['u', 1, 10, 100]).has({
                'a': 1,
                'b': 'b',
                'c': [3, 4, 5],
                'd': {
                    10: 100,
                    20: 200
                }
            })
            obj_as_dict.one(['u', 1, 20, 'q', 'a']).is_(1)
            obj_as_dict.one('w arg').is_('w')
            obj_as_dict.one('arg').is_('z')
            obj_as_dict.exactly(2, 'v c').has(3)
            obj_as_dict.one('y').has(0, {'r': {}})
            obj_as_dict.one('z b').evals_true()
Пример #24
0
 def test_deep_nested_dict(self):
     r = {'z': 10, 'x': 100}
     s = {'y': 40, 'w': 400}
     t = {'u': 80, 'v': 800}
     with Assertable({'a': 1,
                      'b': 2,
                      'c': {'p': r},
                      'd': {'p': s, 'q': t},
                      'e': {'p': {'q': [r, s]}}}) as in_deep_nested_dict:
         in_deep_nested_dict.one().has({'a': 1, 'd': {'p': {'y': 40}}})
         in_deep_nested_dict.one().has({'c': {'p': {'z': 10}}, 'e': {'p': {'q': [r, s]}}})
         in_deep_nested_dict.one().has({'c': {'p': {'z': 10}}, 'd': {'p': {'y': 40, 'w': 400},
                                                                     'q': {'u': 80, 'v': 800}}})
         in_deep_nested_dict.no().has({'a': 2, 'd': {'p': {'y': 40}}})
         in_deep_nested_dict.no().has({'a': 1, 'd': {'p': {'y': 50}}})
         in_deep_nested_dict.no().has({'a': 1, 'd': {'t': {'y': 40}}})
         in_deep_nested_dict.no().has({'c': {'p': {'z': 25}}, 'e': {'p': {'q': [r, s]}}})
         in_deep_nested_dict.no().has({'c': {'p': {'z': 10}}, 'e': {'p': {'q': [s]}}})
         in_deep_nested_dict.no().has({'c': {'p': {'z': 10}}, 'e': {'p': {'q': s}}})
         in_deep_nested_dict.no().has({'c': {'p': {'z': 10}}, 'e': {'p': {'q': {'y': 40}}}})
         in_deep_nested_dict.no().has({'c': {'p': {'z': 20}}, 'd': {'p': {'y': 40, 'w': 400},
                                                                    'q': {'u': 80, 'v': 800}}})
         in_deep_nested_dict.no().has({'c': {'p': {'z': 20}}, 'd': {'p': {'y': 40, 'w': 400},
                                                                    'q': {'u': 60, 'v': 800}}})
         in_deep_nested_dict.no().has({'c': {'p': {'z': 10}}, 'd': {'p': {'y': 40, 'w': 500},
                                                                    'q': {'u': 80, 'v': 800}}})
         in_deep_nested_dict.no().has({'c': {'p': {'z': 10}}, 'd': {'p': {'y': 40, 'w': 400},
                                                                    'q': {'u': 90, 'v': 800}}})
         in_deep_nested_dict.no().has({'c': {'p': {'z': 10}}, 'd': {'p': {'y': 70, 'w': 400},
                                                                    'q': {'u': 80, 'v': 1000}}})
         in_deep_nested_dict.one().has_some_of({'a': 2, 'd': {'p': {'y': 40}}})
         in_deep_nested_dict.one().has_some_of({'a': 1, 'd': {'p': {'y': 50}}})
         in_deep_nested_dict.one().has_some_of({'c': {'p': {'z': 10}},
                                                'e': {'p': {'q': {'y': 50}}}})
         in_deep_nested_dict.one().has_some_of({'c': {'p': {'z': 10}},
                                                'd': {'p': {'y': 50, 'w': 500},
                                                      'q': {'u': 90, 'v': 900}}})
         in_deep_nested_dict.one().has_some_of({'c': {'p': {'z': 20}},
                                                'd': {'p': {'y': 50, 'w': 500},
                                                      'q': {'u': 80, 'v': 900}}})
         in_deep_nested_dict.one().has_some_of({'c': {'p': {'z': 20}},
                                                'd': {'p': {'y': 40, 'w': 500},
                                                      'q': {'u': 80, 'v': 800}}})
         in_deep_nested_dict.no().has({'e': {'p': {'q': {'y': 40}}}})
         in_deep_nested_dict.one('e p q').has({'y': 40})
Пример #25
0
 def test_one_nested_dict(self):
     with Assertable({'a': 1, 'b': 2, 'c': {'z': 10, 'x': 100}}) as in_simple_nested_dict:
         in_simple_nested_dict.no().has({'b': 5, 'c': {'z': 10}})
         in_simple_nested_dict.no().has({'a': 5, 'c': {'z': 10}})
         in_simple_nested_dict.no().has({'a': 1, 'c': {'z': 50}})
         in_simple_nested_dict.no().has({'a': 5, 'c': {'z': 10, 'x': 100}})
         in_simple_nested_dict.no().has({'b': 5, 'c': {'x': 100}})
         in_simple_nested_dict.no().has({'b': 2, 'c': {'x': 50, 'z': 10}})
         in_simple_nested_dict.no().has({'b': 2, 'c': {'x': 100, 'z': 50}})
         in_simple_nested_dict.no().has({'a': 1, 'b': 2, 'c': {'x': 100, 'z': 50}})
         in_simple_nested_dict.one().has({'b': 2, 'c': {'x': 100}})
         in_simple_nested_dict.one().has({'a': 1, 'b': 2, 'c': {'z': 10}})
         in_simple_nested_dict.one().has({'b': 2, 'c': {'z': 10, 'x': 100}})
         in_simple_nested_dict.one().has_some_of({'a': 5, 'c': {'z': 10}})
         in_simple_nested_dict.one().has_some_of({'a': 1, 'c': {'z': 15}})
         in_simple_nested_dict.one().has_some_of({'b': 5, 'c': {'z': 10, 'x': 105}})
         in_simple_nested_dict.one().has_some_of({'a': 5, 'b': 2, 'c': {'z': 10}})
         in_simple_nested_dict.one().is_({'b': 2, 'a': 1, 'c': {'x': 100, 'z': 10}})
Пример #26
0
 def test_basic_dicts(self):
     with Assertable({"x": {"z1": 1,
                            "z2": 2},
                      "y": {"z3": 3,
                            "z4": 4}}) as in_dict:
         in_dict.one("x").is_({"z1": 1, "z2": 2})
         in_dict("x").is_({"z1": 1, "z2": 2})
         in_dict.one("x").has({"z1": 1, "z2": 2})
         in_dict.one("x").has({"z1": 1}, {"z2": 2})
         in_dict.no("x").has([{"z1": 1}, {"z2": 2}])
         in_dict.one().has({"x": {"z1": 1, "z2": 2}})
         in_dict.one().has({"x": {"z1": 1, "z2": 2}}, {"y": {"z3": 3, "z4": 4}})
         in_dict.no().has([{"x": {"z1": 1, "z2": 2}}, {"y": {"z3": 3, "z4": 4}}])
         in_dict.one().is_({"x": {"z1": 1, "z2": 2}, "y": {"z3": 3, "z4": 4}})
         in_dict.one("*").has({"z1": 1}, {"z3": 3})
         in_dict.one("**").has(1, 2, 3, 4)
         in_dict.one("**").is_(4)
         in_dict().is_({"x": {"z1": 1, "z2": 2}, "y": {"z3": 3, "z4": 4}})
Пример #27
0
    def test_some_has(self):
        with Assertable(self.rock_bands) as in_rock_bands:
            in_rock_bands.some("albums year").has(1972)

            in_rock_bands.some(["albums", "title"]).has("Made in Japan")
            in_rock_bands.some(["albums", "title"]).has("Made in Japan", "The Wall")
            self.assertRaises(AssertionError,
                              in_rock_bands.some(["albums", "title"]).has, ["The Wall", "Animals"])

            in_rock_bands.some("members").has("Paice")
            in_rock_bands.some("members").has("Waters", "Barret")
            in_rock_bands.some("members").has(["Waters", "Barret"], ["Paice"])
            self.assertRaises(AssertionError,
                              in_rock_bands.some("members").has, ["Waters", "Paice"])

            in_rock_bands.some().has({"band": "Pink Floyd"})
            in_rock_bands.some().has({"band": "Pink Floyd", "genre": "Psychedelic Rock"})
            in_rock_bands.some().has({"band": "Pink Floyd"}, {"genre": "Blues Rock"})
            self.assertRaises(AssertionError,
                              in_rock_bands.some().has, {"band": "Pink Floyd",
                                                         "genre": "Blues Rock"})
Пример #28
0
    def test_basic_nones(self):
        with Assertable(None) as in_nones:
            in_nones.no().has_no_nones()

        with Assertable([None, None, None, 1]) as in_nones:
            in_nones.some().has_no_nones()

        with Assertable([1, 2, 5, 3, 4]) as in_nones:
            in_nones.every().has_no_nones()

        with Assertable([1, 2, None, 3, 4]) as in_nones:
            self.assertRaises(AssertionError, in_nones.every().has_no_nones)

        with Assertable({1: "z", 2: None}) as in_nones:
            self.assertRaises(AssertionError, in_nones.every("*").has_no_nones)

        with Assertable({1: "z", 2: None}) as in_nones:
            self.assertRaises(AssertionError, in_nones.every("**").has_no_nones)
Пример #29
0
    def test_one_is(self):
        with Assertable(self.rock_bands) as in_rock_bands:
            #in_rock_bands.one("formation").is_(1968)
            in_rock_bands.one([("band", "Pink Floyd"), "periods"]).is_({1963: "Formation",
                                                                        1968: "Fame",
                                                                        1978: "Waters leadership",
                                                                        1986: "Gilmour leadership",
                                                                        1995: "End",
                                                                        2005: "Reunion"})
            in_rock_bands.one([("band", "Cream"), "members"]).has("Clapton")

            self.assertRaises(AssertionError, in_rock_bands.one([("band", "Cream"),
                                                                 "members"]).is_, "Clapton")
            self.assertRaises(AssertionError,
                              in_rock_bands.one([("band", "Pink Floyd"),
                                                 "periods"]).is_, {1963: "Formation"})

            self.assertRaises(AssertionError,
                              in_rock_bands.one([("band",
                                                  "Pink Floyd"), "periods"]).has, {1968: "Fame",
                                                                                   2000: "!"})

            self.assertRaises(AssertionError, in_rock_bands.one("albums year").is_, 1972)
            self.assertRaises(AssertionError, in_rock_bands.one("albums year").is_, 1973)
Пример #30
0
    def test_trivial(self):
        with Assertable([]) as empty_lst:
            empty_lst().evals_false()
            empty_lst().is_not_none()
            empty_lst.every_existent('a').is_('b')
            empty_lst.one().is_([])
            empty_lst().is_([])

        with Assertable({}) as empty_dict:
            empty_dict().evals_false()
            empty_dict().is_not_none()
            empty_lst.every_existent('a').is_('b')
            empty_dict.one().is_({})
            empty_dict().is_({})

        with Assertable('') as empty_str:
            empty_str().evals_false()
            empty_str().is_not_none()
            empty_str.every_existent('a').is_('b')
            empty_str.one().is_('')
            empty_str().is_('')

        with Assertable(None) as none:
            none().evals_false()
            none().is_none()
            none.one().is_(None)
            none().is_(None)

        with Assertable(set([1, 1])) as simple_set:
            simple_set().has_length(1)
            simple_set.one().is_(1)

        with Assertable((1, 2, 3)) as simple_tuple:
            simple_tuple().evals_true()
            simple_tuple().has_length(3)
            simple_tuple().has(2, 3)
            simple_tuple().is_((1, 3, 2))
            simple_tuple().is_ordered((1, 2, 3))