This repository was archived by the owner on Nov 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.py
75 lines (58 loc) · 2.06 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import ast
import sys
import tokenize
import traceback
import warnings
from argparse import ArgumentParser
from concurrent.futures import ProcessPoolExecutor, as_completed
from dataclasses import dataclass
from pathlib import Path
from typing import Any, List, Optional, Tuple
def ast_unparse_c(source):
ann = {}
exec(f"from __future__ import annotations; a: {source}", ann, ann)
return ann["__annotations__"]["a"]
@dataclass
class Report:
filename: Path
report: Any
def test_package_impl(file: Path) -> List[Any]:
reports = []
# IMPLEMENT HERE
return reports
def test_package_files(directory: Path) -> List[Report]:
reports = []
for file in directory.glob("**/*.py"):
# do whatever you want
for report in test_package_impl(file):
reports.append(Report(directory / file, report))
return reports
def test_package(directory: Path) -> Tuple[str, List[Report], Optional[str]]:
name = directory.name.split("-", -1)[0]
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
try:
reports = test_package_files(directory)
except Exception:
return (name, [], traceback.format_exc(limit=2))
return name, reports, None
def test_all(directory: Path, workers: int = 20):
with ProcessPoolExecutor(max_workers=workers) as executor:
futures = {executor.submit(test_package, d) for d in directory.iterdir()}
for future in as_completed(futures):
package, reports, errors = future.result()
if reports or errors:
print("=" * 50)
print("Package:", package)
for report in reports:
print(report)
if errors:
print(f"While testing an exception caught: ", errors)
def main():
parser = ArgumentParser()
parser.add_argument("directory", type=Path)
parser.add_argument("--workers", type=int)
options = parser.parse_args()
test_all(**vars(options))
if __name__ == "__main__":
main()