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_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)
def test_check_file_permission_is_true(self): self.path = join(HERE, 'test_data', 'Executable_file') self.string = "ERROR: {path} is marked as stand-alone executable"\ .format(path=relative_path(join(self.path, "file_permission.py"))) 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)
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)
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)