예제 #1
0
 def test_callable_overwrite_with_callable(self):
     "Allows overwriting a callable with a callable."
     x = Settings()
     x.a = lambda s: s.init + " original"
     x.a = lambda s: s.a + " and derived"
     x.init = "init"
     self.assertEqual(x.a, "init original and derived")
예제 #2
0
 def test_no_callable_overwrite_non_callable(self):
     "Disallows overwriting a callable with non-callable."
     x = Settings()
     x.a = lambda s: 1
     with self.assertRaisesRegex(
             AttributeError, "^trying to override attribute 'a' "
             "from a callable value to a non-callable "
             "one"):
         x.a = 1
예제 #3
0
 def test_as_dict(self):
     "The ``as_dict`` method returns a dictionary of values."
     x = Settings()
     x.a = lambda s: s.init + " original"
     x.a = lambda s: s.a + " and derived"
     x.init = "init"
     self.assertEqual(x.as_dict(), {
         "a": "init original and derived",
         "init": "init",
     })
예제 #4
0
 def test_set_get(self):
     "Sets and gets values."
     x = Settings()
     x.a = 1
     x.b = 2
     self.assertEqual(x.a, 1)
     self.assertEqual(x.b, 2)
예제 #5
0
 def test_parent(self):
     "Fetches values from parent."
     parent = Settings()
     child = Settings(parent)
     parent.a = 1
     parent.b = 2
     child.b = "overriden"
     self.assertEqual(child.a, 1)
     self.assertEqual(child.b, "overriden")