-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest_all.py
More file actions
37 lines (34 loc) · 1.55 KB
/
Copy pathtest_all.py
File metadata and controls
37 lines (34 loc) · 1.55 KB
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
import subprocess, pathlib, re, runpy, sys, operator, contextlib, io, \
difflib, time, webbrowser, argparse, tempfile, os, filecmp
t00 = time.perf_counter()
službeni = pathlib.Path('out_test.txt')
argv = argparse.ArgumentParser()
argv.add_argument('--replace', action='store_true')
argv = argv.parse_args()
izlaz = io.StringIO()
datoteke = sorted((datoteka for datoteka in pathlib.Path().glob('*/*.py')
if re.match(r'\d\d_', datoteka.stem)), key=operator.attrgetter('stem'))
for datoteka in datoteke:
t0 = time.perf_counter()
print(datoteka.stem.center(78, '#'), flush=True, file=izlaz)
rezultat = subprocess.run([sys.executable, '-X', 'utf8', str(datoteka)],
capture_output=True, check=True, text=True,
encoding='utf-8', input='2\n')
print(rezultat.stdout, end='', file=izlaz)
print(format(time.perf_counter() - t0, '.3f'), datoteka)
print(f'Ukupno {time.perf_counter()-t00:.3f}s')
if argv.replace: službeni.write_text(izlaz.getvalue(), encoding='utf-8')
else:
fromlines = službeni.read_text(encoding='utf-8').splitlines()
tolines = izlaz.getvalue().splitlines()
if fromlines == tolines: print('Nema razlike.')
else:
diff = difflib.HtmlDiff(wrapcolumn=79)
diff = diff.make_file(fromlines, tolines, context=True)
with tempfile.NamedTemporaryFile(
mode='w', prefix='_vepar_', delete=False,
encoding='utf-8') as tmp:
print(diff, file=tmp)
webbrowser.open(tmp.name, 2)
time.sleep(6)
pathlib.Path(tmp.name).unlink()