Added tests
This commit is contained in:
parent
04675a01d6
commit
05c8f92683
|
@ -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)
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue