8000 Improve robustness of test_futurize.py and test_pasteurize.py · thecodingchicken/python-future@ed1c6a6 · GitHub
[go: up one dir, main page]

Skip to content

Commit ed1c6a6

Browse files
committed
Improve robustness of test_futurize.py and test_pasteurize.py
Previously two tests within these scripts tried to access the filename using __file__, assuming this to be the name of the .py script. This assumption was incorrect sometimes on Py2 when the __file__ string pointed to a ``.pyc`` file. Removed two xfail decorators
1 parent 4726c54 commit ed1c6a6

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

docs/whatsnew.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ What's New
88
What's new in version 0.14.4 (2015-06-03)
99
=========================================
1010

11-
This release adds two new minor features and fixes some small bugs.
11+
This is primarily a bug-fix release. It adds two new minor features and fixes several small bugs.
1212

1313
Minor features:
1414

@@ -21,6 +21,7 @@ Bug fixes:
2121
implementations where appropriate (issue #146 - thanks to Matt Bogosian)
2222
- Fixed newrange slicing for some slice/range combos (issue #132, thanks to Brad Walker)
2323
- Small doc fixes
24+
- Improve robustness of test suite with .pyc files on Py2
2425

2526

2627
What's new in version 0.14.3 (2014-12-15)

tests/test_future/test_futurize.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@
1717

1818

1919
class TestLibFuturize(unittest.TestCase):
20-
@skip26 # mysterious sporadic UnicodeDecodeError raised by lib2to3 ...
20+
21+
def setUp(self):
22+
# For tests that need a text file:
23+
_, self.textfilename = tempfile.mkstemp(text=True)
24+
super(TestLibFuturize, self).setUp()
25+
26+
def tearDown(self):
27+
os.unlink(self.textfilename)
28+
2129
def test_correct_exit_status(self):
2230
"""
2331
Issue #119: futurize and pasteurize were not exiting with the correct
@@ -26,8 +34,7 @@ def test_correct_exit_status(self):
2634
translates into 1!
2735
"""
2836
from libfuturize.main import main
29-
# Try futurizing this test script:
30-
retcode = main([__file__])
37+
retcode = main([self.textfilename])
3138
self.assertTrue(isinstance(retcode, int)) # i.e. Py2 builtin int
3239

3340
def test_is_shebang_comment(self):
@@ -82,9 +89,6 @@ class TestFuturizeSimple(CodeHandler):
8289
tests for whether they can be passed to ``futurize`` and immediately
8390
run under both Python 2 again and Python 3.
8491
"""
85-
def setUp(self):
86-
self.tempdir = tempfile.mkdtemp() + os.path.sep
87-
super(TestFuturizeSimple, self).setUp()
8892

8993
def test_encoding_comments_kept_at_top(self):
9094
"""
@@ -449,7 +453,6 @@ def test_source_coding_utf8(self):
449453
# -*- coding: utf-8 -*-
450454
icons = [u"◐", u"◓", u"◑", u"◒"]
451455
"""
452-
self.unchanged(code)
453456

454457
def test_exception_syntax(self):
455458
"""
@@ -488,7 +491,7 @@ def test_file(self):
488491
file() as a synonym for open() is obsolete and invalid on Python 3.
489492
"""
490493
before = '''
491-
f = file(__file__)
494+
f = file(self.textfilename)
492495
data = f.read()
493496
f.close()
494497
'''
@@ -851,7 +854,7 @@ def test_absolute_import_changes(self):
851854
852855
Issue #16 (with porting bokeh/bbmodel.py)
853856
"""
854-
with open(tempdir + 'specialmodels.py', 'w') as f:
857+
with open(self.tempdir + 'specialmodels.py', 'w') as f:
855858
f.write('pass')
856859

857860
before = """

tests/test_future/test_pasteurize.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ class TestPasteurize(CodeHandler):
2121
on both Py3 and Py2.
2222
"""
2323

24+
def setUp(self):
25+
# For tests that need a text file:
26+
_, self.textfilename = tempfile.mkstemp(text=True)
27+
super(TestPasteurize, self).setUp()
28+
29+
def tearDown(self):
30+
os.unlink(self.textfilename)
31+
2432
@skip26 # Python 2.6's lib2to3 causes the "from builtins import
2533
# range" line to be stuck at the bottom of the module!
2634
def test_range_slice(self):
@@ -130,7 +138,6 @@ def test_urllib_refactor2(self):
130138
filename = urllib_parse.urlparse(url)[2].split('/')[-1]
131139
"""
132140

133-
@skip26 # mysterious sporadic UnicodeDecodeError raised by lib2to3 ...
134141
def test_correct_exit_status(self):
135142
"""
136143
Issue #119: futurize and pasteurize were not exiting with the correct
@@ -140,7 +147,7 @@ def test_correct_exit_status(self):
140147
"""
141148
from libpasteurize.main import main
142149
# Try pasteurizing this test script:
143-
retcode = main([__file__])
150+
retcode = main([self.textfilename])
144151
self.assertTrue(isinstance(retcode, int)) # i.e. Py2 builtin int
145152

146153

0 commit comments

Comments
 (0)
0