Skip parsing test files that don't need regeneration

This commit is contained in:
Richard Gibson 2021-07-27 15:07:52 -04:00 committed by Rick Waldron
parent e07f577a9c
commit 1483cdee1a
2 changed files with 7 additions and 8 deletions

View File

@ -49,8 +49,8 @@ def create(args):
for test in exp.expand('utf-8', caseFile):
if args.out:
try:
existing = Test(test.file_name)
existing.load(args.out)
test_file = os.path.join(args.out, test.file_name)
test_mtime = os.path.getmtime(test_file)
if args.no_clobber:
print_error(
@ -58,18 +58,18 @@ def create(args):
exit(1)
if not args.regenerate:
test_file = os.path.join(args.out, test.file_name)
test_mtime = os.path.getmtime(test_file)
source_files = test.source_file_names
if all(test_mtime > os.path.getmtime(f) for f in source_files):
continue
existing = Test(test_file)
existing.load()
if not existing.is_generated():
print_error(
'Refusing to overwrite non-generated file: ' +
test.file_name)
exit(1)
except IOError:
except (OSError, IOError):
pass
test.write(args.out, parents=args.parents)

View File

@ -24,9 +24,8 @@ class Test:
self.source = None
self.attribs = dict(meta=None)
def load(self, prefix = None):
location = os.path.join(prefix or '', self.file_name)
with open(location, 'r') as handle:
def load(self):
with open(self.file_name, 'r') as handle:
self.source = handle.read()
self._parse()