summaryrefslogtreecommitdiff
path: root/tests/test_cli.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_cli.py')
-rw-r--r--tests/test_cli.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/tests/test_cli.py b/tests/test_cli.py
index c1a5a75..18c6fcb 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -127,10 +127,11 @@ def test_encoding_stdin_gbk(filepath, load_file, capfd):
path = filepath('encoding_gbk.sql')
expected = load_file('encoding_gbk.sql', 'gbk')
old_stdin = sys.stdin
- sys.stdin = open(path, 'r')
- sys.stdout.encoding = 'gbk'
- sqlparse.cli.main(['-', '--encoding', 'gbk'])
- sys.stdin = old_stdin
+ with open(path, 'r') as stream:
+ sys.stdin = stream
+ sys.stdout.encoding = 'gbk'
+ sqlparse.cli.main(['-', '--encoding', 'gbk'])
+ sys.stdin = old_stdin
out, _ = capfd.readouterr()
assert out == expected