summaryrefslogtreecommitdiff
path: root/tests/test_basic_api.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-10-07 14:10:28 +0200
committerGeorg Brandl <georg@python.org>2014-10-07 14:10:28 +0200
commit9a51e6a6df8a56aebede133687e91e519a186122 (patch)
treeffebef0e0f0b63c2749e2858fdc50972a336fc2b /tests/test_basic_api.py
parent9cbc7803dd8e7826393721fe4acbd702843e131c (diff)
downloadpygments-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_basic_api.py')
-rw-r--r--tests/test_basic_api.py15
1 files changed, 3 insertions, 12 deletions
diff --git a/tests/test_basic_api.py b/tests/test_basic_api.py
index eff49383..0beb0171 100644
--- a/tests/test_basic_api.py
+++ b/tests/test_basic_api.py
@@ -264,11 +264,8 @@ class FiltersTest(unittest.TestCase):
for x in filters.FILTERS:
lx = lexers.PythonLexer()
lx.add_filter(x, **filter_args.get(x, {}))
- fp = open(TESTFILE, 'rb')
- try:
+ with open(TESTFILE, 'rb') as fp:
text = fp.read().decode('utf-8')
- finally:
- fp.close()
tokens = list(lx.get_tokens(text))
roundtext = ''.join([t[1] for t in tokens])
if x not in ('whitespace', 'keywordcase'):
@@ -284,22 +281,16 @@ class FiltersTest(unittest.TestCase):
def test_whitespace(self):
lx = lexers.PythonLexer()
lx.add_filter('whitespace', spaces='%')
- fp = open(TESTFILE, 'rb')
- try:
+ with open(TESTFILE, 'rb') as fp:
text = fp.read().decode('utf-8')
- finally:
- fp.close()
lxtext = ''.join([t[1] for t in list(lx.get_tokens(text))])
self.assertFalse(' ' in lxtext)
def test_keywordcase(self):
lx = lexers.PythonLexer()
lx.add_filter('keywordcase', case='capitalize')
- fp = open(TESTFILE, 'rb')
- try:
+ with open(TESTFILE, 'rb') as fp:
text = fp.read().decode('utf-8')
- finally:
- fp.close()
lxtext = ''.join([t[1] for t in list(lx.get_tokens(text))])
self.assertTrue('Def' in lxtext and 'Class' in lxtext)