diff options
author | Kurt McKee <contactme@kurtmckee.org> | 2020-09-07 12:26:33 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-07 19:26:33 +0200 |
commit | 945ed5ef268e2f3c7bbea42dfae1f8f844096f61 (patch) | |
tree | 16030a76a7d5d371db2828a94dd85fa79e4127c4 | |
parent | 2b3ab6d6fe5c4064c3378315e9b49b3c6ef55b0e (diff) | |
download | pygments-git-945ed5ef268e2f3c7bbea42dfae1f8f844096f61.tar.gz |
Fix a Windows/PyPy3 test failure (#1533)
PyPy3 on Windows has a test failure in `test_cmdline:test_outfile()`
when trying to unlink the temporary output file. The root cause is that
`cmdline:inner_main()` does not explicitly close the file that it opens,
and PyPy3 isn't auto-closing the file when `inner_main()` returns.
This prevents the file from being unlinked, and the test case fails.
-rw-r--r-- | pygments/cmdline.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/pygments/cmdline.py b/pygments/cmdline.py index 80390fe6..457af34d 100644 --- a/pygments/cmdline.py +++ b/pygments/cmdline.py @@ -515,7 +515,11 @@ def main_inner(popts, args, usage): # ... and do it! if '-s' not in opts: # process whole input as per normal... - highlight(code, lexer, fmter, outfile) + try: + highlight(code, lexer, fmter, outfile) + finally: + if outfn: + outfile.close() return 0 else: # line by line processing of stdin (eg: for 'tail -f')... @@ -532,6 +536,9 @@ def main_inner(popts, args, usage): return 0 except KeyboardInterrupt: # pragma: no cover return 0 + finally: + if outfn: + outfile.close() def main(args=sys.argv): |