From 40d59c2ec48d3885d441acc008ae1fcbb1c55cb2 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sun, 3 Jan 2021 22:33:43 +0000 Subject: [PATCH] tests: fix py38, py39 --- tests/tests_main.py | 26 +++++++++++++++----------- tests/tests_synchronisation.py | 1 + 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/tests/tests_main.py b/tests/tests_main.py index 990348d4..f7d33e14 100644 --- a/tests/tests_main.py +++ b/tests/tests_main.py @@ -6,16 +6,13 @@ from tempfile import mkdtemp import sys import subprocess +from pytest import mark + from tqdm.cli import main, TqdmKeyError, TqdmTypeError from tqdm.utils import IS_WIN from .tests_tqdm import skip, _range, closing, UnicodeIO, StringIO, BytesIO -def _sh(*cmd, **kwargs): - return subprocess.Popen(cmd, stdout=subprocess.PIPE, - **kwargs).communicate()[0].decode('utf-8') - - class Null(object): def __call__(self, *_, **__): return self @@ -29,15 +26,22 @@ NULL = Null() def test_pipes(): """Test command line pipes""" - ls_out = _sh('ls').replace('\r\n', '\n') - ls = subprocess.Popen('ls', stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - res = _sh(sys.executable, '-c', 'from tqdm.cli import main; main()', - stdin=ls.stdout, stderr=subprocess.STDOUT) - ls.wait() + ls_out = subprocess.check_output(['ls']) + ls = subprocess.Popen(['ls'], stdout=subprocess.PIPE) + res = subprocess.Popen( + [sys.executable, '-c', 'from tqdm.cli import main; main()'], + stdin=ls.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out, err = res.communicate()[:2] + assert ls.poll() == 0 # actual test: + assert ls_out.replace(b"\r\n", b"\n") == out.replace(b"\r\n", b"\n") + assert b"it/s" in err - assert ls_out in res.replace('\r\n', '\n') + +if sys.version_info[:2] >= (3, 8): + test_pipes = mark.filterwarnings("ignore:unclosed file:ResourceWarning")( + test_pipes) # WARNING: this should be the last test as it messes with sys.stdin, argv diff --git a/tests/tests_synchronisation.py b/tests/tests_synchronisation.py index d5f7bab0..2bf5ada9 100644 --- a/tests/tests_synchronisation.py +++ b/tests/tests_synchronisation.py @@ -200,6 +200,7 @@ def test_imap(): pool = Pool() res = list(tqdm(pool.imap(incr, range(100)), disable=True)) + pool.close() assert res[-1] == 100