예제 #1
0
    def test_not_supported_error(self):
        channels = (b"""
foo = Foo 1
""", b"""
foo = Foo 2
""")
        pattern = r"Unsupported file format \(foo\.unknown\)\."
        with six.assertRaisesRegex(self, MergeNotSupportedError, pattern):
            merge_channels(self.name, channels)
예제 #2
0
    def test_not_supported_error(self):
        channels = (b"""
foo = Foo 1
""", b"""
foo = Foo 2
""")
        pattern = "Unsupported file format \(foo\.unknown\)\."
        with six.assertRaisesRegex(self, MergeNotSupportedError, pattern):
            merge_channels(self.name, *channels)
    def test_still_in_last_with_blank(self):
        channels = (b"""

foo = Foo 1

baz = Baz 1

""", b"""

foo = Foo 2

bar = Bar 2

baz = Baz 2

""")
        self.assertEqual(merge_channels(self.name, *channels), b"""

foo = Foo 1

bar = Bar 2

baz = Baz 1

""")
예제 #4
0
    def test_trailing_whitespace(self):
        channels = (b"""
<!ENTITY foo "Foo 1">
""", b"""
<!ENTITY foo "Foo 2"> \n""")
        self.assertEqual(merge_channels(self.name, channels), b"""
<!ENTITY foo "Foo 1"> \n""")
예제 #5
0
    def test_still_in_last_with_blank(self):
        channels = (b"""

foo = Foo 1

baz = Baz 1

""", b"""

foo = Foo 2

bar = Bar 2

baz = Baz 2

""")
        self.assertEqual(
            merge_channels(self.name, *channels), b"""

foo = Foo 1

bar = Bar 2

baz = Baz 1

""")
 def createWorkdir(self, contents):
     workdir = self.graph.target.git.workdir
     locales = set()
     includes = []
     for tpath, content_list in contents.items():
         try:
             b_content = merge_channels(tpath, content_list)
         except MergeNotSupportedError:
             b_content = content_list[0]
         if tpath.endswith("l10n.toml"):
             try:
                 data = toml.loads(b_content)
                 if 'locales' in data:
                     locales.update(data['locales'])
                 includes.append(tpath)
             except Exception as e:
                 print(e)
                 pass
         tpath = mozpath.join(workdir, tpath)
         tdir = mozpath.dirname(tpath)
         if not os.path.isdir(tdir):
             os.makedirs(tdir)
         with open(tpath, "wb") as fh:
             fh.write(b_content)
     self.ensureL10nToml(workdir, locales, includes)
예제 #7
0
    def test_trailing_whitespace(self):
        channels = (b"""
<!ENTITY foo "Foo 1">
""", b"""
<!ENTITY foo "Foo 2"> \n""")
        self.assertEqual(
            merge_channels(self.name, *channels), b"""
<!ENTITY foo "Foo 1"> \n""")
    def test_trailing_spaces(self):
        channels = (b"""
foo = Foo 1
      """, b"""
foo = Foo 2
""")
        self.assertEqual(merge_channels(self.name, *channels), b"""
foo = Foo 1
      """)
