def test_python3(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") # the grammar does not fully compile code = """ def addition(x, y): return x + y """ try: clparser, cllexer = get_parser_lexer("Python3") except ImportError: warnings.warn("Grammar for Python3 not ready yet.") return parser = parse_code(code, clparser, cllexer) try: tree = parser.single_input() except NameError as e: warnings.warn("Grammar for Python3 not ready yet: {0}".format(e)) return st = get_tree_string(tree, parser) fLOG(st.replace("\\n", "\n")) assert len(st) > 0
def test_csharp(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") code = """ namespace hello { public static class world { public static double function(double x, doubly y) { return x+y ; } } } """ clparser, cllexer = get_parser_lexer("C#") parser = parse_code(code, clparser, cllexer) tree = parser.compilation_unit() st = get_tree_string(tree, parser) fLOG(st.replace("\\n", "\n")) assert len(st) > 0
def test_r(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") code = """ a = 4 ; b = 5 ; c = a + b ; """ clparser, cllexer = get_parser_lexer("R") parser = parse_code(code, clparser, cllexer) tree = parser.parse() st = get_tree_string(tree, parser) assert len(st) > 0 st = get_tree_string(tree, parser, None) fLOG(st.replace("\\n", "\n")) assert len(st) > 0
def test_r(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") code = """ a = 4 ; b = 5 ; c = a + b ; """ clparser, cllexer = get_parser_lexer("R") parser = parse_code(code, clparser, cllexer) tree = parser.parse() st = get_tree_string(tree, parser) assert len(st) > 0 st = get_tree_string(tree, parser, None) fLOG(st.replace("\\n", "\n")) assert len(st) > 0
def test_simple_for_workflow(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") code = """ data_a = flowdata.DataCloud ; modb = flowmodule.RandomFilter( n= 100 ) ; connect data_a to modb.input ; if ( positive_number(modb.average)) { modc = flowmodule.Classify(model="LinearRegression") ; connect ( modb.data , modc.train_data ) ; if ( positive_number(modc.number)) { modc2 = flowmodule.Classify(model="SVM") ; connect ( modc.data , mod2.input ) ; for ( loopv in range(10) ) { modcl = flowmodule.Classify(model=loopv) ; connect ( modc2.data , modcl.output ) ; } } } """ clparser, cllexer = get_parser_lexer("SimpleWorkflow") parser = parse_code(code, clparser, cllexer) tree = parser.parse() st = get_tree_string(tree, parser) assert len(st) > 0 st = get_tree_graph(tree, parser) dot = st.to_dot() assert len(dot) > 0 if "travis" not in sys.executable: temp = get_temp_folder(__file__, "temp_simpleworkflow_grammar_for") name = os.path.join(temp, "graph.dot") with open(name, "w") as f: f.write(dot) img = os.path.join(temp, "graph.png") run_dot(name, img) assert os.path.exists(img)
def test_sql(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") code = """ SELECT a,tbl.b,nb FROM tbl INNER JOIN ( SELECT b, COUNT(*) AS nb FROM tbl ) AS tblG ON tbl.b == tblG.b ; """ clparser, cllexer = get_parser_lexer("SQLite") parser = parse_code(code, clparser, cllexer) tree = parser.parse() st = get_tree_string(tree, parser, None) fLOG(st.replace("\\n", "\n")) assert len(st) > 0
def test_extra(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") code = """ example of the language """ try: from pyensae.languages.LanguageLexer import LanguageLexer from pyensae.languages.LanguageParser import LanguageParser except ImportError: return parser = parse_code(code, LanguageParser, LanguageLexer) tree = parser.compilation_unit() st = get_tree_string(tree, parser) fLOG(st.replace("\\n", "\n")) assert len(st) > 0
def test_DOT(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") # the grammar does not fully compile code = """ digraph { A [label="a"] ; B [label="b"] ; A -> B ; """ clparser, cllexer = get_parser_lexer("DOT") parser = parse_code(code, clparser, cllexer) tree = parser.graph() st = get_tree_string(tree, parser) fLOG(st.replace("\\n", "\n")) assert len(st) > 0
def test_pig(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") code = """ A = LOAD 'filename.txt' USING PigStorage('\t'); STORE A INTO 'samefile.txt' ; """ try: clparser, cllexer = get_parser_lexer("Pig") except ImportError: warnings.warn("Grammar for Pig not ready yet.") return parser = parse_code(code, clparser, cllexer) tree = parser.compilation_unit() st = get_tree_string(tree, parser, None) fLOG(st.replace("\\n", "\n")) assert len(st) > 0
def test_sql(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") code = """ SELECT a,tbl.b,nb FROM tbl INNER JOIN ( SELECT b, COUNT(*) AS nb FROM tbl ) AS tblG ON tbl.b == tblG.b ; """ clparser, cllexer = get_parser_lexer("SQLite") parser = parse_code(code, clparser, cllexer) tree = parser.parse() st = get_tree_string(tree, parser, None) fLOG(st.replace("\\n", "\n")) assert len(st) > 0
def test_DOT(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") # the grammar does not fully compile code = """ digraph { A [label="a"] ; B [label="b"] ; A -> B ; """ clparser, cllexer = get_parser_lexer("DOT") parser = parse_code(code, clparser, cllexer) tree = parser.graph() st = get_tree_string(tree, parser) fLOG(st.replace("\\n", "\n")) assert len(st) > 0
def test_pig(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") code = """ A = LOAD 'filename.txt' USING PigStorage('\t'); STORE A INTO 'samefile.txt' ; """ try: clparser, cllexer = get_parser_lexer("Pig") except ImportError: warnings.warn("Grammar for Pig not ready yet.") return parser = parse_code(code, clparser, cllexer) tree = parser.parse() st = get_tree_string(tree, parser, None) fLOG(st.replace("\\n", "\n")) assert len(st) > 0
def test_csharp_parse(self): code = """ namespace hello { public static class world { public static double function(double x, double y) { return x+y ; } } public class world_nostatic { public virtual double function(double x, double y) { return x+y ; } } /// <summary> /// Documentation /// </summary> public class world_nostatic2: world_nostatic { public int J => myj; int myj; public world_nostatic2(int j) { myj = j; } /// <desc> /// DOCDOC /// </desc> public override double function(double x, double y) { return base.function(x, y); } } } """ clparser, cllexer = get_parser_lexer("C#") parser = parse_code(code, clparser, cllexer) tree = parser.compilation_unit() st = get_tree_string(tree, parser) self.assertNotEmpty(st) self.assertIn("/// <summary>", st)
def test_csharp_parse(self): code = """ namespace hello { public static class world { public static double function(double x, double y) { return x+y ; } } public class world_nostatic { public virtual double function(double x, double y) { return x+y ; } } /// <summary> /// Documentation /// </summary> public class world_nostatic2: world_nostatic { public int J => myj; int myj; public world_nostatic2(int j) { myj = j; } /// <desc> /// DOCDOC /// </desc> public override double function(double x, double y) { return base.function(x, y); } } } """ clparser, cllexer = get_parser_lexer("C#") parser = parse_code(code, clparser, cllexer) tree = parser.parse() st = get_tree_string(tree, parser) self.assertNotEmpty(st) self.assertIn("/// <summary>", st)