Lines Matching +full:test +full:- +full:path

3 # Copyright (c) 2020-2021 Virtuozzo International GmbH
20 from pathlib import Path
39 def silent_unlink(path: Path) -> None: argument
41 path.unlink()
46 def file_diff(file1: str, file2: str) -> List[str]:
47 with open(file1, encoding="utf-8") as f1, \
48 open(file2, encoding="utf-8") as f2:
61 """ Cache for elapsed time for tests, to show it during new test run
64 use it inside with-block or use save() after update().
66 def __init__(self, cache_file: str, env: TestEnv) -> None:
72 with open(cache_file, encoding="utf-8") as f:
77 def get(self, test: str,
78 default: Optional[float] = None) -> Optional[float]:
79 if test not in self.cache:
82 if self.env.imgproto not in self.cache[test]:
85 return self.cache[test][self.env.imgproto].get(self.env.imgfmt,
88 def update(self, test: str, elapsed: float) -> None:
89 d = self.cache.setdefault(test, {})
92 def save(self) -> None:
93 with open(self.cache_file, 'w', encoding="utf-8") as f:
96 def __enter__(self) -> 'LastElapsedTime':
99 def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None:
106 casenotrun: str = '', interrupted: bool = False) -> None:
119 def proc_run_test(test: str, test_field_width: int) -> TestResult:
123 return runner.run_test(test, test_field_width, mp=True)
126 test_field_width: int, jobs: int) -> List[TestResult]:
142 color: str = 'auto') -> None:
145 self.last_elapsed = LastElapsedTime('.last-elapsed-cache', env)
153 def __enter__(self) -> 'TestRunner':
159 def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None:
162 def test_print_one_line(self, test: str,
169 end: str = '\n') -> None:
170 """ Print short test info before/after test run """
171 test = os.path.basename(test)
178 print(f'ok {self.env.imgfmt} {test}')
180 print(f'not ok {self.env.imgfmt} {test}')
182 print(f'ok {self.env.imgfmt} {test} # SKIP')
214 print(f'{test:{test_field_width}} {col}{status:10}{col_end} '
218 def find_reference(self, test: str) -> str:
220 ref = f'{test}.out.nocache'
221 if os.path.isfile(ref):
224 ref = f'{test}.out.{self.env.imgfmt}'
225 if os.path.isfile(ref):
228 ref = f'{test}.{self.env.qemu_default_machine}.out'
229 if os.path.isfile(ref):
232 return f'{test}.out'
234 def do_run_test(self, test: str) -> TestResult:
236 Run one test
238 :param test: test file path
244 f_test = Path(test)
245 f_reference = Path(self.find_reference(test))
249 description=f'No such test file: {f_test}')
262 # Split test directories, so that tests running in parallel don't
265 env[d] = os.path.join(
267 f"{self.env.imgfmt}-{self.env.imgproto}-{f_test.name}")
268 Path(env[d]).mkdir(parents=True, exist_ok=True)
271 f_bad = Path(test_dir, f_test.name + '.out.bad')
272 f_notrun = Path(test_dir, f_test.name + '.notrun')
273 f_casenotrun = Path(test_dir, f_test.name + '.casenotrun')
279 with f_bad.open('w', encoding="utf-8") as f:
293 elapsed = round(time.time() - t0, 1)
303 description=f_notrun.read_text(encoding='utf-8').strip())
307 casenotrun = f_casenotrun.read_text(encoding='utf-8')
324 def run_test(self, test: str,
326 mp: bool = False) -> TestResult:
328 Run one test and print short status
330 :param test: test file path
339 last_el = self.last_elapsed.get(test)
343 self.test_print_one_line(test=test,
350 testname = os.path.basename(test)
353 res = self.do_run_test(test)
356 self.test_print_one_line(test=test,
372 def run_tests(self, tests: List[str], jobs: int = 1) -> bool:
385 test_field_width = max(len(os.path.basename(t)) for t in tests) + 2
391 name = os.path.basename(t)