예제 #9
0
    def test_no_changes(self):
        channels = (b"""
<!ENTITY foo "Foo 1">
""", b"""
<!ENTITY foo "Foo 2">
""")
        self.assertEqual(merge_channels(self.name, channels), b"""
<!ENTITY foo "Foo 1">
""")
예제 #10
0
    def test_no_changes(self):
        channels = (b"""
foo = Foo 1
""", b"""
foo = Foo 2
""")
        self.assertEqual(merge_channels(self.name, channels), b"""
foo = Foo 1
""")
예제 #11
0
    def test_browser_dtd(self):
        channels = (b"""\
<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<!-- LOCALIZATION NOTE : FILE This file contains the browser main menu ... -->
<!-- LOCALIZATION NOTE : FILE Do not translate commandkeys -->

<!-- LOCALIZATION NOTE (mainWindow.titlemodifier) : DONT_TRANSLATE -->
<!ENTITY mainWindow.titlemodifier "&brandFullName;">
<!-- LOCALIZATION NOTE (mainWindow.separator): DONT_TRANSLATE -->
<!ENTITY mainWindow.separator " - ">
<!-- LOCALIZATION NOTE (mainWindow.privatebrowsing2): This will be appended ...
                                                      inside the ... -->
<!ENTITY mainWindow.privatebrowsing2 "(Private Browsing)">
""", b"""\
<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<!-- LOCALIZATION NOTE : FILE This file contains the browser main menu ... -->
<!-- LOCALIZATION NOTE : FILE Do not translate commandkeys -->

<!-- LOCALIZATION NOTE (mainWindow.title): DONT_TRANSLATE -->
<!ENTITY mainWindow.title "&brandFullName;">
<!-- LOCALIZATION NOTE (mainWindow.titlemodifier) : DONT_TRANSLATE -->
<!ENTITY mainWindow.titlemodifier "&brandFullName;">
<!-- LOCALIZATION NOTE (mainWindow.privatebrowsing): This will be appended ...
                                                     inside the ... -->
<!ENTITY mainWindow.privatebrowsing "(Private Browsing)">
""")

        self.assertMultiLineEqual(
            merge_channels(self.name, *channels), b"""\
<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<!-- LOCALIZATION NOTE : FILE This file contains the browser main menu ... -->
<!-- LOCALIZATION NOTE : FILE Do not translate commandkeys -->

<!-- LOCALIZATION NOTE (mainWindow.title): DONT_TRANSLATE -->
<!ENTITY mainWindow.title "&brandFullName;">

<!-- LOCALIZATION NOTE (mainWindow.titlemodifier) : DONT_TRANSLATE -->
<!ENTITY mainWindow.titlemodifier "&brandFullName;">
<!-- LOCALIZATION NOTE (mainWindow.privatebrowsing): This will be appended ...
                                                     inside the ... -->
<!ENTITY mainWindow.privatebrowsing "(Private Browsing)">
<!-- LOCALIZATION NOTE (mainWindow.separator): DONT_TRANSLATE -->
<!ENTITY mainWindow.separator " - ">
<!-- LOCALIZATION NOTE (mainWindow.privatebrowsing2): This will be appended ...
                                                      inside the ... -->
<!ENTITY mainWindow.privatebrowsing2 "(Private Browsing)">
""")
예제 #12
0
    def test_browser_dtd(self):
        channels = (b"""\
<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<!-- LOCALIZATION NOTE : FILE This file contains the browser main menu ... -->
<!-- LOCALIZATION NOTE : FILE Do not translate commandkeys -->

<!-- LOCALIZATION NOTE (mainWindow.titlemodifier) : DONT_TRANSLATE -->
<!ENTITY mainWindow.titlemodifier "&brandFullName;">
<!-- LOCALIZATION NOTE (mainWindow.separator): DONT_TRANSLATE -->
<!ENTITY mainWindow.separator " - ">
<!-- LOCALIZATION NOTE (mainWindow.privatebrowsing2): This will be appended ...
                                                      inside the ... -->
<!ENTITY mainWindow.privatebrowsing2 "(Private Browsing)">
""", b"""\
<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<!-- LOCALIZATION NOTE : FILE This file contains the browser main menu ... -->
<!-- LOCALIZATION NOTE : FILE Do not translate commandkeys -->

<!-- LOCALIZATION NOTE (mainWindow.title): DONT_TRANSLATE -->
<!ENTITY mainWindow.title "&brandFullName;">
<!-- LOCALIZATION NOTE (mainWindow.titlemodifier) : DONT_TRANSLATE -->
<!ENTITY mainWindow.titlemodifier "&brandFullName;">
<!-- LOCALIZATION NOTE (mainWindow.privatebrowsing): This will be appended ...
                                                     inside the ... -->
<!ENTITY mainWindow.privatebrowsing "(Private Browsing)">
""")

        self.assertMultiLineEqual(
            merge_channels(self.name, channels).decode("utf-8"), """\
<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<!-- LOCALIZATION NOTE : FILE This file contains the browser main menu ... -->
<!-- LOCALIZATION NOTE : FILE Do not translate commandkeys -->

<!-- LOCALIZATION NOTE (mainWindow.title): DONT_TRANSLATE -->
<!ENTITY mainWindow.title "&brandFullName;">

<!-- LOCALIZATION NOTE (mainWindow.titlemodifier) : DONT_TRANSLATE -->
<!ENTITY mainWindow.titlemodifier "&brandFullName;">
<!-- LOCALIZATION NOTE (mainWindow.privatebrowsing): This will be appended ...
                                                     inside the ... -->
<!ENTITY mainWindow.privatebrowsing "(Private Browsing)">
<!-- LOCALIZATION NOTE (mainWindow.separator): DONT_TRANSLATE -->
<!ENTITY mainWindow.separator " - ">
<!-- LOCALIZATION NOTE (mainWindow.privatebrowsing2): This will be appended ...
                                                      inside the ... -->
<!ENTITY mainWindow.privatebrowsing2 "(Private Browsing)">
""")
예제 #13
0
    def test_trailing_spaces(self):
        channels = (b"""
foo = Foo 1
      """, b"""
foo = Foo 2
""")
        self.assertEqual(
            merge_channels(self.name, *channels), b"""
foo = Foo 1
      """)
    def test_attribute_in_last(self):
        channels = (b"""
foo = Foo 1
""", b"""
foo = Foo 2
    .attr = Attr 2
""")
        self.assertEqual(merge_channels(self.name, *channels), b"""
foo = Foo 1
""")
    def test_message_comment_in_last(self):
        channels = (b"""
foo = Foo 1
""", b"""
# Comment 2
foo = Foo 2
""")
        self.assertEqual(merge_channels(self.name, *channels), b"""
foo = Foo 1
""")
예제 #16
0
    def test_tag_in_last(self):
        channels = (b"""
foo = Foo 1
""", b"""
foo = Foo 2
    #tag
""")
        self.assertEqual(merge_channels(self.name, *channels), b"""
foo = Foo 1
""")
예제 #17
0
    def test_no_changes(self):
        channels = (b"""
foo = Foo 1
""", b"""
foo = Foo 2
""")
        self.assertEqual(
            merge_channels(self.name, channels), b"""
foo = Foo 1
""")
예제 #18
0
 def get_content(self, local_ref, repo, revs):
     if local_ref.endswith(b".toml"):
         return self.get_config_content(local_ref, repo, revs)
     if len(revs) < 2:
         return repo.cat([b"path:" + local_ref], rev=revs[0])
     contents = [repo.cat([b"path:" + local_ref], rev=rev) for rev in revs]
     try:
         return merge.merge_channels(local_ref.decode("utf-8"), contents)
     except merge.MergeNotSupportedError:
         return contents[0]
