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)
    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)
    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)
    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)
Beispiel #5
0
 def setUp(self):
     self.path = "script.test/"
     self.whitelist = ["INFO: Checking add-on script.test", "INFO: Created by mzfr", "INFO: This is a new addon"
                       "INFO: Image icon exists", "Icon dimensions are fine", "INFO: Image fanart exists",
                       "WARN: Complex entry point", "WARN: We found", "please check the logfile"]
     load_plugins()
     self.config = Config(self.path)
     ReportManager.enable(["array"])
     self.all_repo_addons = get_all_repo_addons()
     self.args = Args()
    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)
    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)
Beispiel #8
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)
Beispiel #9
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)
Beispiel #10
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)
Beispiel #11
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)
Beispiel #12
0
def check_repo(config, repo_path, parameters):
    repo_report = Report(repo_path)
    repo_report.add(Record(INFORMATION, "Checking repository %s" % repo_path))
    if len(parameters) == 0:
        toplevel_folders = sorted(next(os.walk(repo_path))[1])
    else:
        toplevel_folders = sorted(parameters)

    for addon_folder in toplevel_folders:
        if addon_folder[0] != '.':
            repo_report.add(
                Record(INFORMATION, "Checking add-on %s" % addon_folder))
            addon_path = os.path.join(repo_path, addon_folder)
            addon_report = check_addon.start(addon_path, config)
            repo_report.add(addon_report)

    if repo_report.problem_count > 0:
        repo_report.add(
            Record(
                PROBLEM,
                "We found %s problems and %s warnings, please check the logfile."
                % (repo_report.problem_count, repo_report.warning_count)))
    elif repo_report.warning_count > 0:
        repo_report.add(
            Record(
                WARNING,
                "We found %s problems and %s warnings, please check the logfile."
                % (repo_report.problem_count, repo_report.warning_count)))
    else:
        repo_report.add(
            Record(
                INFORMATION,
                "We found no problems and no warnings, please enjoy your day.")
        )

    ReportManager.report(repo_report)
Beispiel #13
0
 def process_config(cls, config):
     reporters = config["reporter"]
     if reporters is not None:
         # To disable all, pass empty array in .tests-config.json
         ReportManager.enable(reporters)
Beispiel #14
0
 def setUp(self):
     self.path = join(HERE, "test_data", "PO_files")
     load_plugins()
     ReportManager.enable(["array"])
     self.report = Report("")
     self.report_matches = ("ERROR: Invalid PO file")
Beispiel #15
0
 def setUp(self):
     load_plugins()
     ReportManager.enable(["array"])
     self.report = Report("")