diff options
author | Andrew Scheller <github@loowis.durge.org> | 2016-07-04 14:20:45 +0100 |
---|---|---|
committer | Andrew Scheller <github@loowis.durge.org> | 2016-07-04 14:20:45 +0100 |
commit | 249342f38762b223b7846526e4637553987f4006 (patch) | |
tree | e5328859d99243e53e7c16301a267deaade2f213 | |
parent | 96bd56b60f6531ba369d152581af72ef28d62082 (diff) | |
download | pyfilesystem-git-249342f38762b223b7846526e4637553987f4006.tar.gz |
Fix test_with_statement to work on python3, and remove the python2.5
special-case code (because we no longer support python2.5)
-rw-r--r-- | fs/tests/__init__.py | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/fs/tests/__init__.py b/fs/tests/__init__.py index 69e4bba..ae83726 100644 --- a/fs/tests/__init__.py +++ b/fs/tests/__init__.py @@ -837,27 +837,18 @@ class FSTestCases(object): self.assertEquals(f.read(), b("\x00")*25 + b("EOF")) def test_with_statement(self): - # This is a little tricky since 'with' is actually new syntax. - # We use eval() to make this method safe for old python versions. - import sys - if sys.version_info[0] >= 2 and sys.version_info[1] >= 5: - # A successful 'with' statement - contents = "testing the with statement" - code = "from __future__ import with_statement\n" - code += "with self.fs.open('f.txt','wb-') as testfile:\n" - code += " testfile.write(contents)\n" - code += "self.assertEquals(self.fs.getcontents('f.txt', 'rb'),contents)" - code = compile(code, "<string>", 'exec') - eval(code) - # A 'with' statement raising an error - contents = "testing the with statement" - code = "from __future__ import with_statement\n" - code += "with self.fs.open('f.txt','wb-') as testfile:\n" - code += " testfile.write(contents)\n" - code += " raise ValueError\n" - code = compile(code, "<string>", 'exec') - self.assertRaises(ValueError, eval, code, globals(), locals()) - self.assertEquals(self.fs.getcontents('f.txt', 'rb'), contents) + contents = b"testing the with statement" + # A successful 'with' statement + with self.fs.open('f.txt','wb-') as testfile: + testfile.write(contents) + self.assertEquals(self.fs.getcontents('f.txt', 'rb'), contents) + # A 'with' statement raising an error + def with_error(): + with self.fs.open('g.txt','wb-') as testfile: + testfile.write(contents) + raise ValueError + self.assertRaises(ValueError, with_error) + self.assertEquals(self.fs.getcontents('g.txt', 'rb'), contents) def test_pickling(self): if self.fs.getmeta('pickle_contents', True): |