diff --git a/translate/convert/test_po2yaml.py b/translate/convert/test_po2yaml.py index cec9cafe2b..0647555ec9 100644 --- a/translate/convert/test_po2yaml.py +++ b/translate/convert/test_po2yaml.py @@ -130,6 +130,10 @@ def test_nested(self): msgid "booo" msgstr "" +#: foo-> +msgid "bar2" +msgstr "" + #: eggs msgid "spam" msgstr "" @@ -137,21 +141,25 @@ def test_nested(self): template_string = ''' foo: bar: bar + '': bar2 baz: boo: booo eggs: spam ''' target_store = self._convert_to_store(input_string, template_string) - assert len(target_store.units) == 3 + assert len(target_store.units) == 4 assert target_store.units[0].getlocations() == ['foo->bar'] assert target_store.units[0].source == "bar" assert target_store.units[0].target == "bar" - assert target_store.units[1].getlocations() == ['foo->baz->boo'] - assert target_store.units[1].source == "booo" - assert target_store.units[1].target == "booo" - assert target_store.units[2].getlocations() == ['eggs'] - assert target_store.units[2].source == "spam" - assert target_store.units[2].target == "spam" + assert target_store.units[1].getlocations() == ['foo->'] + assert target_store.units[1].source == "bar2" + assert target_store.units[1].target == "bar2" + assert target_store.units[2].getlocations() == ['foo->baz->boo'] + assert target_store.units[2].source == "booo" + assert target_store.units[2].target == "booo" + assert target_store.units[3].getlocations() == ['eggs'] + assert target_store.units[3].source == "spam" + assert target_store.units[3].target == "spam" def test_convert_completion_below_threshold(self): """Check no conversion if input completion is below threshold.""" diff --git a/translate/convert/test_yaml2po.py b/translate/convert/test_yaml2po.py index 98ff016e5b..ac8e911023 100644 --- a/translate/convert/test_yaml2po.py +++ b/translate/convert/test_yaml2po.py @@ -71,6 +71,7 @@ def test_nested(self): input_string = ''' foo: bar: bar + '': bar2 baz: boo: booo @@ -78,16 +79,19 @@ def test_nested(self): eggs: spam ''' target_store = self._convert_to_store(input_string) - assert self._count_elements(target_store) == 3 + assert self._count_elements(target_store) == 4 assert target_store.units[1].getlocations() == ['foo->bar'] assert target_store.units[1].source == "bar" assert target_store.units[1].target == "" - assert target_store.units[2].getlocations() == ['foo->baz->boo'] - assert target_store.units[2].source == "booo" + assert target_store.units[2].getlocations() == ['foo->'] + assert target_store.units[2].source == "bar2" assert target_store.units[2].target == "" - assert target_store.units[3].getlocations() == ['eggs'] - assert target_store.units[3].source == "spam" + assert target_store.units[3].getlocations() == ['foo->baz->boo'] + assert target_store.units[3].source == "booo" assert target_store.units[3].target == "" + assert target_store.units[4].getlocations() == ['eggs'] + assert target_store.units[4].source == "spam" + assert target_store.units[4].target == "" def test_no_duplicates(self): """Check converting drops duplicates.""" diff --git a/translate/storage/test_yaml.py b/translate/storage/test_yaml.py index 701ba3a28e..e7c1dee7e9 100644 --- a/translate/storage/test_yaml.py +++ b/translate/storage/test_yaml.py @@ -350,6 +350,27 @@ def test_key_nesting(self): value: teststring2 ''' + def test_empty_key(self): + store = self.StoreClass() + store.parse(''' +'': Jedna +foo: + '': Dve +''') + assert len(store.units) == 2 + assert store.units[0].getid() == '' + assert store.units[0].source == 'Jedna' + assert store.units[1].getid() == 'foo->' + assert store.units[1].source == 'Dve' + out = BytesIO() + store.serialize(out) + assert out.getvalue() == b'''? '' +: Jedna +foo: + ? '' + : Dve +''' + class TestRubyYAMLResourceStore(test_monolingual.TestMonolingualStore): StoreClass = yaml.RubyYAMLFile diff --git a/translate/storage/yaml.py b/translate/storage/yaml.py index 8514f2241e..05c60fac82 100644 --- a/translate/storage/yaml.py +++ b/translate/storage/yaml.py @@ -149,7 +149,7 @@ def get_root_node(self, node): def serialize(self, out): def nested_set(target, path, value): if len(path) > 1: - if len(path) == 2 and path[1][0] == '[' and path[1][-1] == ']' and path[1][1:-1].isdigit(): + if len(path) == 2 and path[1] and path[1][0] == '[' and path[1][-1] == ']' and path[1][1:-1].isdigit(): if path[0] not in target: target[path[0]] = [] target[path[0]].append(value)