Commit c6c46bd7 authored by Dylan Trotter's avatar Dylan Trotter Committed by Dylan Trotter

Clean up a few tests.

parent 887248bd
...@@ -277,7 +277,7 @@ class MakeFutureFeaturesTest(unittest.TestCase): ...@@ -277,7 +277,7 @@ class MakeFutureFeaturesTest(unittest.TestCase):
class ParseFutureFeaturesTest(unittest.TestCase): class ParseFutureFeaturesTest(unittest.TestCase):
def testVisitFuture(self): def testFutureFeatures(self):
print_function_features = imputil.FutureFeatures() print_function_features = imputil.FutureFeatures()
print_function_features.print_function = True print_function_features.print_function = True
testcases = [ testcases = [
...@@ -302,21 +302,24 @@ class ParseFutureFeaturesTest(unittest.TestCase): ...@@ -302,21 +302,24 @@ class ParseFutureFeaturesTest(unittest.TestCase):
_, got = imputil.parse_future_features(mod) _, got = imputil.parse_future_features(mod)
self.assertEqual(want.__dict__, got.__dict__) self.assertEqual(want.__dict__, got.__dict__)
def testVisitFutureLate(self): def testFutureAfterAssignRaises(self):
testcases = [ source = 'foo = 123\nfrom __future__ import print_function'
# future after normal imports mod = pythonparser.parse(source)
"""\ self.assertRaises(util.LateFutureError, imputil.parse_future_features, mod)
import os
from __future__ import print_function
""",
# future after non-docstring expression
"""
asd = 123
from __future__ import print_function
"""
]
for source in testcases: def testFutureAfterImportRaises(self):
mod = pythonparser.parse(textwrap.dedent(source)) source = 'import os\nfrom __future__ import print_function'
self.assertRaises(util.LateFutureError, 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) imputil.parse_future_features, mod)
...@@ -299,6 +299,11 @@ class StatementVisitorTest(unittest.TestCase): ...@@ -299,6 +299,11 @@ class StatementVisitorTest(unittest.TestCase):
import sys import sys
print type(sys.modules)"""))) 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\nfrom __future__ import print_function')
def testImportMember(self): def testImportMember(self):
self.assertEqual((0, "<type 'dict'>\n"), _GrumpRun(textwrap.dedent("""\ self.assertEqual((0, "<type 'dict'>\n"), _GrumpRun(textwrap.dedent("""\
from sys import modules from sys import modules
...@@ -329,12 +334,6 @@ class StatementVisitorTest(unittest.TestCase): ...@@ -329,12 +334,6 @@ class StatementVisitorTest(unittest.TestCase):
from __go__.time import type_Duration as Duration from __go__.time import type_Duration as Duration
print Duration"""))) print Duration""")))
def testPrintStatement(self):
self.assertEqual((0, 'abc 123\nfoo bar\n'), _GrumpRun(textwrap.dedent("""\
print 'abc',
print '123'
print 'foo', 'bar'""")))
def testImportWildcardMemberRaises(self): def testImportWildcardMemberRaises(self):
regexp = r'wildcard member import is not implemented: from foo import *' regexp = r'wildcard member import is not implemented: from foo import *'
self.assertRaisesRegexp(util.ImportError, regexp, _ParseAndVisit, self.assertRaisesRegexp(util.ImportError, regexp, _ParseAndVisit,
...@@ -344,7 +343,13 @@ class StatementVisitorTest(unittest.TestCase): ...@@ -344,7 +343,13 @@ class StatementVisitorTest(unittest.TestCase):
self.assertRaisesRegexp(util.ImportError, regexp, _ParseAndVisit, self.assertRaisesRegexp(util.ImportError, regexp, _ParseAndVisit,
'from __go__.foo import *') 'from __go__.foo import *')
def testFutureFeaturePrintFunction(self): def testPrintStatement(self):
self.assertEqual((0, 'abc 123\nfoo bar\n'), _GrumpRun(textwrap.dedent("""\
print 'abc',
print '123'
print 'foo', 'bar'""")))
def testPrintFunction(self):
want = "abc\n123\nabc 123\nabcx123\nabc 123 " want = "abc\n123\nabc 123\nabcx123\nabc 123 "
self.assertEqual((0, want), _GrumpRun(textwrap.dedent("""\ self.assertEqual((0, want), _GrumpRun(textwrap.dedent("""\
"module docstring is ok to proceed __future__" "module docstring is ok to proceed __future__"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment