Ejemplo n.º 1
0
 def testTupleAssignment(self,):
     src = "a,b = 4, 2\n"
     pycscope.parseSource(src, self.buf)
     output = "".join(self.buf)
     self.assertEqual(output, "\n\n1 \n"
                              "a\n, \n"
                              "b\n= 4 , 2 \n")
Ejemplo n.º 2
0
 def testSyntaxErrors(self, ):
     try:
         parseSource("a a (foo)", self.buf, 0)
     except SyntaxError as e:
         assert e.lineno == 1
     else:
         self.fail("Expected a syntax error")
Ejemplo n.º 3
0
 def testSyntaxErrors(self,):
     try:
         parseSource("a a (foo)", self.buf, 0)
     except SyntaxError as e:
         assert e.lineno == 1
     else:
         self.fail("Expected a syntax error")
Ejemplo n.º 4
0
 def testMultiImport(self,):
     src = "import sys, os, time\n"
     pycscope.parseSource(src, self.buf)
     output = "".join(self.buf)
     self.assertEqual(output, "\n\n1 import \n"
                              "\t~<sys\n, \n"
                              "\t~<os\n, \n"
                              "\t~<time\n\n")
Ejemplo n.º 5
0
 def testClass(self,):
     src = "class Foo:\n\tpass\n"
     pycscope.parseSource(src, self.buf)
     output = "".join(self.buf)
     self.assertEqual(output, "\n\n1 class \n"
                              "\tcFoo\n"
                              ": \n\n"
                              "2 pass \n")
Ejemplo n.º 6
0
 def testFuncDef(self,):
     """Also tests FUNC_END."""
     src = "def main():\n\tpass\n"
     pycscope.parseSource(src, self.buf)
     output = "".join(self.buf)
     self.assertEqual(output, "\n\n1 def \n"
                              "\t$main\n( ) : \n\n"
                              "2 pass \n\n"
                              "2 \n\t}\n\n")
Ejemplo n.º 7
0
 def test0019(self,):
     """Make sure new lines are observed 
     when NEWLINE token doesn't exist.
     """
     src = "(a,\nb) = 4, 2\n"
     pycscope.parseSource(src, self.buf)
     output = "".join(self.buf)
     self.assertEqual(output, "\n\n1 ( \n"
                              "a\n, \n\n"
                              "2 \n"
                              "b\n) = 4 , 2 \n")
Ejemplo n.º 8
0
 def verify(self, src, exp, dump=False):
     ''' Run the verification of a source value against an expected output
         value. The values are list of strings, each string representing an
         individual line. An empty list is interpretted as an empty
         file. And empty string is interpretted as an empty line.
     '''
     # We create one long string for both source and expected values so
     # that the caller can enumerate each line without adding new lines,
     # making it easier to see what is being written.
     srcStr = "\n".join(src)
     if src:
         # Add the trailing new line only if there was something in the
         # "file".
         srcStr += "\n"
     expStr = "\n".join(exp)
     if exp:
         expStr += "\n"
     try:
         l = parseSource(srcStr, self.buf, 0, dump)
     except AssertionError as ae:
         self.fail(
             "Internal AssertionError Encountered: %s\n"
             "Concrete Syntax Tree:\n"
             "%s\n" %
             (ae, dumpCst(parser.suite(srcStr), StringIO()).getvalue()))
     self.assertEqual(l, len(self.buf))
     output = "".join(self.buf)
     self.assertEqual(
         output, expStr, "Output not quite what was expected:\n"
         "    out: %r\n"
         "    exp: %r\n"
         "Concrete Syntax Tree:\n"
         "%s\n" % (output, expStr, dumpCst(parser.suite(srcStr),
                                           StringIO()).getvalue()))
Ejemplo n.º 9
0
 def verify(self, src, exp, dump=False):
     ''' Run the verification of a source value against an expected output
         value. The values are list of strings, each string representing an
         individual line. An empty list is interpretted as an empty
         file. And empty string is interpretted as an empty line.
     '''
     # We create one long string for both source and expected values so
     # that the caller can enumerate each line without adding new lines,
     # making it easier to see what is being written.
     srcStr = "\n".join(src)
     if src:
         # Add the trailing new line only if there was something in the
         # "file".
         srcStr += "\n"
     expStr = "\n".join(exp)
     if exp:
         expStr += "\n"
     try:
         l = parseSource(srcStr, self.buf, 0, dump)
     except AssertionError as ae:
         self.fail("Internal AssertionError Encountered: %s\n"
                   "Concrete Syntax Tree:\n"
                   "%s\n"
                   % (ae, dumpCst(parser.suite(srcStr),StringIO()).getvalue()))
     self.assertEqual(l, len(self.buf))
     output = "".join(self.buf)
     self.assertEqual(output, expStr,
                      "Output not quite what was expected:\n"
                      "    out: %r\n"
                      "    exp: %r\n"
                      "Concrete Syntax Tree:\n"
                      "%s\n"
                      % (output, expStr, dumpCst(parser.suite(srcStr),StringIO()).getvalue()))
