~ubuntu-branches/debian/experimental/pyflakes/experimental

« back to all changes in this revision

Viewing changes to pyflakes/test/test_script.py

  • Committer: Bazaar Package Importer
  • Author(s): Tristan Seligmann, Tristan Seligmann, Sandro Tosi
  • Date: 2009-01-30 20:38:15 UTC
  • mfrom: (1.1.4 upstream) (4.1.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090130203815-v9fnac58fs1sqaes
Tags: 0.3.0-1
[ Tristan Seligmann ]
* New upstream release.

[ Sandro Tosi ]
* debian/copyright
  - added my contribution to packaging
  - updated upstream copyright years
* debian/README.source
  - removed paragraph about "./debian/rules get-orig-source"
* debian/control
  - updated short and long descriptions

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
        count = withStderrTo(err, lambda: checkPath('extremo'))
47
47
        self.assertEquals(err.getvalue(), 'extremo: no such file\n')
48
48
        self.assertEquals(count, 1)
 
49
 
 
50
 
 
51
    def test_multilineSyntaxError(self):
 
52
        """
 
53
        Source which includes a syntax error which results in the raised
 
54
        L{SyntaxError.text} containing multiple lines of source are reported
 
55
        with only the last line of that source.
 
56
        """
 
57
        source = """\
 
58
def foo():
 
59
    '''
 
60
 
 
61
def bar():
 
62
    pass
 
63
 
 
64
def baz():
 
65
    '''quux'''
 
66
"""
 
67
 
 
68
        # Sanity check - SyntaxError.text should be multiple lines, if it
 
69
        # isn't, something this test was unprepared for has happened.
 
70
        def evaluate(source):
 
71
            exec source
 
72
        exc = self.assertRaises(SyntaxError, evaluate, source)
 
73
        self.assertTrue(exc.text.count('\n') > 1)
 
74
 
 
75
        sourcePath = FilePath(self.mktemp())
 
76
        sourcePath.setContent(source)
 
77
        err = StringIO()
 
78
        count = withStderrTo(err, lambda: checkPath(sourcePath.path))
 
79
        self.assertEqual(count, 1)
 
80
 
 
81
        self.assertEqual(
 
82
            err.getvalue(),
 
83
            """\
 
84
%s:8: invalid syntax
 
85
    '''quux'''
 
86
           ^
 
87
""" % (sourcePath.path,))
 
88
 
 
89
 
 
90
    def test_eofSyntaxError(self):
 
91
        """
 
92
        The error reported for source files which end prematurely causing a
 
93
        syntax error reflects the cause for the syntax error.
 
94
        """
 
95
        source = "def foo("
 
96
        sourcePath = FilePath(self.mktemp())
 
97
        sourcePath.setContent(source)
 
98
        err = StringIO()
 
99
        count = withStderrTo(err, lambda: checkPath(sourcePath.path))
 
100
        self.assertEqual(count, 1)
 
101
        self.assertEqual(
 
102
            err.getvalue(),
 
103
            """\
 
104
%s:1: unexpected EOF while parsing
 
105
def foo(
 
106
         ^
 
107
""" % (sourcePath.path,))
 
108