46 lines
2.0 KiB
Python
46 lines
2.0 KiB
Python
"""Run every unittest, standalone test function and main-style contract."""
|
|
from pathlib import Path
|
|
import importlib.util
|
|
import inspect
|
|
import json
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
import unittest
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
TESTS=Path(__file__).resolve().parent
|
|
sys.path.insert(0, str(TESTS))
|
|
suite=unittest.TestSuite()
|
|
modules=[]
|
|
for path in sorted(TESTS.glob('test_*.py')):
|
|
spec=importlib.util.spec_from_file_location('verify_'+path.stem,path)
|
|
assert spec is not None and spec.loader is not None
|
|
module=importlib.util.module_from_spec(spec)
|
|
sys.modules[spec.name]=module
|
|
spec.loader.exec_module(module)
|
|
modules.append(module)
|
|
suite.addTests(unittest.defaultTestLoader.loadTestsFromModule(module))
|
|
result=unittest.TextTestRunner(verbosity=1).run(suite)
|
|
if not result.wasSuccessful(): sys.exit(1)
|
|
standalone=0
|
|
for module in modules:
|
|
for name,fn in inspect.getmembers(module,inspect.isfunction):
|
|
if name.startswith('test_') or name=='main':
|
|
fn()
|
|
standalone+=1
|
|
files=[ROOT/'SKILL.md',*sorted(ROOT.glob('references/*.md'))]
|
|
links=0
|
|
for path in files:
|
|
for link in re.findall(r'\]\(([^)]+)\)',path.read_text()):
|
|
if '://' in link or link.startswith(('#','<')): continue
|
|
target=link.split('#')[0]
|
|
if target:
|
|
assert (path.parent/target).exists(),(path,link)
|
|
links+=1
|
|
subprocess.run(['git','diff','--check'],cwd=ROOT,check=True)
|
|
before=sum(len(subprocess.check_output(['git','show','HEAD:'+str(p.relative_to(ROOT))],cwd=ROOT)) for p in files)
|
|
after=sum(p.stat().st_size for p in files)
|
|
ref_before=before-len(subprocess.check_output(['git','show','HEAD:SKILL.md'],cwd=ROOT))
|
|
ref_after=after-(ROOT/'SKILL.md').stat().st_size
|
|
print(json.dumps({'package':ROOT.name,'unittest':result.testsRun,'standalone':standalone,'total':result.testsRun+standalone,'local_links':links,'diff_check':'passed','operational_bytes_before':before,'operational_bytes_after':after,'reference_bytes_before':ref_before,'reference_bytes_after':ref_after},indent=2))
|