예제 #19
0
    def test_section_comment_in_last(self):
        channels = (b"""
[[ Section ]]
""", b"""
// Comment 2
[[ Section ]]
""")
        self.assertEqual(merge_channels(self.name, *channels), b"""
[[ Section ]]
""")
예제 #20
0
    def test_no_changes(self):
        channels = (b"""
<!ENTITY foo "Foo 1">
""", b"""
<!ENTITY foo "Foo 2">
""")
        self.assertEqual(
            merge_channels(self.name, *channels), b"""
<!ENTITY foo "Foo 1">
""")
    def test_no_eol(self):
        channels = (b"""
foo = Foo 1""", b"""
foo = Foo 2
bar = Bar 2
""")
        self.assertEqual(merge_channels(self.name, *channels), b"""
foo = Foo 1
bar = Bar 2
""")
예제 #22
0
    def test_section_in_first(self):
        channels = (b"""
[[ Section 1 ]]
foo = Foo 1
""", b"""
foo = Foo 2
""")
        self.assertEqual(merge_channels(self.name, *channels), b"""
[[ Section 1 ]]
foo = Foo 1
""")
예제 #23
0
    def test_message_still_in_last(self):
        channels = (b"""
foo = Foo 1
""", b"""
foo = Foo 2
bar = Bar 2
""")
        self.assertEqual(merge_channels(self.name, channels), b"""
foo = Foo 1
bar = Bar 2
""")
    def test_group_comment_in_first(self):
        channels = (b"""
## Group Comment 1
foo = Foo 1
""", b"""
foo = Foo 2
""")
        self.assertEqual(merge_channels(self.name, *channels), b"""
## Group Comment 1
foo = Foo 1
""")
예제 #25
0
    def test_section_comment_in_last(self):
        channels = (b"""
[[ Section ]]
""", b"""
// Comment 2
[[ Section ]]
""")
        self.assertEqual(
            merge_channels(self.name, *channels), b"""
[[ Section ]]
""")
예제 #26
0
    def test_message_added_in_first(self):
        channels = (b"""
foo = Foo 1
bar = Bar 1
""", b"""
foo = Foo 2
""")
        self.assertEqual(merge_channels(self.name, channels), b"""
foo = Foo 1
bar = Bar 1
""")
예제 #27
0
    def test_tag_in_last(self):
        channels = (b"""
foo = Foo 1
""", b"""
foo = Foo 2
    #tag
""")
        self.assertEqual(
            merge_channels(self.name, *channels), b"""
foo = Foo 1
""")
예제 #28
0
    def test_message_comment_in_last(self):
        channels = (b"""
foo = Foo 1
""", b"""
# Comment 2
foo = Foo 2
""")
        self.assertEqual(
            merge_channels(self.name, channels), b"""
foo = Foo 1
""")
예제 #29
0
    def test_no_eol(self):
        channels = (b"""
foo = Foo 1""", b"""
foo = Foo 2
bar = Bar 2
""")
        self.assertEqual(
            merge_channels(self.name, *channels), b"""
foo = Foo 1
bar = Bar 2
""")
예제 #30
0
    def test_attribute_in_first(self):
        channels = (b"""
foo = Foo 1
    .attr = Attr 1
""", b"""
foo = Foo 2
""")
        self.assertEqual(merge_channels(self.name, channels), b"""
foo = Foo 1
    .attr = Attr 1
""")
예제 #31
0
    def test_attribute_in_last(self):
        channels = (b"""
foo = Foo 1
""", b"""
foo = Foo 2
    .attr = Attr 2
""")
        self.assertEqual(
            merge_channels(self.name, channels), b"""
foo = Foo 1
""")
예제 #32
0
    def test_junk_in_last(self):
        channels = (b"""\
one = entry
""", b"""\
line of junk
""")
        self.assertMultiLineEqual(
            merge_channels(self.name, channels).decode('utf-8'), """\
line of junk
one = entry
""")
예제 #33
0
    def test_message_still_in_last(self):
        channels = (b"""
foo = Foo 1
""", b"""
foo = Foo 2
bar = Bar 2
""")
        self.assertEqual(
            merge_channels(self.name, channels), b"""
foo = Foo 1
bar = Bar 2
""")
예제 #34
0
    def test_section_in_last(self):
        channels = (b"""
foo = Foo 1
""", b"""
[[ Section 2 ]]
foo = Foo 2
""")
        self.assertEqual(
            merge_channels(self.name, *channels), b"""
[[ Section 2 ]]
foo = Foo 1
""")
예제 #35
0
    def test_message_comment_in_first(self):
        channels = (b"""
// Comment 1
foo = Foo 1
""", b"""
foo = Foo 2
""")
        self.assertEqual(
            merge_channels(self.name, *channels), b"""
// Comment 1
foo = Foo 1
""")
예제 #36
0
    def test_attribute_in_first(self):
        channels = (b"""
foo = Foo 1
    .attr = Attr 1
""", b"""
foo = Foo 2
""")
        self.assertEqual(
            merge_channels(self.name, *channels), b"""
foo = Foo 1
    .attr = Attr 1
""")
예제 #37
0
    def test_message_comment_changed(self):
        channels = (b"""
// Comment 1
foo = Foo 1
""", b"""
// Comment 2
foo = Foo 2
""")
        self.assertEqual(merge_channels(self.name, *channels), b"""
// Comment 1
foo = Foo 1
""")
예제 #38
0
    def test_tag_changed(self):
        channels = (b"""
foo = Foo 1
    #tag1
""", b"""
foo = Foo 2
    #tag2
""")
        self.assertEqual(merge_channels(self.name, *channels), b"""
foo = Foo 1
    #tag1
""")
예제 #39
0
    def test_message_added_in_first(self):
        channels = (b"""
foo = Foo 1
bar = Bar 1
""", b"""
foo = Foo 2
""")
        self.assertEqual(
            merge_channels(self.name, channels), b"""
foo = Foo 1
bar = Bar 1
""")
예제 #40
0
    def test_group_comment_in_first(self):
        channels = (b"""
## Group Comment 1
foo = Foo 1
""", b"""
foo = Foo 2
""")
        self.assertEqual(
            merge_channels(self.name, channels), b"""
## Group Comment 1
foo = Foo 1
""")
예제 #41
0
    def test_message_reordered(self):
        channels = (b"""
foo = Foo 1
bar = Bar 1
""", b"""
bar = Bar 2
foo = Foo 2
""")
        self.assertEqual(merge_channels(self.name, channels), b"""
foo = Foo 1
bar = Bar 1
""")
    def test_resource_comment_in_last(self):
        channels = (b"""
foo = Foo 1
""", b"""
### Resource Comment 1

foo = Foo 2
""")
        self.assertEqual(merge_channels(self.name, *channels), b"""
### Resource Comment 1

foo = Foo 1
""")
예제 #43
0
    def test_message_reordered(self):
        channels = (b"""
foo = Foo 1
bar = Bar 1
""", b"""
bar = Bar 2
foo = Foo 2
""")
        self.assertEqual(
            merge_channels(self.name, channels), b"""
foo = Foo 1
bar = Bar 1
""")
    def test_standalone_comment_in_last(self):
        channels = (b"""
foo = Foo 1
""", b"""
foo = Foo 2

# Comment 2
""")
        self.assertEqual(merge_channels(self.name, *channels), b"""
foo = Foo 1

# Comment 2
""")
예제 #45
0
    def test_junk_in_last(self):
        channels = (b"""\
one = entry
""", b"""\
line of junk
""")
        self.assertMultiLineEqual(
            merge_channels(self.name, channels).decode('utf-8'),
            """\
line of junk
one = entry
"""
        )
