Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
grumpy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
grumpy
Commits
c6c46bd7
Commit
c6c46bd7
authored
Mar 29, 2017
by
Dylan Trotter
Committed by
Dylan Trotter
Apr 03, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up a few tests.
parent
887248bd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
26 deletions
+34
-26
compiler/imputil_test.py
compiler/imputil_test.py
+22
-19
compiler/stmt_test.py
compiler/stmt_test.py
+12
-7
No files found.
compiler/imputil_test.py
View file @
c6c46bd7
...
...
@@ -277,7 +277,7 @@ class MakeFutureFeaturesTest(unittest.TestCase):
class
ParseFutureFeaturesTest
(
unittest
.
TestCase
):
def
test
VisitFuture
(
self
):
def
test
FutureFeatures
(
self
):
print_function_features
=
imputil
.
FutureFeatures
()
print_function_features
.
print_function
=
True
testcases
=
[
...
...
@@ -302,21 +302,24 @@ class ParseFutureFeaturesTest(unittest.TestCase):
_
,
got
=
imputil
.
parse_future_features
(
mod
)
self
.
assertEqual
(
want
.
__dict__
,
got
.
__dict__
)
def
testVisitFutureLate
(
self
):
testcases
=
[
# future after normal imports
"""
\
import os
from __future__ import print_function
"""
,
# future after non-docstring expression
"""
asd = 123
from __future__ import print_function
"""
]
def
testFutureAfterAssignRaises
(
self
):
source
=
'foo = 123
\
n
from __future__ import print_function'
mod
=
pythonparser
.
parse
(
source
)
self
.
assertRaises
(
util
.
LateFutureError
,
imputil
.
parse_future_features
,
mod
)
for
source
in
testcases
:
mod
=
pythonparser
.
parse
(
textwrap
.
dedent
(
source
))
self
.
assertRaises
(
util
.
LateFutureError
,
def
testFutureAfterImportRaises
(
self
):
source
=
'import os
\
n
from __future__ import print_function'
mod
=
pythonparser
.
parse
(
source
)
self
.
assertRaises
(
util
.
LateFutureError
,
imputil
.
parse_future_features
,
mod
)
def
testUnimplementedFutureRaises
(
self
):
mod
=
pythonparser
.
parse
(
'from __future__ import division'
)
msg
=
'future feature division not yet implemented by grumpy'
self
.
assertRaisesRegexp
(
util
.
ParseError
,
msg
,
imputil
.
parse_future_features
,
mod
)
def
testUndefinedFutureRaises
(
self
):
mod
=
pythonparser
.
parse
(
'from __future__ import foo'
)
self
.
assertRaisesRegexp
(
util
.
ParseError
,
'future feature foo is not defined'
,
imputil
.
parse_future_features
,
mod
)
compiler/stmt_test.py
View file @
c6c46bd7
...
...
@@ -299,6 +299,11 @@ class StatementVisitorTest(unittest.TestCase):
import sys
print type(sys.modules)"""
)))
def
testImportFutureLateRaises
(
self
):
regexp
=
'from __future__ imports must occur at the beginning of the file'
self
.
assertRaisesRegexp
(
util
.
ImportError
,
regexp
,
_ParseAndVisit
,
'foo = bar
\
n
from __future__ import print_function'
)
def
testImportMember
(
self
):
self
.
assertEqual
((
0
,
"<type 'dict'>
\
n
"
),
_GrumpRun
(
textwrap
.
dedent
(
"""
\
from sys import modules
...
...
@@ -329,12 +334,6 @@ class StatementVisitorTest(unittest.TestCase):
from __go__.time import type_Duration as Duration
print Duration"""
)))
def
testPrintStatement
(
self
):
self
.
assertEqual
((
0
,
'abc 123
\
n
foo bar
\
n
'
),
_GrumpRun
(
textwrap
.
dedent
(
"""
\
print 'abc',
print '123'
print 'foo', 'bar'"""
)))
def
testImportWildcardMemberRaises
(
self
):
regexp
=
r'wildcard member import is not implemented: from foo import *'
self
.
assertRaisesRegexp
(
util
.
ImportError
,
regexp
,
_ParseAndVisit
,
...
...
@@ -344,7 +343,13 @@ class StatementVisitorTest(unittest.TestCase):
self
.
assertRaisesRegexp
(
util
.
ImportError
,
regexp
,
_ParseAndVisit
,
'from __go__.foo import *'
)
def
testFutureFeaturePrintFunction
(
self
):
def
testPrintStatement
(
self
):
self
.
assertEqual
((
0
,
'abc 123
\
n
foo bar
\
n
'
),
_GrumpRun
(
textwrap
.
dedent
(
"""
\
print 'abc',
print '123'
print 'foo', 'bar'"""
)))
def
testPrintFunction
(
self
):
want
=
"abc
\
n
123
\
n
abc 123
\
n
abcx123
\
n
abc 123 "
self
.
assertEqual
((
0
,
want
),
_GrumpRun
(
textwrap
.
dedent
(
"""
\
"module docstring is ok to proceed __future__"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment