-
Notifications
You must be signed in to change notification settings - Fork 5
feat: build examples dict for cli commands #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
54974ba
c9cf238
f9a14c3
71423d5
a1ee907
b16c90b
15c8111
db2ac9a
9fcef71
c70ca27
d32201a
fbbf88c
a458c5e
736b519
0bd26fc
4be38f6
280390c
99c4951
aa65d02
4aa15b0
cfb2273
fdf09b2
53ac9a2
ce1efa7
c39dfae
c2e8076
d1038b7
85bb747
0d08dbe
fcbb1a2
52aa4e7
e8c8ee5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ | |
|
|
||
|
|
||
| # Examples | ||
| def _get_examples_dir() -> Path: | ||
| def _get_examples_dir(root_path=None) -> Path: | ||
| """Return the absolute path to the installed examples directory. | ||
|
|
||
| Returns | ||
|
|
@@ -72,6 +72,43 @@ def map_pack_to_examples() -> dict[str, List[str]]: | |
| return examples_by_pack | ||
|
|
||
|
|
||
| def copy_examples( | ||
| examples: List[str], | ||
sbillinge marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| target_dir: Optional[Path] = None, | ||
| ) -> List[Path]: | ||
| """Copy one or more examples to a target directory. | ||
|
||
|
|
||
| Parameters | ||
| ---------- | ||
| examples : list of str | ||
| Example name(s): ['example1'], ['pack1'] | ||
| target_dir : Path, optional | ||
| Target directory where examples should be copied. | ||
| Defaults to current working directory if not specified. | ||
|
|
||
| Returns | ||
| ------- | ||
| list of Path | ||
|
||
| List of destination paths created. | ||
|
|
||
| Raises | ||
| ------ | ||
| ValueError | ||
|
||
| If example name is ambiguous (exists in multiple packs). | ||
| FileNotFoundError | ||
| If example does not exist. | ||
| FileExistsError | ||
| If destination exists and overwrite=False. | ||
| """ | ||
| return | ||
|
|
||
|
|
||
| def print_info(pack_examples_dict): | ||
| """Pretty print available and installed packs and examples to | ||
| console.""" | ||
| return | ||
|
|
||
|
|
||
| def copy_example(pack_example: str) -> Path: | ||
| """Copy an example into the current working directory. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # from diffpy.cmi import get_package_dir | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("root_path", [None, str(Path(__file__).parent)]) | ||
sbillinge marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| def test_get_package_dir(root_path): | ||
| """Test that get_package_dir returns a valid path context | ||
sbillinge marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| manager.""" | ||
| assert False | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import pytest | ||
|
|
||
| from diffpy.cmi.packsmanager import PacksManager | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "expected", | ||
| [ | ||
| { | ||
| # test with pack that has examples | ||
|
||
| "pack1": [ | ||
| "ex1", | ||
| "ex2", | ||
| "ex3", | ||
| ] | ||
| }, | ||
| { | ||
| # test pack with no examples | ||
| "no_examples": [] | ||
| }, | ||
| ], | ||
sbillinge marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
| def test_available_examples(temp_path, expected): | ||
| for pack, examples in expected.items(): | ||
|
||
| pack_dir = temp_path / pack | ||
| pack_dir.mkdir(parents=True, exist_ok=True) | ||
| for ex in examples: | ||
| ex_dir = pack_dir / ex | ||
| ex_dir.mkdir(parents=True, exist_ok=True) | ||
| pkmg = PacksManager(temp_path) | ||
| actual = pkmg.available_examples(temp_path) | ||
|
||
| assert actual == expected | ||
|
|
||
|
|
||
| def test_available_examples_bad(temp_path): | ||
| pkmg = PacksManager(temp_path) | ||
| bad_path = temp_path / "nonexistent" | ||
| with pytest.raises(FileNotFoundError): | ||
| pkmg.available_examples(bad_path) | ||
|
|
||
|
|
||
| def test_print_info(temp_path, capsys): | ||
| pkmg = PacksManager(temp_path) | ||
| pkmg.print_info() | ||
| captured = capsys.readouterr() | ||
| output = captured.out.strip() | ||
| assert "Available packs" in output or "Installed packs" in output | ||
Uh oh!
There was an error while loading. Please reload this page.