start testing get_files
This commit is contained in:
parent
19e90eb647
commit
5c6eec62ee
2 changed files with 46 additions and 1 deletions
|
@ -107,7 +107,7 @@ from .kython.klogging import setup_logger, LazyLogger
|
|||
|
||||
Paths = Union[Sequence[PathIsh], PathIsh]
|
||||
|
||||
def get_files(pp: Paths, glob: str, sort: bool=True) -> Tuple[Path, ...]:
|
||||
def get_files(pp: Paths, glob: str='*', sort: bool=True) -> Tuple[Path, ...]:
|
||||
"""
|
||||
Helper function to avoid boilerplate.
|
||||
|
||||
|
|
45
tests/common.py
Normal file
45
tests/common.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
from pathlib import Path
|
||||
from my.common import get_files
|
||||
|
||||
import pytest # type: ignore
|
||||
|
||||
|
||||
def test_single_file():
|
||||
'''
|
||||
Regular file path is just returned as is.
|
||||
'''
|
||||
|
||||
"Exception if it doesn't exist"
|
||||
with pytest.raises(Exception):
|
||||
get_files('/tmp/hpi_test/file.ext')
|
||||
|
||||
|
||||
create('/tmp/hpi_test/file.ext')
|
||||
|
||||
'''
|
||||
Couple of things:
|
||||
1. Return type is a tuple, it's friendlier for hashing/caching
|
||||
2. It always return pathlib.Path instead of plain strings
|
||||
'''
|
||||
assert get_files('/tmp/hpi_test/file.ext') == (
|
||||
Path('/tmp/hpi_test/file.ext'),
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
test_path = Path('/tmp/hpi_test')
|
||||
def setup():
|
||||
teardown()
|
||||
test_path.mkdir()
|
||||
|
||||
|
||||
def teardown():
|
||||
import shutil
|
||||
if test_path.is_dir():
|
||||
shutil.rmtree(test_path)
|
||||
|
||||
|
||||
from my.common import PathIsh
|
||||
def create(f: PathIsh) -> None:
|
||||
Path(f).touch()
|
Loading…
Add table
Reference in a new issue