From 39f010e50aecb85465ff7f5601f6b9ec7bdfb31d Mon Sep 17 00:00:00 2001 From: pawel Date: Mon, 30 Dec 2019 16:16:37 +0100 Subject: [PATCH 1/4] api: open: fix open scm controlled test --- tests/func/test_api.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/func/test_api.py b/tests/func/test_api.py index 4c21c55318..4f405a85b8 100644 --- a/tests/func/test_api.py +++ b/tests/func/test_api.py @@ -100,15 +100,16 @@ def _set_remote_url_and_commit(repo, remote_url): repo.scm.commit("modify remote") -# FIXME: this test doesn't use scm ;D -def test_open_scm_controlled(dvc_repo, repo_dir): - stage, = dvc_repo.add(repo_dir.FOO) +def test_open_scm_controlled(tmp_dir, scm, dvc): + tmp_dir.scm_gen({"scm_controlled": "file content"}, commit="create file") - stage_content = open(stage.path, "r").read() - with api.open(stage.path) as fd: - assert fd.read() == stage_content + with api.open("scm_controlled") as fd: + assert fd.read() == "file content" +# def test_open_not_cached2(tmp_dir, scm, dvc): +# tmp_dir.dvc_gen({"file": "file content"}) + # TODO: simplify, we shouldn't need run. def test_open_not_cached(dvc): metric_file = "metric.txt" From d9eaabe9bfbb891556e2561f760dc8dc5e63feb3 Mon Sep 17 00:00:00 2001 From: pawel Date: Mon, 30 Dec 2019 18:06:54 +0100 Subject: [PATCH 2/4] some fixmes --- tests/func/test_api.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/func/test_api.py b/tests/func/test_api.py index 4f405a85b8..42fab4991a 100644 --- a/tests/func/test_api.py +++ b/tests/func/test_api.py @@ -29,6 +29,7 @@ def run_dvc(*argv): assert main(argv) == 0 +# FIXME @pytest.mark.parametrize("remote_url", remote_params, indirect=True) def test_get_url(remote_url, tmp_dir, dvc, repo_template): run_dvc("remote", "add", "-d", "upstream", remote_url) @@ -48,6 +49,7 @@ def test_get_url_external(remote_url, erepo_dir): assert api.get_url("foo", repo=repo_url) == expected_url +# FIXME @pytest.mark.parametrize("remote_url", all_remote_params, indirect=True) def test_open(remote_url, tmp_dir, dvc): run_dvc("remote", "add", "-d", "upstream", remote_url) @@ -81,6 +83,7 @@ def test_open_external(remote_url, erepo_dir): assert api.read("version", repo=repo_url, rev="branch") == "branch" +# FIXME @pytest.mark.parametrize("remote_url", all_remote_params, indirect=True) def test_missing(remote_url, tmp_dir, dvc): tmp_dir.dvc_gen("foo", "foo") @@ -100,6 +103,7 @@ def _set_remote_url_and_commit(repo, remote_url): repo.scm.commit("modify remote") +# FIXME def test_open_scm_controlled(tmp_dir, scm, dvc): tmp_dir.scm_gen({"scm_controlled": "file content"}, commit="create file") @@ -107,9 +111,7 @@ def test_open_scm_controlled(tmp_dir, scm, dvc): assert fd.read() == "file content" -# def test_open_not_cached2(tmp_dir, scm, dvc): -# tmp_dir.dvc_gen({"file": "file content"}) - +# FIXME WHAT TO DO ABOUT THAT ONE # TODO: simplify, we shouldn't need run. def test_open_not_cached(dvc): metric_file = "metric.txt" From 020c0496a619bb2f493102684b8685e6e47ab75b Mon Sep 17 00:00:00 2001 From: pawel Date: Fri, 3 Jan 2020 11:30:33 +0100 Subject: [PATCH 3/4] tests: api: convert to dir helpers --- tests/func/test_api.py | 53 +++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/tests/func/test_api.py b/tests/func/test_api.py index 42fab4991a..f6dd6134e2 100644 --- a/tests/func/test_api.py +++ b/tests/func/test_api.py @@ -29,7 +29,6 @@ def run_dvc(*argv): assert main(argv) == 0 -# FIXME @pytest.mark.parametrize("remote_url", remote_params, indirect=True) def test_get_url(remote_url, tmp_dir, dvc, repo_template): run_dvc("remote", "add", "-d", "upstream", remote_url) @@ -49,7 +48,6 @@ def test_get_url_external(remote_url, erepo_dir): assert api.get_url("foo", repo=repo_url) == expected_url -# FIXME @pytest.mark.parametrize("remote_url", all_remote_params, indirect=True) def test_open(remote_url, tmp_dir, dvc): run_dvc("remote", "add", "-d", "upstream", remote_url) @@ -83,17 +81,17 @@ def test_open_external(remote_url, erepo_dir): assert api.read("version", repo=repo_url, rev="branch") == "branch" -# FIXME @pytest.mark.parametrize("remote_url", all_remote_params, indirect=True) -def test_missing(remote_url, tmp_dir, dvc): - tmp_dir.dvc_gen("foo", "foo") - run_dvc("remote", "add", "-d", "upstream", remote_url) +def test_missing(remote_url, tmp_dir, erepo_dir, monkeypatch): + _set_remote_url_and_commit(erepo_dir.dvc, remote_url) + with monkeypatch.context() as m: + m.chdir(fspath(erepo_dir)) # Remove cache to make foo missing - shutil.rmtree(dvc.cache.local.cache_dir) + shutil.rmtree(erepo_dir.dvc.cache.local.cache_dir) with pytest.raises(FileMissingError): - api.read("foo") + api.read("foo", repo=fspath(erepo_dir)) def _set_remote_url_and_commit(repo, remote_url): @@ -103,33 +101,34 @@ def _set_remote_url_and_commit(repo, remote_url): repo.scm.commit("modify remote") -# FIXME -def test_open_scm_controlled(tmp_dir, scm, dvc): - tmp_dir.scm_gen({"scm_controlled": "file content"}, commit="create file") +def test_open_scm_controlled(tmp_dir, erepo_dir): + erepo_dir.scm_gen({"scm_controlled": "file content"}, commit="create file") - with api.open("scm_controlled") as fd: + with api.open("scm_controlled", repo=fspath(erepo_dir)) as fd: assert fd.read() == "file content" -# FIXME WHAT TO DO ABOUT THAT ONE -# TODO: simplify, we shouldn't need run. -def test_open_not_cached(dvc): - metric_file = "metric.txt" +def test_open_not_cached(dvc, erepo_dir, monkeypatch): metric_content = "0.6" - metric_code = "open('{}', 'w').write('{}')".format( - metric_file, metric_content - ) - dvc.run( - metrics_no_cache=[metric_file], - cmd=('python -c "{}"'.format(metric_code)), - ) - - with api.open(metric_file) as fd: + with monkeypatch.context() as m: + m.chdir(erepo_dir) + erepo_dir.dvc.run( + metrics_no_cache=["metric.txt"], + cmd=( + 'python -c "{}"'.format( + "open('{}', 'w').write('{}')".format( + "metric.txt", metric_content + ) + ) + ), + ) + + with api.open("metric.txt", repo=fspath(erepo_dir)) as fd: assert fd.read() == metric_content - os.remove(metric_file) + os.remove(fspath(erepo_dir / "metric.txt")) with pytest.raises(FileMissingError): - api.read(metric_file) + api.read("metric.txt", repo=fspath(erepo_dir)) def test_summon(tmp_dir, dvc, erepo_dir): From af425318aa9e45793dc7e6a906b72869e527a3e2 Mon Sep 17 00:00:00 2001 From: pawel Date: Fri, 3 Jan 2020 15:32:18 +0100 Subject: [PATCH 4/4] tests: api: roll back erepo usage --- tests/func/test_api.py | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/tests/func/test_api.py b/tests/func/test_api.py index f6dd6134e2..96ee3f9646 100644 --- a/tests/func/test_api.py +++ b/tests/func/test_api.py @@ -7,6 +7,7 @@ from dvc import api from dvc.api import SummonError +from dvc.compat import fspath from dvc.exceptions import FileMissingError from dvc.main import main from dvc.path_info import URLInfo @@ -82,16 +83,15 @@ def test_open_external(remote_url, erepo_dir): @pytest.mark.parametrize("remote_url", all_remote_params, indirect=True) -def test_missing(remote_url, tmp_dir, erepo_dir, monkeypatch): - _set_remote_url_and_commit(erepo_dir.dvc, remote_url) - with monkeypatch.context() as m: - m.chdir(fspath(erepo_dir)) +def test_missing(remote_url, tmp_dir, dvc): + tmp_dir.dvc_gen("foo", "foo") + run_dvc("remote", "add", "-d", "upstream", remote_url) # Remove cache to make foo missing - shutil.rmtree(erepo_dir.dvc.cache.local.cache_dir) + shutil.rmtree(dvc.cache.local.cache_dir) with pytest.raises(FileMissingError): - api.read("foo", repo=fspath(erepo_dir)) + api.read("foo") def _set_remote_url_and_commit(repo, remote_url): @@ -108,27 +108,23 @@ def test_open_scm_controlled(tmp_dir, erepo_dir): assert fd.read() == "file content" -def test_open_not_cached(dvc, erepo_dir, monkeypatch): +def test_open_not_cached(dvc): + metric_file = "metric.txt" metric_content = "0.6" - with monkeypatch.context() as m: - m.chdir(erepo_dir) - erepo_dir.dvc.run( - metrics_no_cache=["metric.txt"], - cmd=( - 'python -c "{}"'.format( - "open('{}', 'w').write('{}')".format( - "metric.txt", metric_content - ) - ) - ), - ) - - with api.open("metric.txt", repo=fspath(erepo_dir)) as fd: + metric_code = "open('{}', 'w').write('{}')".format( + metric_file, metric_content + ) + dvc.run( + metrics_no_cache=[metric_file], + cmd=('python -c "{}"'.format(metric_code)), + ) + + with api.open(metric_file) as fd: assert fd.read() == metric_content - os.remove(fspath(erepo_dir / "metric.txt")) + os.remove(metric_file) with pytest.raises(FileMissingError): - api.read("metric.txt", repo=fspath(erepo_dir)) + api.read(metric_file) def test_summon(tmp_dir, dvc, erepo_dir):