예제 #46
0
    def test_tag_changed(self):
        channels = (b"""
foo = Foo 1
    #tag1
""", b"""
foo = Foo 2
    #tag2
""")
        self.assertEqual(
            merge_channels(self.name, *channels), b"""
foo = Foo 1
    #tag1
""")
    def test_blank_lines_between_messages(self):
        channels = (b"""
foo = Foo 1

bar = Bar 1
""", b"""
foo = Foo 2
bar = Bar 2
""")
        self.assertEqual(merge_channels(self.name, *channels), b"""
foo = Foo 1

bar = Bar 1
""")
예제 #48
0
    def test_comment_still_in_last(self):
        channels = (b"""
foo = Foo 1
bar = Bar 1
""", b"""
foo = Foo 2
# Bar Comment 2
bar = Bar 2
""")
        self.assertMultiLineEqual(
            merge_channels(self.name, channels).decode("utf-8"), """
foo = Foo 1
bar = Bar 1
""")
예제 #49
0
    def test_standalone_comment_in_first(self):
        channels = (b"""
foo = Foo 1

// Comment 1
""", b"""
foo = Foo 2
""")
        self.assertEqual(
            merge_channels(self.name, *channels), b"""
foo = Foo 1

// Comment 1
""")
예제 #50
0
 def createWorkdir(self, contents):
     workdir = self.graph.target.git.workdir
     for tpath, content_list in contents.items():
         try:
             b_content = merge_channels(tpath, content_list)
         except MergeNotSupportedError:
             b_content = content_list[0]
         tpath = mozpath.join(workdir, tpath)
         tdir = mozpath.dirname(tpath)
         if not os.path.isdir(tdir):
             os.makedirs(tdir)
         with open(tpath, "wb") as fh:
             fh.write(b_content)
     self.ensureL10nToml(workdir)
