예제 #1
0
    def test_check_for_invalid_strings_po_encoding(self):
        ReportManager.getEnabledReporters()[0].reports = []

        path = join(self.path, "encoding")
        language_path = join(path, "resources", "language",
                             "resource.language.en_gb")
        full_path = join(language_path, "strings.po")

        file_index = [{"path": language_path, "name": "strings.po"}]

        expected = [
            "ERROR: Invalid PO file {path}: "
            "File is not saved with UTF-8 encoding".format(
                path=relative_path(full_path))
        ]

        check_for_invalid_strings_po(self.report, file_index)

        records = [
            Record.__str__(r)
            for r in ReportManager.getEnabledReporters()[0].reports
        ]
        output = [s for s in records if s.startswith(self.report_matches)]

        self.assertListEqual(expected, output)
예제 #2
0
    def test_check_for_invalid_strings_po_missing_en_gb(self):
        ReportManager.getEnabledReporters()[0].reports = []

        path = join(self.path, "path_check")
        language_path = join(path, "resources", "language")

        file_index = [{
            "path": join(language_path, "resource.language.en_us"),
            "name": "strings.po"
        }]

        expected = ["ERROR: Required default language 'en_gb' is not present."]

        check_for_invalid_strings_po(self.report, file_index)

        matches = (
            self.report_matches,
            "ERROR: Required default language",
        )

        records = [
            Record.__str__(r)
            for r in ReportManager.getEnabledReporters()[0].reports
        ]
        output = [s for s in records if s.startswith(matches)]
        self.assertListEqual(expected, output)
예제 #3
0
    def test_check_for_invalid_strings_po_missing_header(self):
        ReportManager.getEnabledReporters()[0].reports = []

        path = join(self.path, "missing_header")
        language_path = join(path, "resources", "language",
                             "resource.language.en_gb")
        full_path = join(language_path, "strings.po")

        file_index = [{"path": language_path, "name": "strings.po"}]

        expected = [
            'ERROR: Invalid PO file {path}:\n'
            'Missing required header:\n'
            '\tmsgid ""\n\tmsgstr ""'.format(path=relative_path(full_path))
        ]

        check_for_invalid_strings_po(self.report, file_index)

        records = [
            Record.__str__(r)
            for r in ReportManager.getEnabledReporters()[0].reports
        ]
        output = [s for s in records if s.startswith(self.report_matches)]

        self.assertListEqual(expected, output)
예제 #4
0
    def test_check_for_invalid_strings_po_language_code(self):
        ReportManager.getEnabledReporters()[0].reports = []

        path = join(self.path, "path_check")
        language_path = join(path, "resources", "language")

        file_index = [{
            "path": join(language_path, "resource.language.testing"),
            "name": "strings.po"
        }, {
            "path": join(language_path, "resource.language.en_gb"),
            "name": "strings.po"
        }]

        expected = [
            "ERROR: PO file with invalid language code in the correct path: {path}"
            .format(path=relative_path(
                join(language_path, "resource.language.testing",
                     "strings.po")))
        ]

        check_for_invalid_strings_po(self.report, file_index)

        matches = (
            self.report_matches,
            "ERROR: PO file with invalid language code in the correct path")

        records = [
            Record.__str__(r)
            for r in ReportManager.getEnabledReporters()[0].reports
        ]
        output = [s for s in records if s.startswith(matches)]

        self.assertListEqual(expected, output)
예제 #5
0
    def test_check_for_invalid_strings_po_valid_file(self):
        ReportManager.getEnabledReporters()[0].reports = []

        path = join(self.path, "valid_file")
        file_index = [{"path": path, "name": "strings.po"}]

        expected = []

        check_for_invalid_strings_po(self.report, file_index)

        records = [Record.__str__(r) for r in ReportManager.getEnabledReporters()[0].reports]
        output = [s for s in records if s.startswith(self.report_matches)]

        self.assertListEqual(expected, output)
예제 #6
0
    def test_check_for_invalid_strings_po_empty(self):
        ReportManager.getEnabledReporters()[0].reports = []

        path = join(self.path, "empty")
        full_path = join(path, "strings.po")

        file_index = [{"path": path, "name": "strings.po"}]

        expected = ["ERROR: Invalid PO file {path}: File is empty".format(path=relative_path(full_path))]

        check_for_invalid_strings_po(self.report, file_index)

        records = [Record.__str__(r) for r in ReportManager.getEnabledReporters()[0].reports]
        output = [s for s in records if s.startswith(self.report_matches)]

        self.assertListEqual(expected, output)
예제 #7
0
 def test_check_file_permission_is_true(self):
     self.path = join(HERE, 'test_data', 'Executable file')
     self.string = "ERROR: .{path}/file_permission.py is marked as stand-alone executable".format(
         path=self.path)
     file_index = create_file_index(self.path)
     check_file_permission(self.report, file_index)
     records = [
         Record.__str__(r)
         for r in ReportManager.getEnabledReporters()[0].reports
     ]
     flag = any(s == self.string for s in records)
     self.assertTrue(flag)
예제 #8
0
 def test_gitignore(self):
     path = join(HERE, 'test_data', 'GitIgnore')
     string = "WARN: Found non whitelisted file ending in filename {path}" \
         .format(path=relative_path(join(path, ".gitignore")))
     file_index = create_file_index(path)
     check_file_whitelist(self.report, file_index, path)
     records = [
         Record.__str__(r)
         for r in ReportManager.getEnabledReporters()[0].reports
     ]
     self.assertGreater(len(records), 0)
     self.assertEqual(records[-1], string)
예제 #9
0
    def test_start(self):
        start(self.path, self.args, self.all_repo_addons, self.config)
        records = [Record.__str__(r) for r in ReportManager.getEnabledReporters()[0].reports]

        # Comparing the whitelist with the list of output we get from addon-checker tool
        for white_str in self.whitelist:
            for value in records:
                if white_str.lower() == value.lower():
                    break
            else:
                flag = False
        else:
            flag = True

        self.assertTrue(flag)
예제 #10
0
 def test_check_file_permission_is_true(self):
     path = join(HERE, 'test_data', 'Executable_file')
     string = "ERROR: {path} is marked as stand-alone executable"\
         .format(path=relative_path(join(path, "file_permission.py")))
     file_index = create_file_index(path)
     check_file_permission(self.report, file_index)
     records = [
         Record.__str__(r)
         for r in ReportManager.getEnabledReporters()[0].reports
     ]
     flag = any(s == string for s in records)
     if os.name == "nt":
         self.assertFalse(flag)
     else:
         self.assertTrue(flag)