diff options
author | Georg Brandl <georg@python.org> | 2014-10-07 14:10:28 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-10-07 14:10:28 +0200 |
commit | 9a51e6a6df8a56aebede133687e91e519a186122 (patch) | |
tree | ffebef0e0f0b63c2749e2858fdc50972a336fc2b /tests/test_examplefiles.py | |
parent | 9cbc7803dd8e7826393721fe4acbd702843e131c (diff) | |
download | pygments-9a51e6a6df8a56aebede133687e91e519a186122.tar.gz |
Closes #980: fix DeprecationWarnings (mostly due to files closed by __del__) on Py3.
Also fix a bunch of other uses of open() to use the with statement.
Diffstat (limited to 'tests/test_examplefiles.py')
-rw-r--r-- | tests/test_examplefiles.py | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/tests/test_examplefiles.py b/tests/test_examplefiles.py index 12f9d62f..ac5b4244 100644 --- a/tests/test_examplefiles.py +++ b/tests/test_examplefiles.py @@ -41,7 +41,8 @@ def test_example_files(): continue print(absfn) - code = open(absfn, 'rb').read() + with open(absfn, 'rb') as f: + code = f.read() try: code = code.decode('utf-8') except UnicodeError: @@ -78,11 +79,8 @@ def test_example_files(): def check_lexer(lx, fn): absfn = os.path.join(TESTDIR, 'examplefiles', fn) - fp = open(absfn, 'rb') - try: + with open(absfn, 'rb') as fp: text = fp.read() - finally: - fp.close() text = text.replace(b'\r\n', b'\n') text = text.strip(b'\n') + b'\n' try: @@ -114,18 +112,12 @@ def check_lexer(lx, fn): # no previous output -- store it outfn = os.path.join(TESTDIR, 'examplefiles', 'output', fn) if not os.path.isfile(outfn): - fp = open(outfn, 'wb') - try: + with open(outfn, 'wb') as fp: pickle.dump(tokens, fp) - finally: - fp.close() return # otherwise load it and compare - fp = open(outfn, 'rb') - try: + with open(outfn, 'rb') as fp: stored_tokens = pickle.load(fp) - finally: - fp.close() if stored_tokens != tokens: f1 = pprint.pformat(stored_tokens) f2 = pprint.pformat(tokens) |