From bf9ce73e3720bdbf1cc671f35f4f299511d59650 Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Sun, 24 Sep 2017 09:14:35 +0200 Subject: Close files during tests. --- tests/test_cli.py | 9 +++++---- tests/test_regressions.py | 12 ++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'tests') 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 diff --git a/tests/test_regressions.py b/tests/test_regressions.py index 89828f0..406328c 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -186,9 +186,9 @@ def test_format_accepts_encoding(load_file): def test_stream(get_stream): - stream = get_stream("stream.sql") - p = sqlparse.parse(stream)[0] - assert p.get_type() == 'INSERT' + with get_stream("stream.sql") as stream: + p = sqlparse.parse(stream)[0] + assert p.get_type() == 'INSERT' def test_issue90(): @@ -238,9 +238,9 @@ def test_null_with_as(): def test_issue190_open_file(filepath): path = filepath('stream.sql') - stream = open(path) - p = sqlparse.parse(stream)[0] - assert p.get_type() == 'INSERT' + with open(path) as stream: + p = sqlparse.parse(stream)[0] + assert p.get_type() == 'INSERT' def test_issue193_splitting_function(): -- cgit v1.2.1