def test_get(self): contents = StringIO(''' key=value ''') p = DotProperties(contents) self.assertEqual(p.get('missing'), None) self.assertEqual(p.get('missing', 'default'), 'default') self.assertEqual(p.get('key'), 'value')
def test_get(self): contents = StringIO(""" key=value """) p = DotProperties(contents) self.assertEqual(p.get("missing"), None) self.assertEqual(p.get("missing", "default"), "default") self.assertEqual(p.get("key"), "value")
def test_update(self): contents = StringIO(''' old=old value key=value ''') p = DotProperties(contents) self.assertEqual(p.get('old'), 'old value') self.assertEqual(p.get('key'), 'value') new_contents = StringIO(''' key=new value ''') p.update(new_contents) self.assertEqual(p.get('old'), 'old value') self.assertEqual(p.get('key'), 'new value')
def test_get_dict_with_value_prefix(self): contents = StringIO(''' A.default=A A.default.B=B A.default.B.ignored=B ignored A.default.C=C A.default.C.ignored=C ignored ''') p = DotProperties(contents) self.assertEqual(p.get('A.default'), 'A') # This enumerates the properties. self.assertEqual(p.get_dict('A.default'), {'B': 'B', 'C': 'C'}) # They can still be fetched directly. self.assertEqual(p.get('A.default.B'), 'B') self.assertEqual(p.get('A.default.C'), 'C')
def test_update(self): contents = StringIO(""" old=old value key=value """) p = DotProperties(contents) self.assertEqual(p.get("old"), "old value") self.assertEqual(p.get("key"), "value") new_contents = StringIO(""" key=new value """) p.update(new_contents) self.assertEqual(p.get("old"), "old value") self.assertEqual(p.get("key"), "new value")
def test_get_dict_with_value_prefix(self): contents = StringIO(""" A.default=A A.default.B=B A.default.B.ignored=B ignored A.default.C=C A.default.C.ignored=C ignored """) p = DotProperties(contents) self.assertEqual(p.get("A.default"), "A") # This enumerates the properties. self.assertEqual(p.get_dict("A.default"), {"B": "B", "C": "C"}) # They can still be fetched directly. self.assertEqual(p.get("A.default.B"), "B") self.assertEqual(p.get("A.default.C"), "C")