summaryrefslogtreecommitdiff
path: root/tests/test_lexers_other.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_lexers_other.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_lexers_other.py')
-rw-r--r--tests/test_lexers_other.py19
1 files changed, 8 insertions, 11 deletions
diff --git a/tests/test_lexers_other.py b/tests/test_lexers_other.py
index 5e1ee098..e3625a2b 100644
--- a/tests/test_lexers_other.py
+++ b/tests/test_lexers_other.py
@@ -26,17 +26,14 @@ class AnalyseTextTest(unittest.TestCase):
for pattern in lexer.filenames:
exampleFilesPattern = _exampleFilePath(pattern)
for exampleFilePath in glob.glob(exampleFilesPattern):
- exampleFile = open(exampleFilePath, 'rb')
- try:
- text = exampleFile.read().decode('utf-8')
- probability = lexer.analyse_text(text)
- self.assertTrue(probability > 0,
- '%s must recognize %r' % (
- lexer.name, exampleFilePath))
- guessedLexer = guess_lexer(text)
- self.assertEqual(guessedLexer.name, lexer.name)
- finally:
- exampleFile.close()
+ with open(exampleFilePath, 'rb') as fp:
+ text = fp.read().decode('utf-8')
+ probability = lexer.analyse_text(text)
+ self.assertTrue(probability > 0,
+ '%s must recognize %r' % (
+ lexer.name, exampleFilePath))
+ guessedLexer = guess_lexer(text)
+ self.assertEqual(guessedLexer.name, lexer.name)
def testCanRecognizeAndGuessExampleFiles(self):
self._testCanRecognizeAndGuessExampleFiles(RexxLexer)