Exemplo n.º 1
0
    def test_str_to_predicate(self):
        nt = collections.namedtuple("FooBar", "foo bar")
        obj1 = nt(foo=True, bar=None)
        obj2 = nt(foo=None, bar=obj1)

        self.assertEqual(obj2.bar.foo, True)

        pred = Collection._str_to_predicate("bar.foo")
        self.assertEqual(pred(obj2), True)

        pred = Collection._str_to_predicate("bar")
        self.assertEqual(pred(obj2), obj1)

        pred = Collection._str_to_predicate("bar.xyz")
        with self.assertRaises(AttributeError):
            pred(obj2)
Exemplo n.º 2
0
    def test_str_to_predicate(self):
        nt = collections.namedtuple("FooBar", "foo bar")
        obj1 = nt(foo=True, bar=None)
        obj2 = nt(foo=None, bar=obj1)

        assert obj2.bar.foo is True

        pred = Collection._str_to_predicate("bar.foo")
        assert pred(obj2) is True

        pred = Collection._str_to_predicate("bar")
        assert pred(obj2) == obj1

        pred = Collection._str_to_predicate("bar.xyz")
        with pytest.raises(AttributeError):
            pred(obj2)