-
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 63 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 |
---|---|---|
|
@@ -14,15 +14,25 @@ | |
|
||
import os | ||
|
||
import pytest | ||
from click import get_app_dir | ||
from click.testing import CliRunner | ||
|
||
from zenml.cli.config import opt_in, opt_out | ||
from zenml.cli.config import ( | ||
list_metadata_stores, | ||
opt_in, | ||
opt_out, | ||
register_metadata_store, | ||
set_logging_verbosity, | ||
) | ||
from zenml.config.constants import GLOBAL_CONFIG_NAME | ||
from zenml.config.global_config import GlobalConfig | ||
from zenml.constants import APP_NAME | ||
from zenml.constants import APP_NAME, ZENML_LOGGING_VERBOSITY | ||
from zenml.metadata.sqlite_metadata_wrapper import SQLiteMetadataStore | ||
from zenml.utils.yaml_utils import read_json | ||
|
||
NOT_LOGGING_LEVELS = ["abc", "my_cat_is_called_aria", "pipeline123"] | ||
|
||
|
||
def read_global_config(): | ||
"""Read the global config file""" | ||
|
@@ -61,3 +71,54 @@ def test_analytics_opt_out_amends_global_config(): | |
assert result.exit_code == 0 | ||
assert not read_global_config()["analytics_opt_in"] | ||
set_analytics_opt_in_status(pre_test_status) | ||
|
||
|
||
@pytest.mark.parametrize("not_a_level", NOT_LOGGING_LEVELS) | ||
def test_set_logging_verbosity_stops_when_not_real_level( | ||
not_a_level: str, | ||
) -> None: | ||
"""Check that set_logging_verbosity doesn't run when no real level""" | ||
# TODO: [Medium] replace the pytest params with hypothesis params | ||
pre_test_logging_status = ZENML_LOGGING_VERBOSITY | ||
runner = CliRunner() | ||
result = runner.invoke(set_logging_verbosity, [not_a_level]) | ||
os.environ["ZENML_LOGGING_VERBOSITY"] = pre_test_logging_status | ||
assert result.exit_code == 2 | ||
|
||
|
||
@pytest.mark.xfail() | ||
def test_metadata_register_actually_registers_new_metadata_store( | ||
tmp_path, | ||
) -> None: | ||
"""Test that the metadata register command actually registers a metadata store""" | ||
# TODO: [Medium] implement this test | ||
runner = CliRunner() | ||
test_metadata_dir = os.path.join(tmp_path, "metadata.db") | ||
|
||
result = runner.invoke( | ||
register_metadata_store, | ||
["test_store", SQLiteMetadataStore(uri=test_metadata_dir)], | ||
) | ||
assert result.exit_code == 0 | ||
|
||
|
||
def test_metadata_list_lists_default_local_metadata_store() -> None: | ||
"""Test that the metadata list command lists the default local metadata store""" | ||
# TODO: [HIGH] add a fixture that spins up a test env each time | ||
schustmi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
runner = CliRunner() | ||
result = runner.invoke(list_metadata_stores) | ||
assert result.exit_code == 0 | ||
assert "local_metadata_store" in result.output | ||
|
||
|
||
# test metadata register command actually registers a new metadata store | ||
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. Are these all TODO's? 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. Was leftover from an initial session thinking through the code. Removed now. |
||
# test metadata list actually lists newly created metadata stores | ||
# test metadata delete actually deletes newly created metadata stores | ||
# test artifact register command actually registers a new artifact store | ||
# test artifact list actually lists newly created artifact stores | ||
# test artifact delete actually deletes newly created artifact stores | ||
# test orchestrator register command actually registers a new orchestrator | ||
# test orchestrator list actually lists newly created orchestrators | ||
# test orchestrator delete actually deletes newly created orchestrators | ||
# test orchestrator up actually spins up our orchestrator | ||
# test orchestrator down actually shuts down our orchestrator |
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,60 @@ 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""" | ||
runner = CliRunner() | ||
with runner.isolated_filesystem(): | ||
runner.invoke(pull, ["-f", "-v", "0.5.0"]) | ||
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
|
||
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) | ||
|
||
|
||
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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (c) ZenML GmbH 2020. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at: | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
# or implied. See the License for the specific language governing | ||
# permissions and limitations under the License. | ||
|
||
|
||
def test_me() -> None: | ||
"""basic test""" | ||
assert True | ||
|
||
|
||
# test pipeline run with no arguments | ||
# test pipeline run with a file but no config YAML file (should fail) | ||
# test what is returned from a pipeline run | ||
# test failure of bad YAML file | ||
# test failure of bad pipeline python file |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright (c) ZenML GmbH 2021. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at: | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
# or implied. See the License for the specific language governing | ||
# permissions and limitations under the License. | ||
|
||
|
||
def test_me() -> None: | ||
"""basic test""" | ||
assert True | ||
|
||
|
||
# test registering a stack works | ||
# test listing a stack works | ||
# test deleting a stack works | ||
# test activating a stack works | ||
# test geting the active stack works | ||
# test that on initial installation we have an active stack to start with (maybe not here, though?) |
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.
This might be a bit weird because maybe an example is there but doesnt have a README and it would say the example is not present
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.
Fixed now.