mirror of
https://github.com/JockeTF/fimfarchive.git
synced 2024-11-24 14:17:59 +01:00
Convert tqdm function to subclass
This commit is contained in:
parent
129a3440e6
commit
f28b10c63a
2 changed files with 32 additions and 11 deletions
|
@ -29,7 +29,7 @@ from importlib import import_module
|
|||
from importlib_resources import files
|
||||
from pathlib import Path
|
||||
from typing import (
|
||||
cast, Any, Callable, Dict, Iterable, Iterator,
|
||||
cast, Any, Callable, Dict, Iterator,
|
||||
Optional, Set, Tuple, Type, TypeVar, Union,
|
||||
)
|
||||
|
||||
|
@ -302,15 +302,18 @@ class ResourceLoader:
|
|||
return resource.read_text()
|
||||
|
||||
|
||||
def tqdm(iterable: Iterable[T], **kwargs) -> Iterable[T]:
|
||||
class tqdm(_tqdm):
|
||||
"""
|
||||
Adds an ASCII progress bar to the iterable.
|
||||
"""
|
||||
return _tqdm(
|
||||
iterable,
|
||||
ascii=True,
|
||||
leave=False,
|
||||
smoothing=0,
|
||||
ncols=72,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
defaults = {
|
||||
'ascii': True,
|
||||
'leave': False,
|
||||
'smoothing': 0.0,
|
||||
'ncols': 72,
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs = {**self.defaults, **kwargs}
|
||||
return super().__init__(*args, **kwargs)
|
||||
|
|
|
@ -33,7 +33,7 @@ from fimfarchive import utils
|
|||
from fimfarchive.flavors import DataFormat, MetaFormat, MetaPurity
|
||||
from fimfarchive.utils import (
|
||||
find_flavor, get_path, is_blacklisted,
|
||||
Empty, JayWalker, PersistedDict,
|
||||
Empty, JayWalker, PersistedDict, tqdm,
|
||||
)
|
||||
|
||||
|
||||
|
@ -366,3 +366,21 @@ class TestIsBlacklisted:
|
|||
story = story.merge(key=key, meta=meta)
|
||||
|
||||
assert result is is_blacklisted(story)
|
||||
|
||||
|
||||
class TestTqdm:
|
||||
"""
|
||||
tqdm tests.
|
||||
"""
|
||||
|
||||
def test_overridden_default(self):
|
||||
"""
|
||||
Tests defaults can be overridden.
|
||||
"""
|
||||
tqdm((), disable=True, smoothing=1.0)
|
||||
|
||||
def test_without_iterator(self):
|
||||
"""
|
||||
Tests iterator is not required.
|
||||
"""
|
||||
tqdm(disable=True, total=42)
|
||||
|
|
Loading…
Reference in a new issue