예제 #51
0
    def test_resource_comment_in_last(self):
        channels = (b"""
foo = Foo 1
""", b"""
### Resource Comment 1

foo = Foo 2
""")
        self.assertEqual(
            merge_channels(self.name, channels), b"""
### Resource Comment 1

foo = Foo 1
""")
예제 #52
0
    def test_standalone_comment_in_last(self):
        channels = (b"""
foo = Foo 1
""", b"""
foo = Foo 2

# Comment 2
""")
        self.assertEqual(
            merge_channels(self.name, channels), b"""
foo = Foo 1

# Comment 2
""")
예제 #53
0
    def test_group_comment_changed(self):
        channels = (b"""
## Group Comment 1
foo = Foo 1
""", b"""
## Group Comment 2
foo = Foo 2
""")
        self.assertEqual(
            merge_channels(self.name, channels), b"""
## Group Comment 2
## Group Comment 1
foo = Foo 1
""")
예제 #54
0
    def test_comment_added_in_first(self):
        channels = (b"""
foo = Foo 1
# Bar Comment 1
bar = Bar 1
""", b"""
foo = Foo 2
bar = Bar 2
""")
        self.assertMultiLineEqual(
            merge_channels(self.name, channels).decode("utf-8"), """
foo = Foo 1
# Bar Comment 1
bar = Bar 1
""")
예제 #55
0
    def test_blank_lines_between_messages(self):
        channels = (b"""
foo = Foo 1

bar = Bar 1
""", b"""
foo = Foo 2
bar = Bar 2
""")
        self.assertEqual(
            merge_channels(self.name, *channels), b"""
foo = Foo 1

bar = Bar 1
""")
예제 #56
0
    def test_encoding(self):
        channels = (encode(u"""
foo = Foo 1…
""", "utf8"), encode(u"""
foo = Foo 2…
""", "utf8"))
        output = merge_channels(self.name, channels)
        self.assertEqual(output, encode(u"""
foo = Foo 1…
""", "utf8"))

        u_output = decode(output, "utf8")
        self.assertEqual(u_output, u"""
foo = Foo 1…
""")
예제 #57
0
    def test_group_comment_and_section(self):
        channels = (b"""
## Group Comment
foo = Foo 1
""", b"""
// Section Comment
[[ Section ]]
foo = Foo 2
""")
        self.assertEqual(
            merge_channels(self.name, channels), b"""
// Section Comment
[[ Section ]]
## Group Comment
foo = Foo 1
""")
예제 #58
0
    def test_comment_changed(self):
        channels = (b"""
foo = Foo 1
# Bar Comment 1
bar = Bar 1
""", b"""
foo = Foo 2
# Bar Comment 2
bar = Bar 2
""")
        self.assertMultiLineEqual(
            merge_channels(self.name, *channels), b"""
foo = Foo 1
# Bar Comment 1
bar = Bar 1
""")
예제 #59
0
    def test_comment_still_in_last(self):
        channels = (b"""
# Foo Comment 1
foo = Foo 1
""", b"""
# Standalone Comment 2

# Foo Comment 2
foo = Foo 2
""")
        self.assertMultiLineEqual(
            merge_channels(self.name, channels).decode("utf-8"), """
# Standalone Comment 2

# Foo Comment 1
foo = Foo 1
""")