Added tests

This commit is contained in:
Ayrton 2023-11-20 18:52:14 -07:00
parent 04675a01d6
commit 05c8f92683
3 changed files with 28 additions and 4 deletions

View file

@ -2,7 +2,7 @@ import random
import string
import xml.etree.ElementTree as ET
from english_words import get_english_words_set
# from english_words import get_english_words_set
from constants import *
@ -38,7 +38,8 @@ class AstGenerator:
self.symbol_table.append(global_scope) # NOTE for debug
self.current_scope = global_scope
names = get_english_words_set(['web2'], lower=True)
# names = get_english_words_set(['web2'], lower=True)
names = random.choices(string.ascii_letters, k=self.settings['properties']['id-length']['max'])
possible_names = filter(lambda x: self.settings['properties']['id-length']['min'] < len(x)
< self.settings['properties']['id-length']['max'], names)

View file

@ -267,7 +267,7 @@ class TestGeneration(unittest.TestCase):
def test_failing_assignment(self):
self.ast_gen.ast = ET.Element("block")
self.ast_gen.current_ast_element = self.ast_gen.ast
self.ast_gen.generate_main()
# self.ast_gen.generate_main()
with self.assertRaises(ValueError):
self.ast_gen.generate_assignment()

View file

@ -13,7 +13,7 @@ from ast_generator.ast_generator import AstGenerator
from ast_parser.python_unparser import PythonUnparser
class MyTestCase(unittest.TestCase):
class TestCorrectness(unittest.TestCase):
@classmethod
def setUpClass(cls):
with open("config.yaml", 'r') as stream:
@ -128,7 +128,30 @@ class MyTestCase(unittest.TestCase):
print(self.python_unparser.source)
self.fail(e)
def test_routine(self):
self.ast_gen.ast = ET.Element("block")
self.ast_gen.current_ast_element = self.ast_gen.ast
self.ast_gen.generate_routine()
self.python_unparser.xml = self.ast_gen.ast
self.python_unparser.unparse()
try:
exec(self.python_unparser.source)
except Exception as e:
print(self.python_unparser.source)
self.fail(e)
def test_program(self):
self.ast_gen.generate_ast()
self.python_unparser.xml = self.ast_gen.ast
self.python_unparser.unparse()
try:
exec(self.python_unparser.source)
except Exception as e:
print(self.python_unparser.source)
self.fail(e)
if __name__ == '__main__':
unittest.main()