def validate(self, full_path, i=0): """ Run validation tests against the data in the given directory. """ top_dir = os.path.basename(full_path) if top_dir.startswith(self.VALID_DATA_NAME): print("-------\n[{0}.] Checking data in '{1}'; should be valid...". format(i, full_path)) checker = checkloc.CheckLoc(manifest_dir=full_path, locales_only=self.LOCALES_ONLY) errors = checker.validate_loc_files() self.tester.assertFalse(errors) elif top_dir.startswith(self.INVALID_DATA_NAME): print( "-------\n[{0}.] Checking invalid data in '{1}'; should find an error..." .format(i, full_path)) checker = checkloc.CheckLoc(manifest_dir=full_path, locales_only=self.LOCALES_ONLY) errors = checker.validate_loc_files() self.tester.assertTrue(errors) elif top_dir.startswith(self.WARNING_NAME): print( "-------\n[{0}.] Checking warning data in '{1}'; should generate a warning..." .format(i, full_path)) # capture all warnings so we can verify that they happen with warnings.catch_warnings(record=True) as warn_list: checker = checkloc.CheckLoc(manifest_dir=full_path, locales_only=self.LOCALES_ONLY) errors = checker.validate_loc_files() self.tester.assertFalse( errors, "Warning test '{0}' should not generate any errors.". format(full_path)) self.tester.assertTrue( len(warn_list) > 0, "Warning test '{0}' should generate at least one warning.". format(full_path)) self.tester.assertTrue( issubclass(warn_list[-1].category, Warning), "Warning test '{0}' should generate a warning of type Warning." .format(full_path)) # with catch_warnings() the behaviour changes so warnings # are no longer printed to stdout. # print them to stdout so users can still see what is going on. for warn in warn_list: logging.warning(warn.message) else: raise Exception( "validate() called with '{0}' - this is not a valid type of data!" .format(full_path))
def test_finding_no_baseline_folder_raises_an_error(self): base_dir = os.path.join(self.test_data_dir, 'other_no_baseline') self.assertTrue( os.path.exists(base_dir), "Test setup: directory {0} should exist".format(base_dir)) self.assertTrue(os.path.isdir(base_dir), "Test setup: {0} is not a directory".format(base_dir)) checker = checkloc.CheckLoc(locales_only=True, manifest_dir=base_dir) errors = checker.validate_loc_files() self.assertTrue(errors)
def test_passing_non_manifest_file_raises_an_error(self): file_name = os.path.join(self.test_data_dir, 'test_file.txt') self.assertTrue(os.path.exists(file_name), "Test setup: file {0} should exist".format(file_name)) self.assertFalse( os.path.isdir(file_name), "Test setup: file {0} is a directory".format(file_name)) checker = checkloc.CheckLoc(locales_only=True, manifest_dir=file_name) errors = checker.validate_loc_files() self.assertTrue(errors)
def test_nonexistent_directories_raise_an_error(self): non_existent_dir = os.path.join(self.test_data_dir, 'null_empty') self.assertFalse( os.path.exists(non_existent_dir), "Test setup: directory {0} should not exist".format( non_existent_dir)) checker = checkloc.CheckLoc(locales_only=True, manifest_dir=non_existent_dir) errors = checker.validate_loc_files() self.assertTrue(errors)
def test_finding_no_loc_data_raises_an_error(self): # by this we mean: no Mozilla-style localization data of any kind. # the folder could contain anything, but it's not in the format we're expecting. # the script should still fail gracefully in this case. base_dir = self.test_data_dir self.assertTrue( os.path.exists(base_dir), "Test setup: directory {0} should exist".format(base_dir)) self.assertTrue(os.path.isdir(base_dir), "Test setup: {0} is not a directory".format(base_dir)) checker = checkloc.CheckLoc(manifest_dir=base_dir) errors = checker.validate_loc_files() self.assertTrue(errors)
def test_passing_manifest_file_rather_than_manifest_directory_succeeds( self): manifest_file = os.path.join(self.test_data_dir, 'manifest_valid_data', 'chrome.manifest') self.assertTrue( os.path.exists(manifest_file), "Test setup: manifest file '{0}' should exist".format( manifest_file)) self.assertFalse( os.path.isdir(manifest_file), "Test setup: file '{0}' is a directory".format(manifest_file)) checker = checkloc.CheckLoc(manifest_dir=manifest_file) errors = checker.validate_loc_files() self.assertFalse(errors)