-
Notifications
You must be signed in to change notification settings - Fork 0
/
templates.py
50 lines (39 loc) · 1.49 KB
/
templates.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
#!/usr/bin/env python3
# Importing needed things, defining terminal elements of the grammar, defining generator and
# __main__, and declaring needed variables
class_template = '''#!/usr/bin/env python3
import os
import random
import sys
from templates import test_file
# Local packages
from arg_parser import _constants
class TestGenerator():
random.seed({SEED})
{GENERATED_FUNCTIONS}
def number(self):
num = random.randint(_constants.min, _constants.max)
return "(" + str(num) + ")"
def operator(self):
operator_array = ["+", "-", "*", "/", "%", "|", "&", "^"]
return operator_array[random.randint(0, len(operator_array) - 1)]
def generate(self):
test_count = 0
file_count = 1
if not os.path.isdir(_constants.generated_folder):
os.makedirs(_constants.generated_folder)
while test_count != {TEST_COUNT}:
with open (os.path.join(_constants.generated_folder, test_file.format(NO = file_count)), "w") as file:
for i in range(0, {TEST_CASES_IN_A_FILE}):
test_count += 1
file.write(self.{STARTER_FUNCTION}())
if test_count != {TEST_CASES_IN_A_FILE} and test_count != {TEST_COUNT}:
file.write(\",\\n\")
else:
break
file_count += 1
if __name__ == '__main__':
generator = TestGenerator()
generator.generate()
'''
test_file = '''testfile{NO}.js'''