From b6265d1f681945494b49ee551d96f1a62331e10a Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Aug 15 2019 18:25:55 +0000 Subject: Fix tests for removing defaults The tests were not accounting for the removal of a file. This patch changes the get_index_and_defaults() function to return FileNotFoundError instead of IOError when the file does not exist for a commit and then changes the logic of the consuming function to handle IOError and FileNotFoundError appropriately. Signed-off-by: Stephen Gallagher --- diff --git a/tests/compare_defaults.py b/tests/compare_defaults.py index 346b304..5b1d9b9 100755 --- a/tests/compare_defaults.py +++ b/tests/compare_defaults.py @@ -21,12 +21,9 @@ def get_index_and_defaults (repo, filename, commit): try: yaml = repo.git.show('%s:%s' % (commit, filename)) except git.exc.GitCommandError as e: - # This file didn't exist in the baseline commit, so just return - # IOError to skip checking it. - # If there's anything wrong with the new file, it will be caught in - # common_tests.sh - raise IOError("No baseline file") - + # This file didn't exist in the commit, so return + # FileNotFoundError to skip checking it. + raise FileNotFoundError("{} does not exist at commit {}".format(filename, commit)) index = Modulemd.ModuleIndex.new() @@ -67,17 +64,26 @@ def main(): try: baseline_index, baseline_defaults = get_index_and_defaults ( repo, filename, baseline_commit) - except IOError as e: - # Either the baseline file didn't exist or was itself invalid (which - # should never happen...). In either case, there's no valid original + except FileNotFoundError as e: + # The baseline file didn't exist, so there's no valid original # to compare to. Check it only with validate.py. print(e, file=sys.stderr) return unusable_baseline() + except IOError as e: + # The baseline file was invalid (which should never happen...). + # Check it only with validate.py (in case this PR is trying to + # correct the situation + print(e, file=sys.stderr) + return os.EX_DATAERR try: updated_commit = updated_commit updated_index, updated_defaults = get_index_and_defaults ( repo, filename, updated_commit) + except FileNotFoundError as e: + # The PR is removing this file. Assume that this is acceptable + print("{} is being removed. Not performing any comparison tests.".format(filename), file=sys.stderr) + return os.EX_OK except IOError as e: # If we hit this, the patch is broken. print(e, file=sys.stderr)