def test_graph_graphviz(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.parse() st = get_tree_graph(tree, parser) dot = st.to_dot() # fLOG(dot) assert len(dot) > 0 if "travis" not in sys.executable: temp = get_temp_folder(__file__, "temp_dot_grammar") 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_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_graph_style(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") temp = get_temp_folder(__file__, "temp_dot") # still some issues with scipy and fortran compiler + graphviz # dependency from sklearn.datasets import load_iris from sklearn import tree clf = tree.DecisionTreeClassifier() iris = load_iris() clf = clf.fit(iris.data, iris.target) outfile = os.path.join(temp, "out_tree.dot") tree.export_graphviz(clf, out_file=outfile) img = os.path.join(temp, "out_tree.png") try: run_dot(outfile, img) except FileNotFoundError as e: p = os.environ.get("PATH", None) raise Exception("PATH={0}".format(p)) from e self.assertExists(img)