コード例 #1
0
ファイル: testparsesource.py プロジェクト: aswins/vimrc
 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")
コード例 #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")
コード例 #3
0
ファイル: testparsesource.py プロジェクト: DevilsTrill/vim
 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")
コード例 #4
0
ファイル: testparsesource.py プロジェクト: aswins/vimrc
 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")
コード例 #5
0
ファイル: testparsesource.py プロジェクト: aswins/vimrc
 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")
コード例 #6
0
ファイル: testparsesource.py プロジェクト: aswins/vimrc
 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")
コード例 #7
0
ファイル: testissues.py プロジェクト: aswins/vimrc
 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")
コード例 #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()))
コード例 #9
0
ファイル: testparsesource.py プロジェクト: leejunghwa/home
 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()))
コード例 #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")
コード例 #11
0
ファイル: testissues.py プロジェクト: leejunghwa/home
 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")
コード例 #12
0
ファイル: testissues.py プロジェクト: DevilsTrill/vim
    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")
コード例 #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")
コード例 #14
0
ファイル: testparsesource.py プロジェクト: dstanek/pycscope
 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)
コード例 #15
0
ファイル: testparsesource.py プロジェクト: DevilsTrill/vim
 def testMissingNewLine(self,):
     # Verify we can handle dumping
     parseSource(" ", self.buf, 0)
     assert len(self.buf) == 0
コード例 #16
0
ファイル: testparsesource.py プロジェクト: aswins/vimrc
 def testEmptyLine(self,):
     src = "\n"
     pycscope.parseSource(src, self.buf)
     output = "".join(self.buf)
     self.assertEqual(output, "\n")
コード例 #17
0
ファイル: testparsesource.py プロジェクト: aswins/vimrc
 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")
コード例 #18
0
 def testMissingNewLine(self, ):
     # Verify we can handle dumping
     parseSource(" ", self.buf, 0)
     assert len(self.buf) == 0
コード例 #19
0
ファイル: testparsesource.py プロジェクト: aswins/vimrc
 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")
コード例 #20
0
ファイル: testparsesource.py プロジェクト: aswins/vimrc
 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")