示例#1
0
 def test__args__list_value(self):
     fun = Mock()
     self.prop_test(F(fun, args=V([1, 2])), NO_ASSERT)
     fun.assert_called_with(1, 2)
     self.prop_test(F(fun, args=V([[1, 2]])), NO_ASSERT)
     fun.assert_called_with([1, 2])
     self.prop_test(F(fun, args=V([[1, 2], 3])), NO_ASSERT)
     fun.assert_called_with([1, 2], 3)
示例#2
0
 def test__args__values_list(self):
     fun = Mock()
     self.prop_test(F(fun, args=[V(1), V(2)]), NO_ASSERT)
     fun.assert_called_with(1, 2)
     self.prop_test(F(fun, args=[V([1, 2])]), NO_ASSERT)
     fun.assert_called_with([1, 2])
     self.prop_test(F(fun, args=[V([1, 2]), V(3)]), NO_ASSERT)
     fun.assert_called_with([1, 2], 3)
示例#3
0
 def test__args__star_values(self):
     fun = Mock()
     self.prop_test(F(fun, V(1), V(2)), NO_ASSERT)
     fun.assert_called_with(1, 2)
     self.prop_test(F(fun, V([1, 2])), NO_ASSERT)
     fun.assert_called_with([1, 2])
     self.prop_test(F(fun, V([1, 2]), V(3)), NO_ASSERT)
     fun.assert_called_with([1, 2], 3)
示例#4
0
 def test__kwargs(self):
     fun = Mock()
     self.prop_test(F(fun), NO_ASSERT)
     fun.assert_called_with()
     self.prop_test(F(fun, kwargs=V(dict())), NO_ASSERT)
     fun.assert_called_with()
     self.prop_test(F(fun, kwargs=V(dict(x=1))), NO_ASSERT)
     fun.assert_called_with(x=1)
     self.prop_test(F(fun, kwargs=dict(x=V(1))), NO_ASSERT)
     fun.assert_called_with(x=1)
示例#5
0
    def test__r(self):

        self.prop_test(
            CompoundProperty(
                total_hours=R('days') * 24 + R('hours') + R('minutes') / 60,
                days=V(1),
                hours=V(1),
                minutes=V(30),
            ),
            dict(days=1, hours=1, minutes=30, total_hours=25.5),
        )
示例#6
0
    def test__f(self):
        full_name = 'Ayn Rand'
        name, surname = full_name.split()

        self.prop_test(
            F(' '.join, args=[V([name, surname])]),
            full_name,
        )
        self.prop_test(
            F(str.split, args=[V(full_name)]),
            [name, surname],
        )
示例#7
0
 def test__v__index_of(self):
     self.prop_test(V(list([2, 1, 2])).index_of(V(2)), 0)
     self.prop_test(V(list([2, 1, 2])).index_of(V(1)), 1)
     with self.assertRaises(ValueError):
         self.prop_test(V(list([2, 1, 2])).index_of(V(0)), None)
     self.prop_test(V(list([2, 1, 2])).index_of(2), 0)
     self.prop_test(V(list([2, 1, 2])).index_of(1), 1)
 def test__str(self):
     self.assertEqual(
         "CompoundProperty(x=Value(1))",
         str(CompoundProperty(x=V(1))),
     )
     self.assertEqual(
         "CompoundProperty(sources=['y', 'z'], x=Value(1))",
         str(CompoundProperty(dict(sources=['y', 'z']), x=V(1))),
     )
     self.assertEqual(
         "CompoundProperty("
         "sources=[['y'], ['z', 'w']], "
         "x=Value(1), "
         "y=PropertyRef('x'))",
         str(
             CompoundProperty(
                 dict(sources=[['y'], ['z', 'w']]),
                 x=V(1),
                 y=PropertyRef('x'),
             )),
     )
示例#9
0
 def test__v__add(self):
     self.prop_test(V(1) + V(1), 2)
     self.prop_test(V(1) + V(2), 3)
     self.prop_test(V(1) + V(-1), 0)
示例#10
0
 def test__v__ge(self):
     self.prop_test(V(5) >= V(5), True)
     self.prop_test(V(6) >= V(5), True)
     self.prop_test(V(4) >= V(5), False)
示例#11
0
 def test__args__values_list__some_not_resolved(self):
     fun = Mock()
     self.prop_test(F(fun, args=[P(1)]), PropertyNotResolved)
     self.prop_test(F(fun, args=[P(1), V(2), V(3)]), PropertyNotResolved)
     self.prop_test(F(fun, args=[V(1), P(2), V(3)]), PropertyNotResolved)
     self.prop_test(F(fun, args=[V(1), V(2), P(3)]), PropertyNotResolved)
