From c1e409e6934ba298cc71dfb7c6a0079d2038b09d Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Fri, 20 Feb 2015 14:07:57 +0100 Subject: [doc] Add support for additional input files in test/DocTests.py by allowing file: and with_file: options on examples. --- test/DocTests.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'test/DocTests.py') diff --git a/test/DocTests.py b/test/DocTests.py index 6f0276da..f5746ec4 100755 --- a/test/DocTests.py +++ b/test/DocTests.py @@ -24,10 +24,12 @@ class DocTests: self.testin_token = 'command' self.testout_token = 'output' self.testdat_token = 'input' + self.testfile_token = 'file' self.validate_token = 'validate' self.validate_cmd_token = 'validate-command' self.validate_dat_token = 'validate-data' self.testwithdat_token = 'with_input' + self.testwithfile_token = 'with_file' def read_example(self): endexample = re.compile(r'^@end\s+smallexample\s*$') @@ -44,8 +46,8 @@ class DocTests: return hashlib.sha1(example.rstrip()).hexdigest()[0:7].upper() def find_examples(self): - startexample = re.compile(r'^@smallexample\s+@c\s+(%s|%s|%s)(?::([\dA-Fa-f]+|validate))?(?:,(.*))?' - % (self.testin_token, self.testout_token, self.testdat_token)) + startexample = re.compile(r'^@smallexample\s+@c\s+(%s|%s|%s|%s)(?::([\dA-Fa-f]+|validate))?(?:,(.*))?' + % (self.testin_token, self.testout_token, self.testdat_token, self.testfile_token)) while True: line = self.file.readline() self.current_line += 1 @@ -187,6 +189,14 @@ class DocTests: elif os.path.exists(os.path.join(test_input_dir, test_file)): command[findex] = os.path.join(test_input_dir, test_file) try: + convert_idx = command.index('convert') + convert_file = command[convert_idx+1] + convert_data = example[self.testfile_token][self.testfile_token] + if not os.path.exists(convert_file): + with open(convert_file, 'w') as f: + f.write(convert_data) + except ValueError: + pass error = None try: verify = subprocess.check_output(command, stderr=subprocess.STDOUT) -- cgit v1.2.3