Esempio n. 1
0
 def test__default_required(self):
     with self.assertRaises(AssertionError):
         Property(default=5, required=True)
     with self.assertRaises(AssertionError):
         Property(default=None, required=True)
     with self.assertRaises(AssertionError):
         Property(default=0, required=True)
Esempio n. 2
0
 def test__errors(self):
     x = Property('x')
     prop = Property(x)
     with self.assertRaises(PropertyNotResolved) as exc:
         prop.get({})
     self.assertIs(prop, exc.exception.prop)
     self.assertIn(str(prop), str(exc.exception))
     self.assertIn(str(x), str(exc.exception))
Esempio n. 3
0
 def test__sources_it(self):
     with self.assertRaises(AssertionError):
         Property('x', sources_it=('x',))
     prop = Property(sources_it=range(6))
     self.assertEqual(3, prop.get({i: i for i in range(3, 6)}))
     self.assertEqual(2, prop.get({i: i for i in range(2, 6)}))
     self.assertEqual(1, prop.get({i: i for i in range(1, 6)}))
     self.assertEqual(0, prop.get({i: i for i in range(0, 6)}))
Esempio n. 4
0
 def test__root_source(self):
     prop = Property([])
     data = dict(x=1)
     self.assertEqual(data, prop.get(data))
     prop = Property('y', [], 'x')
     self.assertEqual(data, prop.get(data))
Esempio n. 5
0
 def test__sources__properties__nested(self):
     self.assertEqual(1, Property([Value(dict(x=1)), Property('x')]).get({}))
Esempio n. 6
0
 def test__sources__properties(self):
     self.assertEqual(1, Property(Property('x'), Value(1)).get({}))
Esempio n. 7
0
 def test__sources__property__not_found(self):
     with self.assertRaises(PropertyNotResolved):
         Property(Property('x')).get({})
Esempio n. 8
0
 def test__sources__property(self):
     self.assertEqual(1, Property(Value(1)).get({}))
Esempio n. 9
0
 def test__default_none(self):
     self.assertEqual(None, Property('x', default=None).get({}))
Esempio n. 10
0
 def test__default(self):
     self.assertEqual(1, Property('x', default=1).get({}))
Esempio n. 11
0
 def test__str(self):
     self.assertEqual('Property([])', str(Property([])))
     self.assertEqual("Property('x')", str(Property('x')))
     self.assertEqual("Property('x', 'y')", str(Property('x', 'y')))
     self.assertEqual('StringProperty()', str(StringProperty()))
Esempio n. 12
0
 def test__no_sources(self):
     prop = Property()
     data = dict(x=1)
     self.assertEqual(data, prop.get(data))