Skip to content

Commit

Permalink
[Tests] Fixing root dir test files not being run (mlrun#780)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hedingber authored Mar 8, 2021
1 parent 6e957a5 commit 282169c
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 109 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ test: clean ## Run mlrun tests
--capture=no \
--disable-warnings \
--ignore=tests/integration \
--ignore=tests/test_notebooks.py \
--ignore=tests/rundb/test_httpdb.py \
-rf \
tests
Expand All @@ -422,6 +423,7 @@ test-integration: clean ## Run mlrun integration tests
--disable-warnings \
-rf \
tests/integration \
tests/test_notebooks.py \
tests/rundb/test_httpdb.py

.PHONY: test-migrations-dockerized
Expand Down
2 changes: 1 addition & 1 deletion mlrun/artifacts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def get_store_url(self, with_tag=True, project=None):
uri_project = project or self.project
uri = "/".join([uri_project, self.db_key])
if with_tag:
uri += "#" + self.tree
uri += ":" + self.tree
return get_store_uri(StorePrefix.Artifact, uri)

def base_dict(self):
Expand Down
23 changes: 8 additions & 15 deletions mlrun/datastore/store_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import mlrun
from mlrun.config import config
from mlrun.utils.helpers import parse_versioned_object_uri
from mlrun.utils.helpers import parse_versioned_object_uri, parse_artifact_uri
from .targets import get_online_target
from .v3io import parse_v3io_path
from ..utils import DB_SCHEMA, StorePrefix
Expand Down Expand Up @@ -139,30 +139,23 @@ def get_store_resource(uri, db=None, secrets=None, project=None):
return db.get_feature_vector(name, project, tag, uid)

elif StorePrefix.is_artifact(kind):
project, name, tag, uid = parse_versioned_object_uri(
project, key, iteration, tag, uid = parse_artifact_uri(
uri, project or config.default_project
)
iteration = None
if "/" in name:
loc = uri.find("/")
name = uri[:loc]
try:
iteration = int(uri[loc + 1 :])
except ValueError:
raise ValueError(
f"illegal store path {uri}, iteration must be integer value"
)

resource = db.read_artifact(
name, project=project, tag=tag or uid, iter=iteration
key, project=project, tag=tag or uid, iter=iteration
)
if resource.get("kind", "") == "link":
# todo: support other link types (not just iter, move this to the db/api layer
resource = db.read_artifact(
name, tag=tag, iter=resource.get("link_iteration", 0), project=project,
key, tag=tag, iter=resource.get("link_iteration", 0), project=project,
)
if resource:
return mlrun.artifacts.dict_to_artifact(resource)
# import here to avoid circular imports
from mlrun.artifacts import dict_to_artifact

return dict_to_artifact(resource)

else:
stores = mlrun.store_manager.set(secrets, db=db)
Expand Down
25 changes: 25 additions & 0 deletions mlrun/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,31 @@ def parse_versioned_object_uri(uri, default_project=""):
return project, uri, tag, hash_key


def parse_artifact_uri(uri, default_project=""):
uri_pattern = r"^((?P<project>.*)/)?(?P<key>.*?)(\#(?P<iteration>.*?))?(:(?P<tag>.*?))?(@(?P<uid>.*))?$"
match = re.match(uri_pattern, uri)
if not match:
raise ValueError(
"Uri not in supported format [<project>/]<key>[#<iteration>][:<tag>][@<uid>]"
)
group_dict = match.groupdict()
iteration = group_dict["iteration"]
if iteration is not None:
try:
iteration = int(iteration)
except ValueError:
raise ValueError(
f"illegal store path {uri}, iteration must be integer value"
)
return (
group_dict["project"] or default_project,
group_dict["key"],
iteration,
group_dict["tag"],
group_dict["uid"],
)


def generate_object_uri(project, name, tag=None, hash_key=None):
uri = f"{project}/{name}"

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ test = pytest

[tool:pytest]
addopts = -v -rf --disable-warnings
python_files = tests/*/test_*.py
python_files = tests/*/test_*.py tests/test_*.py
6 changes: 5 additions & 1 deletion tests/Dockerfile.test-nb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
# limitations under the License.

FROM python:3.6-slim
ENV PIP_NO_CACHE_DIR=1
RUN apt-get update && apt-get install -y g++ make git-core
RUN python -m pip install --upgrade --no-cache pip
RUN python -m pip install --upgrade pip~=20.2.0
WORKDIR /mlrun

COPY ./requirements.txt ./
Expand All @@ -28,3 +29,6 @@ RUN pip install \
COPY . .
ENV PYTHONPATH=/mlrun
RUN python -m pip install .[complete]
{args}
{pip}
RUN jupyter nbconvert --execute {notebook} --to html
Empty file removed tests/clients/__init__.py
Empty file.
19 changes: 9 additions & 10 deletions tests/test_datastores.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,41 +102,40 @@ def test_parse_url_preserve_case():

def test_get_store_artifact_url_parsing():
db = Mock()
store_manager = mlrun.datastore.StoreManager(db=db)
cases = [
{
"url": "store:///artifact_key",
"project": "default",
"key": "artifact_key",
"tag": "",
"tag": None,
"iter": None,
},
{
"url": "store://project_name/artifact_key",
"project": "project_name",
"key": "artifact_key",
"tag": "",
"tag": None,
"iter": None,
},
{
"url": "store://Project_Name/Artifact_Key#ABC",
"url": "store://Project_Name/Artifact_Key@ABC",
"project": "Project_Name",
"key": "Artifact_Key",
"tag": "ABC",
"iter": None,
},
{
"url": "store://project_name/artifact_key#a5dc8e34a46240bb9a07cd9deb3609c7",
"url": "store://project_name/artifact_key@a5dc8e34a46240bb9a07cd9deb3609c7",
"project": "project_name",
"key": "artifact_key",
"tag": "a5dc8e34a46240bb9a07cd9deb3609c7",
"iter": None,
},
{
"url": "store://project_name/artifact_key/1",
"url": "store://project_name/artifact_key#1",
"project": "project_name",
"key": "artifact_key",
"tag": "",
"tag": None,
"iter": 1,
},
{
Expand All @@ -147,14 +146,14 @@ def test_get_store_artifact_url_parsing():
"iter": None,
},
{
"url": "store:///ArtifacT_key/1:some_Tag",
"url": "store:///ArtifacT_key#1:some_Tag",
"project": "default",
"key": "ArtifacT_key",
"tag": "some_Tag",
"iter": 1,
},
{
"url": "store:///ArtifacT_key/1#Some_Tag",
"url": "store:///ArtifacT_key#1@Some_Tag",
"project": "default",
"key": "ArtifacT_key",
"tag": "Some_Tag",
Expand Down Expand Up @@ -183,7 +182,7 @@ def mock_read_artifact(key, tag=None, iter=None, project=""):
return {}

db.read_artifact = mock_read_artifact
store_manager.get_store_artifact(url)
mlrun.datastore.store_resources.get_store_resource(url, db)


@pytest.mark.usefixtures("patch_file_forbidden")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ def test_example(db, fname):
"run",
path,
]
out = run(cmd, env=env)
out = run(cmd, env=env, cwd=examples_path)
assert out.returncode == 0, "bad run"
2 changes: 1 addition & 1 deletion tests/test_kfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _assert_iteration_output_dir_files(output_dir):
contents = results_file.read()
assert contents == results_body
assert os.path.exists(output_dir + "/chart.html")
assert os.path.exists(output_dir + "/mydf.csv")
assert os.path.exists(output_dir + "/mydf.parquet")


def _assert_artifacts_dir(artifacts_dir, expected_accuracy, expected_loss):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_log_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def my_func(context):
"y": [25, 94, 0.1, 57, datetime.datetime(2018, 1, 1)],
}
df = pd.DataFrame(raw_data, columns=["first_name", "last_name", "x", "y"])
context.log_dataset("df1", df=df)
context.log_dataset("df1", df=df, format="csv")

date_rng = pd.date_range("2018-01-01", periods=4, freq="H")
df = pd.DataFrame(date_rng, columns=["date"])
Expand Down
3 changes: 1 addition & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
from tests.conftest import (
tests_root_directory,
examples_path,
root_path,
)


def exec_main(op, args):
cmd = [executable, "-m", "mlrun", op]
if args:
cmd += args
out = run(cmd, stdout=PIPE, stderr=PIPE, cwd=root_path)
out = run(cmd, stdout=PIPE, stderr=PIPE, cwd=examples_path)
if out.returncode != 0:
print(out.stderr.decode("utf-8"), file=stderr)
raise Exception(out.stderr.decode("utf-8"))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ def test_notebook(notebook):
+ ["."]
)
out = run(cmd, cwd=root)
assert out.returncode == 0, "cannot build"
assert out.returncode == 0, f"Failed building {out.stdout} {out.stderr}"
74 changes: 0 additions & 74 deletions tests/test_remote.py

This file was deleted.

4 changes: 3 additions & 1 deletion tests/test_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def test_requirement_specifiers_inconsistencies():
ignored_inconsistencies_map = {
# It's ==1.4.1 only in models-gpu because of tensorflow 2.2.0, TF version expected to be changed there soon so
# ignoring for now
"scipy": ["~=1.0", "==1.4.1", "~=1.0"]
"scipy": ["~=1.0", "==1.4.1", "~=1.0"],
# It's ok we have 2 different versions cause they are for different python versions
"pandas": ["~=1.2; python_version >= '3.7'", "~=1.0; python_version < '3.7'"],
}

for (
Expand Down
5 changes: 5 additions & 0 deletions tests/test_run_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,18 @@ def test_run_local_with_uid_does_not_exist(monkeypatch):
def mock_getpwuid_raise(*args, **kwargs):
raise KeyError("getpwuid(): uid not found: 400")

old_v3io_username = environ.pop("V3IO_USERNAME", None)
environ["V3IO_USERNAME"] = "some_user"
monkeypatch.setattr(getpass, "getuser", mock_getpwuid_raise)
spec = tag_test(base_spec, "test_run_local")
result = run_local(
spec, command=f"{examples_path}/training.py", workdir=examples_path
)
verify_state(result)
if old_v3io_username is not None:
environ["V3IO_USERNAME"] = old_v3io_username
else:
del environ["V3IO_USERNAME"]


def test_run_local_handler():
Expand Down

0 comments on commit 282169c

Please sign in to comment.