-
Notifications
You must be signed in to change notification settings - Fork 467
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
Tests for core
and cli
modules
#149
Changes from all commits
fb8f90e
9b19fec
5622c18
2077753
4bdd0fb
1dde009
cacce40
a66031a
d275b93
09c88f7
eb8243b
bf4813f
06cb86a
5d470ed
ea1d018
3084794
534fba9
1be061c
3bc2dbe
07c8f2d
6a80726
c729f33
bc3a2ba
12a6222
6c09eee
8b2e49b
884515a
353f45c
7a2e28d
13d933d
8132fb3
9b74e58
d227163
118b586
4ffe771
f538878
33398db
e2f336a
d431e3e
e59b41f
2df978b
90ca98a
4057a93
363d6b1
4b79a34
bc17e5b
274da2b
d2f5e54
9d84226
184e624
7e32ae3
1aa4954
8e907ef
e2c44a8
1e72710
5df8a9d
3d70ec9
e18aee1
423d068
2e7a9c8
7393d7e
0a1c754
c3064b6
4b4dbcd
6112000
d68649a
e86cbc8
164b273
de1e18c
cf01120
51602c8
1c4915f
10f17aa
48b9d20
4c63ab8
415acff
eb94030
8ca413f
f850ab9
6d43400
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 |
---|---|---|
|
@@ -12,17 +12,26 @@ | |
# or implied. See the License for the specific language governing | ||
# permissions and limitations under the License. | ||
|
||
import os | ||
|
||
import click | ||
import pytest | ||
from click.testing import CliRunner | ||
from git.repo.base import Repo | ||
|
||
from zenml import __version__ as running_zenml_version | ||
from zenml.cli.example import info, list, pull | ||
from zenml.cli.example import EXAMPLES_GITHUB_REPO, info, list, pull | ||
from zenml.constants import APP_NAME | ||
from zenml.logger import get_logger | ||
|
||
# from hypothesis import given | ||
# from hypothesis.strategies import text | ||
|
||
|
||
logger = get_logger(__name__) | ||
|
||
ZERO_FIVE_RELEASE_EXAMPLES = ["airflow", "legacy", "quickstart"] | ||
NOT_ZERO_FIVE_RELEASE_EXAMPLES = ["not_airflow", "not_legacy", "not_quickstart"] | ||
BAD_VERSIONS = ["aaa", "999999", "111111"] | ||
|
||
|
||
|
@@ -95,3 +104,90 @@ def test_pull_of_bad_version_when_valid_version_already_exists( | |
runner.invoke(pull, ["-f", "-v", "0.5.1"]) | ||
result = runner.invoke(pull, ["-f", "-v", bad_version]) | ||
assert result.exit_code != 0 | ||
|
||
|
||
def test_pull_without_any_flags_should_exit_without_errors() -> None: | ||
"""Check pull command exits without errors""" | ||
runner = CliRunner() | ||
with runner.isolated_filesystem(): | ||
result1 = runner.invoke(pull) | ||
assert result1.exit_code == 0 | ||
|
||
|
||
@pytest.mark.parametrize("example", ZERO_FIVE_RELEASE_EXAMPLES) | ||
def test_info_echos_out_readme_content(example: str) -> None: | ||
"""Check that info subcommand displays readme content""" | ||
# TODO: [LOW] make test handle rich markdown output | ||
runner = CliRunner() | ||
with runner.isolated_filesystem(): | ||
# setup the test | ||
runner.invoke(pull, ["-f", "-v", "0.5.0"]) | ||
|
||
# get path variables | ||
repo_dir = click.get_app_dir(APP_NAME) | ||
examples_dir = os.path.join(repo_dir, EXAMPLES_GITHUB_REPO, "examples") | ||
readme_path = os.path.join(examples_dir, example, "README.md") | ||
|
||
result = runner.invoke(info, [example]) | ||
assert result.exit_code == 0 | ||
assert example in result.output | ||
schustmi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
with open(readme_path) as f: | ||
for line in f.read().splitlines(): | ||
assert line in result.output | ||
examples_dir = os.path.join(os.getcwd(), EXAMPLES_GITHUB_REPO) | ||
assert example in os.listdir(examples_dir) | ||
|
||
|
||
@pytest.mark.parametrize("bad_example", NOT_ZERO_FIVE_RELEASE_EXAMPLES) | ||
def test_info_fails_gracefully_when_bad_example_given( | ||
tmp_path: str, bad_example: str | ||
) -> None: | ||
"""Check info command fails gracefully when bad example given""" | ||
runner = CliRunner() | ||
with runner.isolated_filesystem(tmp_path): | ||
runner.invoke(pull, ["-f", "-v", "0.5.0"]) | ||
result = runner.invoke(info, [bad_example]) | ||
assert ( | ||
f"Example {bad_example} is not one of the available options." | ||
in result.output | ||
) | ||
assert bad_example not in os.listdir(tmp_path) | ||
|
||
|
||
@pytest.mark.parametrize("bad_example", NOT_ZERO_FIVE_RELEASE_EXAMPLES) | ||
def test_info_fails_gracefully_when_no_readme_present( | ||
tmp_path: str, bad_example: str | ||
) -> None: | ||
"""Check info command fails gracefully when bad example given""" | ||
# get path variables | ||
repo_dir = click.get_app_dir(APP_NAME) | ||
examples_dir = os.path.join(repo_dir, EXAMPLES_GITHUB_REPO, "examples") | ||
|
||
runner = CliRunner() | ||
with runner.isolated_filesystem(tmp_path): | ||
runner.invoke(pull, ["-f", "-v", "0.5.0"]) | ||
fake_example_path = os.path.join(examples_dir, bad_example) | ||
os.mkdir(fake_example_path) | ||
result = runner.invoke(info, [bad_example]) | ||
assert "No README.md file found" in result.output | ||
os.rmdir(fake_example_path) | ||
|
||
|
||
def test_user_has_latest_zero_five_version_but_wants_zero_five_one(): | ||
"""Test the scenario where the latest version available to the user is 0.5.0 | ||
but the user wants to download 0.5.1. In this case, it should redownload | ||
and try to checkout the desired version.""" | ||
runner = CliRunner() | ||
with runner.isolated_filesystem(): | ||
# save the repository currently on the local system | ||
current_saved_global_examples_path = os.path.join( | ||
click.get_app_dir(APP_NAME), EXAMPLES_GITHUB_REPO | ||
) | ||
current_saved_global_examples_repo = Repo( | ||
current_saved_global_examples_path | ||
) | ||
# reset the repo such that it has 0.5.0 as the latest version | ||
current_saved_global_examples_repo.git.reset("--hard", "0.5.0") | ||
runner.invoke(pull, ["-f", "-v", "0.5.1"]) | ||
result = runner.invoke(list) | ||
assert "airflow_local" in result.output | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this call raise an error somehow if the version does not exist? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @schustmi I didn't understand this. Do you mean that we should add another test to catch this condition (i.e. if the version doesn't exist) or that the currently-written test is doing something unexpected? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure actually how this should be handled, maybe a warning message that the requested version does not exists and that we fallback to the latest one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alex-zenml wdyt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added a warning message. |
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.
Nice!