def test_missing_key_in_dot_path(self): """ A missing key in the dot notation path must raise a `KeyError`. """ d = {} with self.assertRaises(KeyError): config.set_value(d, 'foo.bar', 'pies')
def test_set_dotted_non_dict(self): """ Setting a value on an object that doesn't implement `__setitem__` must raise a `TypeError`. """ d = { 'foo': { 'bar': [] } } with self.assertRaises(TypeError): config.set_value(d, 'foo.bar.baz', 'pies')
def test_set_value(self): """ Set nested values using dot notation. """ d = { 'http': { 'address': '127.0.0.1' } } config.set_value(d, 'http.port', 5000) config.set_value(d, 'log_level', 'debug') expected = { 'http': { 'address': '127.0.0.1', 'port': 5000 }, 'log_level': 'debug' } self.assertEqual(d, expected)