-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·57 lines (49 loc) · 1.54 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
#!/usr/bin/env python3
import sys, os
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def custom_read(f):
for line in f.readlines():
if line.strip() != None:
print(line, end="")
filepath = sys.argv[1]
filepath_splited = filepath.split('/')
if len(filepath_splited) == 1:
contest = '.'
else:
contest = '/'.join(filepath_splited[:-1])
problem = filepath_splited[-1]
files = os.listdir(contest)
# print(files)
for file in files:
if file.startswith(problem):
extension = file.split('.')[-1]
if extension == 'py':
continue
if extension == 'inp':
# print(f"Input {file.split('.')[0][1:]}:")
with open(contest + '/' + file) as f:
custom_read(f)
# print(f"Actual Output {file.split('.')[0][1:]}:")
print(f"\n-------------------------------{bcolors.OKBLUE}")
os.system(f"python3 {filepath}.py < {contest}/{file}")
print(bcolors.OKGREEN, end="")
try:
with open(contest + '/' + file.split('.')[0] + '.out') as f:
# print(f"Required Output {file.split('.')[0][1:]}:")
print(f.read())
except:
print("No output file found!")
print(bcolors.ENDC)
print()
# os.rename(file, problem + '.cpp')
else:
continue