def test_get_dict_with_shared_prefix(self): contents = StringIO(''' A.title=title A A.subdict.title=title A subdict B.title=title B B.url=url B B.subdict.title=title B subdict B.subdict.url=url B subdict ''') p = DotProperties(contents) self.assertEqual(p.get_dict('A'), {'title': 'title A'}) self.assertEqual(p.get_dict('B'), {'title': 'title B', 'url': 'url B'}) self.assertEqual(p.get_dict('A.subdict'), {'title': 'title A subdict'}) self.assertEqual(p.get_dict('B.subdict'), {'title': 'title B subdict', 'url': 'url B subdict'})
def test_get_dict_with_shared_prefix(self): contents = StringIO(''' A.title=title A A.subdict.title=title A subdict B.title=title B B.url=url B B.subdict.title=title B subdict B.subdict.url=url B subdict ''') p = DotProperties(contents) self.assertEqual(p.get_dict('A'), {'title': 'title A'}) self.assertEqual(p.get_dict('B'), {'title': 'title B', 'url': 'url B'}) self.assertEqual(p.get_dict('A.subdict'), {'title': 'title A subdict'}) self.assertEqual(p.get_dict('B.subdict'), {'title': 'title B subdict', 'url': 'url B subdict'})
def test_get_dict_with_shared_prefix(self): contents = StringIO(""" A.title=title A A.subdict.title=title A subdict B.title=title B B.url=url B B.subdict.title=title B subdict B.subdict.url=url B subdict """) p = DotProperties(contents) self.assertEqual(p.get_dict("A"), {"title": "title A"}) self.assertEqual(p.get_dict("B"), {"title": "title B", "url": "url B"}) self.assertEqual(p.get_dict("A.subdict"), {"title": "title A subdict"}) self.assertEqual( p.get_dict("B.subdict"), { "title": "title B subdict", "url": "url B subdict" }, )
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_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_unicode(self): contents = StringIO(''' # Danish. # #### ~~ Søren Munk Skrøder, sskroeder - 2009-05-30 @ #mozmae # Korean. A.title=한메일 # Russian. list.0 = test list.1 = Яндекс ''') p = DotProperties(contents) self.assertEqual(p.get_dict('A'), {'title': '한메일'}) self.assertEqual(p.get_list('list'), ['test', 'Яндекс'])
def test_unicode(self): contents = StringIO(""" # Danish. # #### ~~ Søren Munk Skrøder, sskroeder - 2009-05-30 @ #mozmae # Korean. A.title=한메일 # Russian. list.0 = test list.1 = Яндекс """) p = DotProperties(contents) self.assertEqual(p.get_dict("A"), {"title": "한메일"}) self.assertEqual(p.get_list("list"), ["test", "Яндекс"])
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_unicode(self): contents = StringIO(''' # Danish. # #### ~~ Søren Munk Skrøder, sskroeder - 2009-05-30 @ #mozmae # Korean. A.title=한메일 # Russian. list.0 = test list.1 = Яндекс ''') p = DotProperties(contents) self.assertEqual(p.get_dict('A'), {'title': '한메일'}) self.assertEqual(p.get_list('list'), ['test', 'Яндекс'])
def test_get_dict(self): contents = StringIO(""" A.title=title A B.title=title B B.url=url B C=value """) p = DotProperties(contents) self.assertEqual(p.get_dict("missing"), {}) self.assertEqual(p.get_dict("A"), {"title": "title A"}) self.assertEqual(p.get_dict("B"), {"title": "title B", "url": "url B"}) with self.assertRaises(ValueError): p.get_dict("A", required_keys=["title", "url"]) with self.assertRaises(ValueError): p.get_dict("missing", required_keys=["key"]) # A key=value pair is considered to root an empty dict. self.assertEqual(p.get_dict("C"), {}) with self.assertRaises(ValueError): p.get_dict("C", required_keys=["missing_key"])
def test_get_dict(self): contents = StringIO(''' A.title=title A B.title=title B B.url=url B C=value ''') p = DotProperties(contents) self.assertEqual(p.get_dict('missing'), {}) self.assertEqual(p.get_dict('A'), {'title': 'title A'}) self.assertEqual(p.get_dict('B'), {'title': 'title B', 'url': 'url B'}) with self.assertRaises(ValueError): p.get_dict('A', required_keys=['title', 'url']) with self.assertRaises(ValueError): p.get_dict('missing', required_keys=['key']) # A key=value pair is considered to root an empty dict. self.assertEqual(p.get_dict('C'), {}) with self.assertRaises(ValueError): p.get_dict('C', required_keys=['missing_key'])
def test_get_dict(self): contents = StringIO(''' A.title=title A B.title=title B B.url=url B C=value ''') p = DotProperties(contents) self.assertEqual(p.get_dict('missing'), {}) self.assertEqual(p.get_dict('A'), {'title': 'title A'}) self.assertEqual(p.get_dict('B'), {'title': 'title B', 'url': 'url B'}) with self.assertRaises(ValueError): p.get_dict('A', required_keys=['title', 'url']) with self.assertRaises(ValueError): p.get_dict('missing', required_keys=['key']) # A key=value pair is considered to root an empty dict. self.assertEqual(p.get_dict('C'), {}) with self.assertRaises(ValueError): p.get_dict('C', required_keys=['missing_key'])
def test_get_dict(self): contents = StringIO(''' A.title=title A B.title=title B B.url=url B ''') p = DotProperties(contents) self.assertEqual(p.get_dict('missing'), {}) self.assertEqual(p.get_dict('A'), {'title': 'title A'}) self.assertEqual(p.get_dict('B'), {'title': 'title B', 'url': 'url B'}) with self.assertRaises(ValueError): p.get_dict('A', required_keys=['title', 'url']) with self.assertRaises(ValueError): p.get_dict('missing', required_keys=['key'])
def test_get_dict(self): contents = StringIO(''' A.title=title A B.title=title B B.url=url B ''') p = DotProperties(contents) self.assertEqual(p.get_dict('missing'), {}) self.assertEqual(p.get_dict('A'), {'title': 'title A'}) self.assertEqual(p.get_dict('B'), {'title': 'title B', 'url': 'url B'}) with self.assertRaises(ValueError): p.get_dict('A', required_keys=['title', 'url']) with self.assertRaises(ValueError): p.get_dict('missing', required_keys=['key'])
def test_valid_unicode_from_file(self): # The contents of valid.properties is identical to the contents of the # test above. This specifically exercises reading from a file. p = DotProperties(os.path.join(test_data_path, 'valid.properties')) self.assertEqual(p.get_dict('A'), {'title': '한메일'}) self.assertEqual(p.get_list('list'), ['test', 'Яндекс'])
def test_valid_unicode_from_file(self): # The contents of valid.properties is identical to the contents of the # test above. This specifically exercises reading from a file. p = DotProperties(os.path.join(test_data_path, "valid.properties")) self.assertEqual(p.get_dict("A"), {"title": "한메일"}) self.assertEqual(p.get_list("list"), ["test", "Яндекс"])
def test_valid_unicode_from_file(self): # The contents of valid.properties is identical to the contents of the # test above. This specifically exercises reading from a file. p = DotProperties(os.path.join(test_data_path, 'valid.properties')) self.assertEqual(p.get_dict('A'), {'title': '한메일'}) self.assertEqual(p.get_list('list'), ['test', 'Яндекс'])