-
Couldn't load subscription status.
- Fork 5
test: copy_examples test
#65
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
Open
cadenmyers13
wants to merge
14
commits into
diffpy:main
Choose a base branch
from
cadenmyers13:copy-func-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+376
−93
Open
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
17e3747
rm api from cli.py
cadenmyers13 82f7394
add copy_examples api to packsmanager
cadenmyers13 d973c83
add tests for copy_examples
cadenmyers13 375606c
add additional dirs to temp structure
cadenmyers13 711c24e
rm old tests
cadenmyers13 987c3e3
add news
cadenmyers13 9e65a27
glob only files and not dirs
cadenmyers13 5354831
fix target dir location to be under cwd and change name for new test …
cadenmyers13 47d87fb
Add additional test case, fix how copy location is tested
cadenmyers13 0a490b9
copy_examples function
cadenmyers13 6e2695d
rm error message function
cadenmyers13 e96988f
add test for forced overwrite of copied files
cadenmyers13 abfba68
Add 'force' param to copy_examples
cadenmyers13 d4cddf5
fix copy_tree to handle warnings and errors properly
cadenmyers13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,23 @@ | ||
| **Added:** | ||
|
|
||
| * Add test for ``copy_examples``. | ||
|
|
||
| **Changed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Deprecated:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Removed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Fixed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Security:** | ||
|
|
||
| * <news item> |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,65 +0,0 @@ | ||
| import os | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from diffpy.cmi import cli | ||
|
|
||
|
|
||
| def test_map_pack_to_examples_structure(): | ||
| """Test that map_pack_to_examples returns the right shape of | ||
| data.""" | ||
| actual = cli.map_pack_to_examples() | ||
| assert isinstance(actual, dict) | ||
| for pack, exdirs in actual.items(): | ||
| assert isinstance(pack, str) | ||
| assert isinstance(exdirs, list) | ||
| for ex in exdirs: | ||
| assert isinstance(ex, str) | ||
| # Check for known packs | ||
| assert "core" in actual.keys() | ||
| assert "pdf" in actual.keys() | ||
| # Check for known examples | ||
| assert ["linefit"] in actual.values() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "input_valid_str", | ||
| [ | ||
| "core/linefit", | ||
| "pdf/ch03NiModelling", | ||
| ], | ||
| ) | ||
| def test_copy_example_success(tmp_path, input_valid_str): | ||
| """Given a valid example format (<pack>/<ex>), test that its copied | ||
| to the temp dir.""" | ||
| os.chdir(tmp_path) | ||
| actual = cli.copy_example(input_valid_str) | ||
| expected = tmp_path / Path(input_valid_str).name | ||
| assert expected.exists() and expected.is_dir() | ||
| assert actual == expected | ||
|
|
||
|
|
||
| def test_copy_example_fnferror(): | ||
| """Test that FileNotFoundError is raised when the example does not | ||
| exist.""" | ||
| with pytest.raises(FileNotFoundError): | ||
| cli.copy_example("pack/example1") | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "input_bad_str", | ||
| [ | ||
| "", # empty string | ||
| "/", # missing pack and example | ||
| "corelinefit", # missing slash | ||
| "linefit", # missing pack and slash | ||
| "core/", # missing example | ||
| "/linefit", # missing pack | ||
| "core/linefit/extra", # too many slashes | ||
| ], | ||
| ) | ||
| def test_copy_example_valueerror(input_bad_str): | ||
| """Test that ValueError is raised when the format is invalid.""" | ||
| with pytest.raises(ValueError): | ||
| cli.copy_example(input_bad_str) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added new
forceinput param