示例#12
0
 def test__empty_source(self):
     with self.assertRaises(PropertyNotResolved):
         R().get({}, {})
     with self.assertRaises(PropertyNotResolved):
         R(sources_it=[]).get({}, {})
     self.prop_test(D(x=V(1), y=D(x=R()))['y']['x'], 1)
示例#13
0
 def test__v__gt(self):
     self.prop_test(V(5) > V(4), True)
     self.prop_test(V(4) > V(4), False)
     self.prop_test(V(3) > V(4), False)
示例#14
0
 def test__v__abs(self):
     self.prop_test(abs(V(-1)), 1)
     self.prop_test(abs(V(+1)), 1)
示例#15
0
 def test__ref_to_property_in_grandparent(self):
     self.prop_test(D(x=V(1), y=D(z=R('x')))['y']['z'], 1)
 def test__star_props__some_not_resolved(self):
     self.prop_not_resolved(L(P(0)))
     self.prop_not_resolved(L(P(0), V(1)))
     self.prop_not_resolved(L(V(0), P(1)))
     self.prop_not_resolved(L(V(0), V(1), P(2)))
     self.prop_not_resolved(L(P(0), P(1), P(2)))
 def test__star_props__lists__some_entirely_not_resolved(self):
     self.prop_not_resolved(L([P(0)]))
     self.prop_not_resolved(L([P(0), P(1)]))
     self.prop_not_resolved(L([P(0), V(1)], [P(2)]))
 def test__props_it(self):
     self.prop_test(L(props_it=[V(1), V(2)]), [1, 2])
     self.prop_test(L(props_it=[V(1), V([2, 3])]), [1, [2, 3]])
示例#19
0
 def test__v__and(self):
     self.prop_test(V(True) & V(True), True)
     self.prop_test(V(True) & V(False), False)
     self.prop_test(V(False) & V(True), False)
     self.prop_test(V(False) & V(False), False)
     self.prop_test(V(True) & True, True)
     self.prop_test(V(True) & False, False)
     self.prop_test(V(False) & True, False)
     self.prop_test(V(False) & False, False)
示例#20
0
 def test__v__pos(self):
     self.prop_test(+V(1), +1)
示例#21
0
 def test__v__neg(self):
     self.prop_test(-V(1), -1)
     self.prop_test(-V(-1), 1)
示例#22
0
 def test__v__or(self):
     self.prop_test(V(True) | V(True), True)
     self.prop_test(V(True) | V(False), True)
     self.prop_test(V(False) | V(True), True)
     self.prop_test(V(False) | V(False), False)
     self.prop_test(V(True) | True, True)
     self.prop_test(V(True) | False, True)
     self.prop_test(V(False) | True, True)
     self.prop_test(V(False) | False, False)
示例#23
0
 def test__no_args__no_kwargs(self):
     self.prop_test(F(lambda: 1), 1)
     self.prop_test(F(lambda: 2, args=V(())), 2)
     self.prop_test(F(lambda: 3, args=V(()), kwargs=V({})), 3)
     self.prop_test(F(lambda: 4, kwargs=V({})), 4)
示例#24
0
 def test__v__floordiv(self):
     self.prop_test(V(1) // V(2), 0)
     self.prop_test(V(2) // V(2), 1)
     self.prop_test(V(3) // 2, 1)
 def test__star_props(self):
     self.prop_test(L(V(0)), [0])
     self.prop_test(L(V(0), V(1)), [0, 1])
     self.prop_test(L(V(0), V(1), V(2)), [0, 1, 2])
     self.prop_test(L(V(0), V(1), V(2)), [0, 1, 2])
示例#26
0
 def test__v__mod(self):
     self.prop_test(V(5) % V(2), 1)
     self.prop_test(V(5) % 2, 1)
 def test__star_props__lists(self):
     self.prop_test(L([V(0), P(1)]), [0])
     self.prop_test(L([P(0), V(1)]), [1])
     self.prop_test(L([P(0), V(1)], [V(2)]), [1, 2])
     self.prop_test(L([P(0), V(1)], [P(2), V(3)]), [1, 3])
示例#28
0
 def test__v__mul(self):
     self.prop_test(V(2) * V(2), 4)
     self.prop_test(V(2) * 3, 6)
 def test__simple(self):
     self.prop_test(L(V(1), V(2)), [1, 2])
示例#30
0
 def test__ref_to_property_in_parent(self):
     self.prop_test(D(x=V(1), y=R('x'))['y'], 1)