Ejemplo n.º 10
0
    def testIssue0003(self):
        """ Verify we don't have conflicting marks.
        """
        src = """
class MyClass(object):

    @property
    def get_bar(self):
        return 'foo'

    def my_method(self):
        from datetime import datetime
"""
        l = pycscope.parseSource(src, self.buf, 0)
        self.assertEqual(l, len(self.buf))
        output = "".join(self.buf)
        self.assertEqual(
            output, "2 class \n"
            "\tcMyClass\n"
            " ( \n"
            "object\n"
            " ) :\n"
            "\n"
            "4 @ \n"
            "property\n"
            "\n"
            "5 def \n"
            "\t$get_bar\n"
            " ( \n"
            "self\n"
            " ) :\n"
            "\n"
            "6 return 'foo' \n"
            "\t}\n"
            "\n"
            "8 def \n"
            "\t$my_method\n"
            " ( \n"
            "self\n"
            " ) :\n"
            "\n"
            "9 from \n"
            "\t~datetime\n"
            " import \n"
            "datetime\n"
            " \n"
            "\t}\n"
            "\n")
Ejemplo n.º 11
0
 def test0019(self,):
     """ Make sure new lines are observed 
         when NEWLINE token doesn't exist.
     """
     src = "(a,\nb,) = 4, 2\n"
     l = pycscope.parseSource(src, self.buf, 0)
     self.assertEqual(l, len(self.buf))
     output = "".join(self.buf)
     self.assertEqual(output, "1 ( \n"
                              "\t=a\n"
                              " ,\n"
                              "\n"
                              "2 \n"
                              "\t=b\n"
                              " , ) = 4 , 2\n"
                              "\n")
Ejemplo n.º 12
0
    def testIssue0003(self):
        """ Verify we don't have conflicting marks.
        """
        src = """
class MyClass(object):

    @property
    def get_bar(self):
        return 'foo'

    def my_method(self):
        from datetime import datetime
"""
        l = pycscope.parseSource(src, self.buf, 0)
        self.assertEqual(l, len(self.buf))
        output = "".join(self.buf)
        self.assertEqual(output, "2 class \n"
                                 "\tcMyClass\n"
                                 " ( \n"
                                 "object\n"
                                 " ) :\n"
                                 "\n"
                                 "4 @ \n"
                                 "property\n"
                                 "\n"
                                 "5 def \n"
                                 "\t$get_bar\n"
                                 " ( \n"
                                 "self\n"
                                 " ) :\n"
                                 "\n"
                                 "6 return 'foo' \n"
                                 "\t}\n"
                                 "\n"
                                 "8 def \n"
                                 "\t$my_method\n"
                                 " ( \n"
                                 "self\n"
                                 " ) :\n"
                                 "\n"
                                 "9 from \n"
                                 "\t~datetime\n"
                                 " import \n"
                                 "datetime\n"
                                 " \n"
                                 "\t}\n"
                                 "\n")
Ejemplo n.º 13
0
 def test0019(self, ):
     """ Make sure new lines are observed
         when NEWLINE token doesn't exist.
     """
     src = "(a,\nb,) = 4, 2\n"
     l = pycscope.parseSource(src, self.buf, 0)
     self.assertEqual(l, len(self.buf))
     output = "".join(self.buf)
     self.assertEqual(
         output, "1 ( \n"
         "\t=a\n"
         " ,\n"
         "\n"
         "2 \n"
         "\t=b\n"
         " , ) = 4 , 2\n"
         "\n")
Ejemplo n.º 14
0
 def verify(self, src, exp):
     ''' Run the verification of a source value against an expected output
         value. The values are list of strings, each string representing an
         individual line. An empty list is interpretted as an empty
         file. And empty string is interpretted as an empty line.
     '''
     # We create one long string for both source and expected values so
     # that the caller can enumerate each line with adding new lines,
     # making it easier to see what is being written.
     srcStr = "\n".join(src)
     if src:
         # Add the trailing new line only if there was something in the
         # "file".
         srcStr += "\n"
     expStr = "\n".join(exp)
     if exp:
         expStr += "\n"
     l = parseSource(srcStr, self.buf, 0)
     self.assertEqual(l, len(self.buf))
     output = "".join(self.buf)
     #print "\nVerifying: \n\tfrom: %r\n%r\n\tmatches\n%r" % (srcStr, output, expStr)
     self.assertEqual(output, expStr)
Ejemplo n.º 15
0
 def testMissingNewLine(self,):
     # Verify we can handle dumping
     parseSource(" ", self.buf, 0)
     assert len(self.buf) == 0
Ejemplo n.º 16
0
 def testEmptyLine(self,):
     src = "\n"
     pycscope.parseSource(src, self.buf)
     output = "".join(self.buf)
     self.assertEqual(output, "\n")
Ejemplo n.º 17
0
 def testSimpleAssignment(self,):
     src = "a = 4\n"
     pycscope.parseSource(src, self.buf)
     output = "".join(self.buf)
     self.assertEqual(output, "\n\n1 \na\n= 4 \n")
Ejemplo n.º 18
0
 def testMissingNewLine(self, ):
     # Verify we can handle dumping
     parseSource(" ", self.buf, 0)
     assert len(self.buf) == 0
Ejemplo n.º 19
0
 def testSingleImport(self,):
     src = "import sys\n"
     pycscope.parseSource(src, self.buf)
     output = "".join(self.buf)
     self.assertEqual(output, "\n\n1 import \n"
                              "\t~<sys\n\n")
Ejemplo n.º 20
0
 def testFuncCall(self,):
     src = "main()\n"
     pycscope.parseSource(src, self.buf)
     output = "".join(self.buf)
     self.assertEqual(output, "\n\n1 \n"
                              "\t`main\n( ) \n")