mirror of https://github.com/tqdm/tqdm.git
tests: lots of tidying
This commit is contained in:
parent
99fa82df08
commit
32dc63552b
|
@ -3,10 +3,8 @@ from sys import platform
|
|||
from time import time
|
||||
import asyncio
|
||||
|
||||
from pytest import mark
|
||||
|
||||
from tqdm.asyncio import tqdm_asyncio, tarange
|
||||
from .tests_tqdm import StringIO, closing
|
||||
from .tests_tqdm import StringIO, closing, mark
|
||||
|
||||
tqdm = partial(tqdm_asyncio, miniters=0, mininterval=0)
|
||||
trange = partial(tarange, miniters=0, mininterval=0)
|
||||
|
|
|
@ -4,8 +4,8 @@ import sys
|
|||
if sys.version_info[:2] > (3, 6):
|
||||
from .py37_asyncio import * # NOQA, pylint: disable=wildcard-import
|
||||
else:
|
||||
import pytest
|
||||
from .tests_tqdm import skip
|
||||
try:
|
||||
pytest.skip("async not supported", allow_module_level=True)
|
||||
skip("async not supported", allow_module_level=True)
|
||||
except TypeError:
|
||||
pass
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
"""
|
||||
Tests for `tqdm.contrib.concurrent`.
|
||||
"""
|
||||
from pytest import mark, warns
|
||||
from pytest import warns
|
||||
|
||||
from tqdm.contrib.concurrent import thread_map, process_map
|
||||
from .tests_tqdm import importorskip, skip, StringIO, closing, TqdmWarning
|
||||
from .tests_tqdm import StringIO, closing, TqdmWarning, importorskip, mark, skip
|
||||
|
||||
|
||||
def incr(x):
|
||||
|
@ -40,7 +40,7 @@ def test_process_map():
|
|||
(['x' * 100, ('x',) * 1001], True)])
|
||||
def test_chunksize_warning(iterables, should_warn):
|
||||
"""Test contrib.concurrent.process_map chunksize warnings"""
|
||||
patch = importorskip("unittest.mock").patch
|
||||
patch = importorskip('unittest.mock').patch
|
||||
with patch('tqdm.contrib.concurrent._executor_map'):
|
||||
if should_warn:
|
||||
warns(TqdmWarning, process_map, incr, *iterables)
|
||||
|
|
|
@ -28,7 +28,7 @@ def test_enumerate():
|
|||
|
||||
def test_enumerate_numpy():
|
||||
"""Test contrib.tenumerate(numpy.ndarray)"""
|
||||
np = importorskip("numpy")
|
||||
np = importorskip('numpy')
|
||||
with closing(StringIO()) as our_file:
|
||||
a = np.random.random((42, 7))
|
||||
assert list(tenumerate(a, file=our_file)) == list(np.ndenumerate(a))
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
from __future__ import division
|
||||
|
||||
from pytest import mark
|
||||
|
||||
from tqdm import tqdm
|
||||
from .tests_tqdm import importorskip, StringIO, closing
|
||||
from .tests_tqdm import StringIO, closing, importorskip, mark
|
||||
pytestmark = mark.slow
|
||||
|
||||
|
||||
@mark.filterwarnings("ignore:.*:DeprecationWarning")
|
||||
def test_keras():
|
||||
"""Test tqdm.keras.TqdmCallback"""
|
||||
TqdmCallback = importorskip("tqdm.keras").TqdmCallback
|
||||
np = importorskip("numpy")
|
||||
TqdmCallback = importorskip('tqdm.keras').TqdmCallback
|
||||
np = importorskip('numpy')
|
||||
try:
|
||||
import keras as K
|
||||
except ImportError:
|
||||
K = importorskip("tensorflow.keras")
|
||||
K = importorskip('tensorflow.keras')
|
||||
|
||||
# 1D autoencoder
|
||||
dtype = np.float32
|
||||
|
|
|
@ -5,11 +5,9 @@ import logging
|
|||
import sys
|
||||
import subprocess
|
||||
|
||||
from pytest import mark, raises
|
||||
|
||||
from tqdm.cli import main, TqdmKeyError, TqdmTypeError
|
||||
from tqdm.utils import IS_WIN
|
||||
from .tests_tqdm import _range, closing, BytesIO
|
||||
from .tests_tqdm import _range, BytesIO, closing, mark, raises
|
||||
|
||||
|
||||
def restore_sys(func):
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
from tqdm import tqdm
|
||||
from .tests_tqdm import importorskip, skip, StringIO, closing
|
||||
|
||||
from pytest import mark
|
||||
from .tests_tqdm import StringIO, closing, importorskip, mark, skip
|
||||
pytestmark = mark.slow
|
||||
|
||||
random = importorskip("numpy.random")
|
||||
random = importorskip('numpy.random')
|
||||
rand = random.rand
|
||||
randint = random.randint
|
||||
pd = importorskip("pandas")
|
||||
pd = importorskip('pandas')
|
||||
|
||||
|
||||
def test_pandas_setup():
|
||||
|
|
|
@ -10,10 +10,8 @@ except ImportError:
|
|||
from time import clock
|
||||
process_time = clock
|
||||
|
||||
from pytest import mark
|
||||
|
||||
from tqdm import tqdm, trange
|
||||
from .tests_tqdm import importorskip, skip, _range, patch_lock
|
||||
from .tests_tqdm import _range, importorskip, mark, patch_lock, skip
|
||||
pytestmark = mark.slow
|
||||
|
||||
|
||||
|
|
|
@ -209,7 +209,7 @@ def test_imap():
|
|||
@patch_lock(thread=True)
|
||||
def test_threadpool():
|
||||
"""Test concurrent.futures.ThreadPoolExecutor"""
|
||||
ThreadPoolExecutor = importorskip("concurrent.futures").ThreadPoolExecutor
|
||||
ThreadPoolExecutor = importorskip('concurrent.futures').ThreadPoolExecutor
|
||||
|
||||
with ThreadPoolExecutor(8) as pool:
|
||||
try:
|
||||
|
|
|
@ -8,8 +8,7 @@ import re
|
|||
import os
|
||||
from functools import wraps
|
||||
from contextlib import contextmanager
|
||||
from pytest import raises as assert_raises
|
||||
from pytest import importorskip, skip
|
||||
from pytest import importorskip, mark, raises, skip
|
||||
from warnings import catch_warnings, simplefilter
|
||||
|
||||
from tqdm import tqdm
|
||||
|
@ -798,15 +797,15 @@ def test_smoothed_dynamic_min_iters_with_min_interval():
|
|||
assert '14%' in out and '14%' in out2
|
||||
|
||||
|
||||
@mark.slow
|
||||
def test_rlock_creation():
|
||||
"""Test that importing tqdm does not create multiprocessing objects."""
|
||||
import multiprocessing as mp
|
||||
if sys.version_info < (3, 3):
|
||||
skip("unittest.mock is a 3.3+ feature")
|
||||
importorskip('multiprocessing')
|
||||
from multiprocessing import get_context
|
||||
|
||||
# Use 'spawn' instead of 'fork' so that the process does not inherit any
|
||||
# globals that have been constructed by running other tests
|
||||
ctx = mp.get_context('spawn')
|
||||
ctx = get_context('spawn')
|
||||
with ctx.Pool(1) as pool:
|
||||
# The pool will propagate the error if the target method fails
|
||||
pool.apply(_rlock_creation_target)
|
||||
|
@ -814,8 +813,8 @@ def test_rlock_creation():
|
|||
|
||||
def _rlock_creation_target():
|
||||
"""Check that the RLock has not been constructed."""
|
||||
from unittest.mock import patch
|
||||
import multiprocessing as mp
|
||||
patch = importorskip('unittest.mock').patch
|
||||
|
||||
# Patch the RLock class/method but use the original implementation
|
||||
with patch('multiprocessing.RLock', wraps=mp.RLock) as rlock_mock:
|
||||
|
@ -1087,10 +1086,9 @@ def test_smoothing():
|
|||
assert a2 <= c2 <= b2
|
||||
|
||||
|
||||
@mark.skipif(nt_and_no_colorama, reason="Windows without colorama")
|
||||
def test_deprecated_nested():
|
||||
"""Test nested progress bars"""
|
||||
if nt_and_no_colorama:
|
||||
skip("Windows without colorama")
|
||||
# TODO: test degradation on windows without colorama?
|
||||
|
||||
# Artificially test nested loop printing
|
||||
|
@ -1188,11 +1186,9 @@ def test_reset():
|
|||
assert '| 10/12' in our_file.getvalue()
|
||||
|
||||
|
||||
@mark.skipif(nt_and_no_colorama, reason="Windows without colorama")
|
||||
def test_position():
|
||||
"""Test positioned progress bars"""
|
||||
if nt_and_no_colorama:
|
||||
skip("Windows without colorama")
|
||||
|
||||
# Artificially test nested loop printing
|
||||
# Without leave
|
||||
our_file = StringIO()
|
||||
|
@ -1553,7 +1549,7 @@ def test_write():
|
|||
|
||||
def test_len():
|
||||
"""Test advance len (numpy array shape)"""
|
||||
np = importorskip("numpy")
|
||||
np = importorskip('numpy')
|
||||
with closing(StringIO()) as f:
|
||||
with tqdm(np.zeros((3, 4)), file=f) as t:
|
||||
assert len(t) == 3
|
||||
|
@ -1585,8 +1581,8 @@ def test_deprecation_exception():
|
|||
def test_TqdmDeprecationWarning_nofpwrite():
|
||||
raise TqdmDeprecationWarning('Test!', fp_write=None)
|
||||
|
||||
assert_raises(TqdmDeprecationWarning, test_TqdmDeprecationWarning)
|
||||
assert_raises(Exception, test_TqdmDeprecationWarning_nofpwrite)
|
||||
raises(TqdmDeprecationWarning, test_TqdmDeprecationWarning)
|
||||
raises(Exception, test_TqdmDeprecationWarning_nofpwrite)
|
||||
|
||||
|
||||
def test_postfix():
|
||||
|
|
Loading…
Reference in New Issue