Exemplo n.º 1
0
    def test_merge_source_catalog_parse_python_special_comments(self):
        js_catalog = Catalog("en")
        python_catalog = Catalog("en")
        python_catalog.add(
            "id1",
            locations=[("file1", "1")],
            auto_comments=["default-message: Text1", "some comment"],
        )
        old_source_catalog = Catalog("en")

        new_js_catalog, new_python_catalog, fuzzy = _merge_source_catalog(
            js_catalog, python_catalog, old_source_catalog
        )

        expected_python_catalog = Catalog("en")
        expected_python_catalog.add(
            "id1",
            string="Text1",
            locations=[("file1", "1")],
            auto_comments=["some comment"],
        )
        expected_js_catalog = Catalog("en")
        expected_js_catalog.add(
            "id1",
            string="Text1",
            locations=[("file1", "1")],
            auto_comments=["some comment"],
        )
        assert_catalogs_deeply_equal(new_js_catalog, expected_js_catalog)
        assert_catalogs_deeply_equal(new_python_catalog, expected_python_catalog)
        self.assertEqual(fuzzy, frozenset())
Exemplo n.º 2
0
    def test_fill_catalog_get_properties(self):
        target_catalog = Catalog()
        target_catalog.add("id1", string="Text1")

        source_catalog = Catalog()
        source_catalog.add("id1",
                           string="Text1ignore",
                           auto_comments=["comment"])
        source_catalog.add("id2",
                           string="Text2ignore",
                           locations=[("file1", "1")])

        string_source_catalog = Catalog()
        string_source_catalog.add(
            "id1",
            string="Text1new",
            auto_comments=["comment2"],
            locations=[("file2", "1")],
        )

        fill_catalog(target_catalog, source_catalog, string_source_catalog)

        expected_catalog = Catalog()
        expected_catalog.add("id1",
                             string="Text1new",
                             auto_comments=["comment"])
        expected_catalog.add("id2", string="", locations=[("file1", "1")])

        assert_catalogs_deeply_equal(target_catalog, expected_catalog)
Exemplo n.º 3
0
    def test_merge_catalog_update_from_js_fuzzy_empty(self):
        js_catalog = Catalog("el")
        js_catalog.add(
            "id1",
            string="",
            locations=[("file2", "1")],
            auto_comments=["some new comment"],
        )
        python_catalog = Catalog("en")
        old_catalog = Catalog("el")
        old_catalog.add(
            "id1", string="", locations=[("file1", "1")], auto_comments=["some comment"]
        )
        fuzzy = frozenset(["id1"])

        new_catalog = _merge_catalogs([js_catalog, python_catalog], old_catalog, fuzzy)

        expected_catalog = Catalog("el")
        expected_catalog.add(
            "id1",
            string="",
            locations=[("file2", "1")],
            auto_comments=["some new comment"],
        )
        assert_catalogs_deeply_equal(new_catalog, expected_catalog)
Exemplo n.º 4
0
    def test_merge_catalog_update_from_python(self):
        js_catalog = Catalog("el")
        python_catalog = Catalog("en")
        python_catalog.add(
            "id1",
            string="Text1",
            locations=[("file2", "1")],
            auto_comments=["some new comment"],
        )
        old_catalog = Catalog("el")
        old_catalog.add(
            "id1",
            string="Text0",
            locations=[("file3", "2")],
            auto_comments=["some old comment"],
        )
        fuzzy = frozenset()

        new_catalog = _merge_catalogs([js_catalog, python_catalog], old_catalog, fuzzy)

        expected_catalog = Catalog("el")
        expected_catalog.add(
            "id1",
            string="Text0",
            locations=[("file2", "1")],
            auto_comments=["some new comment"],
        )
        assert_catalogs_deeply_equal(new_catalog, expected_catalog)
Exemplo n.º 5
0
    def test_merge_source_catalog_fuzzy_in_js(self):
        js_catalog = Catalog("en")
        js_catalog.add(
            "id1",
            string="Text1",
            locations=[("file1", "1")],
            auto_comments=["some comment"],
        )
        python_catalog = Catalog("en")
        old_source_catalog = Catalog("en")
        old_source_catalog.add(
            "id1",
            string="Text0",
            locations=[("file1", "1")],
            auto_comments=["some comment"],
        )

        new_js_catalog, new_python_catalog, fuzzy = _merge_source_catalog(
            js_catalog, python_catalog, old_source_catalog
        )

        expected_python_catalog = Catalog("en")
        expected_js_catalog = Catalog("en")
        expected_js_catalog.add(
            "id1",
            string="Text1",
            locations=[("file1", "1")],
            auto_comments=["some comment"],
        )
        assert_catalogs_deeply_equal(new_js_catalog, expected_js_catalog)
        assert_catalogs_deeply_equal(new_python_catalog, expected_python_catalog)
        self.assertEqual(fuzzy, frozenset(["id1"]))
Exemplo n.º 6
0
 def test_remove_strings(self):
     old_catalog = Catalog()
     old_catalog.add("id1", string="Text1")
     old_catalog.add("id2", string="Text1", context="ctxt")
     remove_strings(old_catalog)
     expected_catalog = Catalog()
     expected_catalog.add("id1", string="")
     expected_catalog.add("id2", string="", context="ctxt")
     assert_catalogs_deeply_equal(old_catalog, expected_catalog)
Exemplo n.º 7
0
    def test_move_strings_to_comments(self):
        catalog = Catalog()
        catalog.add("id", string="Text1")
        move_strings_to_comments(catalog, comment_tag="default-message")

        expected = Catalog()
        expected.add("id", string="", auto_comments=["default-message: Text1"])

        assert_catalogs_deeply_equal(catalog, expected)
