diff options
author | Micka?l Schoentgen <contact@tiger-222.fr> | 2019-01-07 18:20:59 +0100 |
---|---|---|
committer | Micka?l Schoentgen <contact@tiger-222.fr> | 2019-01-07 18:20:59 +0100 |
commit | 810e049f65b44e06dbfd7c8800750a6230f93b39 (patch) | |
tree | 0532e3686d3260167c974bef44a4f7da69d44aa4 /tests | |
parent | 867fbbd26114b70d04c5885e1447af1d8acb08df (diff) | |
download | pygments-810e049f65b44e06dbfd7c8800750a6230f93b39.tar.gz |
Fix ResourceWarning: unclosed file
Also uniformize usage of the 'with' contact manager to prevent resource leaks.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_html_formatter.py | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/tests/test_html_formatter.py b/tests/test_html_formatter.py index 10450c56..670a5be9 100644 --- a/tests/test_html_formatter.py +++ b/tests/test_html_formatter.py @@ -132,9 +132,8 @@ class HtmlFormatterTest(unittest.TestCase): outencoding='utf-8') handle, pathname = tempfile.mkstemp('.html') - tfile = os.fdopen(handle, 'w+b') - fmt.format(tokensource, tfile) - tfile.close() + with os.fdopen(handle, 'w+b') as tfile: + fmt.format(tokensource, tfile) catname = os.path.join(TESTDIR, 'dtds', 'HTML4.soc') try: import subprocess @@ -173,9 +172,8 @@ class HtmlFormatterTest(unittest.TestCase): cssstyles=u'div:before { content: \'bäz\' }', encoding='utf-8') handle, pathname = tempfile.mkstemp('.html') - tfile = os.fdopen(handle, 'w+b') - fmt.format(tokensource, tfile) - tfile.close() + with os.fdopen(handle, 'w+b') as tfile: + fmt.format(tokensource, tfile) def test_ctags(self): try: |