def test_getitem(self): settings = Config(YAML_DATA) self.assertEqual(settings["sitename"], "bob") self.assertEqual(settings["thingy"], ["one", "two", "three"]) self.assertEqual(settings.get("sitename"), "bob") self.assertEqual(settings.get("sitetitle"), None) with self.assertRaises(KeyError): settings["sitetitle"]
def test_getitem_with_parent(self): parent = Config({"test": True}) settings = Config(YAML_DATA, parent=parent, node=mock.Mock()) self.assertEqual(settings["sitename"], "bob") self.assertEqual(settings["thingy"], ["one", "two", "three"]) self.assertEqual(settings["test"], True) self.assertEqual(settings.get("sitename"), "bob") self.assertEqual(settings.get("test"), True) self.assertEqual(settings.get("sitetitle"), None) self.assertEqual(parent.get("sitename"), None) with self.assertRaises(KeyError): settings["sitetitle"]