From 05c8f926835f0badb5d93de12688079b64920e47 Mon Sep 17 00:00:00 2001 From: Ayrton Date: Mon, 20 Nov 2023 18:52:14 -0700 Subject: [PATCH] Added tests --- ast_generator/ast_generator.py | 5 +++-- ast_generator/test/test_ast_generator.py | 2 +- test/test_correctness.py | 25 +++++++++++++++++++++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/ast_generator/ast_generator.py b/ast_generator/ast_generator.py index 3490121..facbeef 100644 --- a/ast_generator/ast_generator.py +++ b/ast_generator/ast_generator.py @@ -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) diff --git a/ast_generator/test/test_ast_generator.py b/ast_generator/test/test_ast_generator.py index ed20b2d..8890367 100644 --- a/ast_generator/test/test_ast_generator.py +++ b/ast_generator/test/test_ast_generator.py @@ -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() diff --git a/test/test_correctness.py b/test/test_correctness.py index a256fff..7e229ab 100644 --- a/test/test_correctness.py +++ b/test/test_correctness.py @@ -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()