Пример #1
0
    def test_charp_graph_networkx(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)

        if "travis" in sys.executable:
            # no networkx
            return

        st.draw()

        import matplotlib.pyplot as plt
        if __name__ == "__main__":
            plt.show()

        plt.close('all')
Пример #2
0
    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_workflow(self):
        fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__")

        code = """
        set varconst = 10 ;
        data_a = flowdata.DataCloud ;
        modb = flowmodule.RandomFilter(
                    n= 100
                    ) ;
        connect data_a to modb.input ;

        if ( positive_number(modb.average, varconst)) {
            modc = flowmodule.Classify(model="LinearRegression") ;
            connect ( modb.data , modc.train_data ) ;
        }
        """

        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")
            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)
Пример #4
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.parse()
        st = get_tree_string(tree, parser)
        fLOG(st.replace("\\n", "\n"))
        assert len(st) > 0
Пример #5
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' ;
     """
     
     clparser,cllexer = get_parser_lexer("Pig")
     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
Пример #6
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
Пример #7
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
Пример #8
0
    def test_extra(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        code = """
        example of the language
        """
        return
        from src.pyensae.languages.LanguageLexer import LanguageLexer
        from src.pyensae.languages.LanguageParser import LanguageParser

        parser = parse_code(code, LanguageParser, LanguageLexer)
        tree = parser.parse()
        st = get_tree_string(tree, parser)
        fLOG(st.replace("\\n", "\n"))
        assert len(st) > 0
Пример #9
0
    def test_python3(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        # the grammar does not fully compile
        return

        code = """
        def addition(x, y):
            return x + y
        """

        clparser, cllexer = get_parser_lexer("Python3")
        parser = parse_code(code, clparser, cllexer)
        tree = parser.parse()
        st = get_tree_string(tree, parser)
        fLOG(st.replace("\\n", "\n"))
        assert len(st) > 0
Пример #10
0
 def test_error(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)
     try:
         tree = parser.parse()
     except SyntaxError as e :
         fLOG(e)
         return
         
     raise Exception("should not be here")
Пример #11
0
    def test_DOT(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        # the grammar does not fully compile
        return

        code = """
        digraph {
            A [label="a"] ;
            B [label="b"] ;
            A -> B ;
        """

        clparser, cllexer = get_parser_lexer("DOT")
        parser = parse_code(code, clparser, cllexer)
        tree = parser.parse()
        st = get_tree_string(tree, parser)
        fLOG(st.replace("\\n", "\n"))
        assert len(st) > 0