generated from entelecheia/hyperfast-python-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(copier): add tests for Copier class methods
- Loading branch information
1 parent
62ba225
commit 7ae60c3
Showing
3 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ | |
import colorama | ||
from pydantic import StrictBool | ||
|
||
|
||
colorama.init() | ||
|
||
IntSeq = Sequence[int] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import os | ||
import shutil | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from hyfi.utils.copier import Copier | ||
|
||
|
||
def test_files_are_copied(tmp_path): | ||
# source path is under src/hyfi/conf | ||
src_path = Path("src/hyfi/conf") | ||
assert src_path.exists() | ||
dst_path = tmp_path / "output" | ||
|
||
with Copier(src_path=src_path, dst_path=dst_path, verbose=False) as worker: | ||
worker.run_copy() | ||
|
||
for root, _, files in os.walk(src_path): | ||
for filename in files: | ||
if filename.endswith(".yaml"): | ||
src_file = Path(root, filename) | ||
dst_file = dst_path / src_file.relative_to(src_path) | ||
assert dst_file.exists() | ||
|
||
|
||
def test_cleanup_on_error(tmp_path): | ||
src_path = Path("src/hyfi/conf") | ||
assert src_path.exists() | ||
dst_path = tmp_path / "output" | ||
|
||
with pytest.raises(Exception): | ||
with Copier(src_path=src_path, dst_path=dst_path, verbose=False) as worker: | ||
worker.run_copy() | ||
raise Exception("Simulated error") | ||
|
||
assert not dst_path.exists() | ||
|
||
|
||
def test_no_cleanup_on_error_if_dst_existed(tmp_path): | ||
src_path = Path("src/hyfi/conf") | ||
assert src_path.exists() | ||
dst_path = tmp_path / "output" | ||
dst_path.mkdir(parents=True, exist_ok=True) | ||
|
||
with pytest.raises(Exception): | ||
with Copier(src_path=src_path, dst_path=dst_path, verbose=False) as worker: | ||
worker.run_copy() | ||
raise Exception("Simulated error") | ||
|
||
assert dst_path.exists() | ||
shutil.rmtree(dst_path) | ||
|
||
|
||
if __name__ == "__main__": | ||
pytest.main(["-v", "test_copier.py"]) |