Exemple #1
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
    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_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')
Exemple #4
0
    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_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)
Exemple #6
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
Exemple #7
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
Exemple #8
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
Exemple #9
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_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
Exemple #12
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
Exemple #13
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
Exemple #14
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
Exemple #15
0
    def test_pig(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")

        # does not work yet
        return

        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
Exemple #16
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
Exemple #17
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
Exemple #18
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
Exemple #19
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
Exemple #20
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")
Exemple #21
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:
            parser.parse()
        except SyntaxError as e:
            fLOG(e)
            return

        raise Exception("should not be here")
Exemple #22
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
    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)