OnJava8-Examples/verify_output.py

45 lines
1.5 KiB
Python
Raw Normal View History

2015-12-02 09:20:27 -08:00
# Requires Python 3.5 or greater
2015-12-15 11:47:04 -08:00
# (c)2016 MindView LLC: see Copyright.txt
2015-12-02 09:20:27 -08:00
# We make no guarantees that this code is fit for any purpose.
# Visit http://mindviewinc.com/Books/OnJava/ for more book information.
"""
ToDo:
- Validate errors
"""
from pathlib import Path
from output_duet import Duet, Valid
import os
2015-12-15 11:47:04 -08:00
import collections
import pprint
2015-12-02 09:20:27 -08:00
2015-12-15 11:47:04 -08:00
def trace(*str): pass
# trace = print
2015-12-02 09:20:27 -08:00
if __name__ == '__main__':
2015-12-15 11:47:04 -08:00
jfiles = sorted([java.name for java in Path(".").glob("**/*.java")])
duplicates = sorted([x for x, y in collections.Counter(jfiles).items() if y > 1])
if duplicates:
print("Duplicates:")
pprint.pprint(duplicates)
2015-12-02 09:20:27 -08:00
count = 0
for output in Path(".").glob("**/*.out"):
duet = Duet(output)
2015-12-15 11:47:04 -08:00
trace("duet.ignore:", duet.ignore, duet.java_path )
if duet.ignore:
continue
2015-12-02 09:20:27 -08:00
v = duet.validate()
if v is Valid.fail:
with Path("validate_failures.txt").open('a') as vf:
print(duet, file = vf)
with Path("strategies.txt").open('a') as st:
2015-12-15 11:47:04 -08:00
print(' "' + duet.java_path.name + '" : IgnoreSortedLines(),', file = st)
2015-12-02 09:20:27 -08:00
with Path("update_output.bat").open('a') as uo:
2015-12-15 11:47:04 -08:00
print('call u ' + str(duet.out_path), file = uo)
2015-12-02 09:20:27 -08:00
count += 1
2015-12-15 11:47:04 -08:00
print("\n" + " Verified files = {} ".format(count).center(60, "*"))
if Path("validate_failures.txt").exists():
os.system("subl update_output.bat strategies.txt validate_failures.txt")
else:
print("\n" + " No Output Errors ".center(60, "="))