Exemplo n.º 8
0
    def test_add_or_update_message_update(self):
        target_catalog = Catalog()
        target_catalog.add("id1", string="Text1")

        add_or_update_message(target_catalog, Message("id1", string="Text2"))

        expected_catalog = Catalog()
        expected_catalog.add("id1", string="Text2")

        assert_catalogs_deeply_equal(target_catalog, expected_catalog)
Exemplo n.º 9
0
    def test_merge_source_catalog_update_existing_old(self):
        js_catalog = Catalog("en")
        js_catalog.add(
            "id0",
            string="Text0",
            locations=[("file0", "2")],
            auto_comments=["some js comment"],
        )
        python_catalog = Catalog("en")
        python_catalog.add(
            "id1",
            locations=[("file1", "1")],
            auto_comments=["default-message: Text1", "some comment"],
        )
        old_source_catalog = Catalog("en")
        old_source_catalog.add(
            "id0",
            string="Text0",
            locations=[("file0", "3")],
            auto_comments=["some js comment"],
        )
        old_source_catalog.add(
            "id1",
            string="Text1",
            locations=[("file0", "2")],
            auto_comments=["some old comment"],
        )

        new_js_catalog, new_python_catalog, fuzzy = _merge_source_catalog(
            js_catalog, python_catalog, old_source_catalog
        )

        expected_python_catalog = Catalog("en")
        expected_python_catalog.add(
            "id1",
            string="Text1",
            locations=[("file1", "1")],
            auto_comments=["some comment"],
        )
        expected_js_catalog = Catalog("en")
        expected_js_catalog.add(
            "id0",
            string="Text0",
            locations=[("file0", "2")],
            auto_comments=["some js comment"],
        )
        expected_js_catalog.add(
            "id1",
            string="Text1",
            locations=[("file1", "1")],
            auto_comments=["some comment"],
        )
        assert_catalogs_deeply_equal(new_js_catalog, expected_js_catalog)
        assert_catalogs_deeply_equal(new_python_catalog, expected_python_catalog)
        self.assertEqual(fuzzy, frozenset())
Exemplo n.º 10
0
    def test_mark_fuzzy_no_mark_empty(self):
        target_catalog = Catalog()
        target_catalog.add("id1", string="")

        old_catalog = Catalog()

        fuzzy = frozenset(["id1"])

        mark_fuzzy(target_catalog, fuzzy, old_catalog)

        expected_catalog = Catalog()
        expected_catalog.add("id1", string="")

        assert_catalogs_deeply_equal(target_catalog, expected_catalog)
Exemplo n.º 11
0
    def test_mark_fuzzy_mark_old(self):
        target_catalog = Catalog()
        target_catalog.add("id1", string="Text1", flags=["fuzzy"])

        old_catalog = Catalog()

        fuzzy = frozenset()

        mark_fuzzy(target_catalog, fuzzy, old_catalog)

        expected_catalog = Catalog()
        expected_catalog.add("id1", string="Text1", flags=["fuzzy"])

        assert_catalogs_deeply_equal(target_catalog, expected_catalog)
Exemplo n.º 12
0
    def test_fill_catalog_preserve_old(self):
        target_catalog = Catalog()
        target_catalog.add("id1", string="Text1")

        source_catalog = Catalog()

        string_source_catalog = Catalog()

        fill_catalog(target_catalog, source_catalog, string_source_catalog)

        expected_catalog = Catalog()
        expected_catalog.add("id1", string="Text1")

        assert_catalogs_deeply_equal(target_catalog, expected_catalog)
Exemplo n.º 13
0
    def test_fill_catalog_update_message(self):
        target_catalog = Catalog()
        target_catalog.add("id1", string="Text1")

        source_catalog = Catalog()
        source_catalog.add("id1", string="Text1")

        string_source_catalog = Catalog()
        string_source_catalog.add("id1", string="Text2")

        fill_catalog(target_catalog, source_catalog, string_source_catalog)

        expected_catalog = Catalog()
        expected_catalog.add("id1", string="Text2")

        assert_catalogs_deeply_equal(target_catalog, expected_catalog)
Exemplo n.º 14
0
    def test_fill_catalog_add_new(self):
        target_catalog = Catalog()
        target_catalog.add("id1", string="Text1")

        source_catalog = Catalog()
        source_catalog.add("id2", string="Text2ignore")

        string_source_catalog = Catalog()
        string_source_catalog.add("id2", string="Text2")

        fill_catalog(target_catalog, source_catalog, string_source_catalog)

        expected_catalog = Catalog()
        expected_catalog.add("id1", string="Text1")
        expected_catalog.add("id2", string="Text2")

        assert_catalogs_deeply_equal(target_catalog, expected_catalog)
Exemplo n.º 15
0
    def test_fill_catalog_update_properties(self):
        target_catalog = Catalog()
        target_catalog.add("id1", string="Text1", auto_comments=["comment"])

        source_catalog = Catalog()
        source_catalog.add("id1",
                           string="Text1ignore",
                           auto_comments=["new comment"])

        string_source_catalog = Catalog()

        fill_catalog(target_catalog, source_catalog, string_source_catalog)

        expected_catalog = Catalog()
        expected_catalog.add("id1",
                             string="Text1",
                             auto_comments=["new comment"])

        assert_catalogs_deeply_equal(target_catalog, expected_catalog)
Exemplo n.º 16
0
 def test_copy_catalog_copies(self):
     old_catalog = Catalog()
     old_catalog.add("id1", string="Text1")
     new_catalog = copy_catalog(old_catalog)
     assert_catalogs_deeply_equal(old_catalog, new_catalog)