-
Notifications
You must be signed in to change notification settings - Fork 1.2k
api: open scm controlled files #2566
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
Changes from all commits
bbcfce9
a3b1c32
6525553
9d1f245
f6730da
4f59e6e
2f64620
958fcfa
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import os | ||
|
||
import pytest | ||
import shutil | ||
|
||
from dvc import api | ||
from dvc.exceptions import OutputFileMissingError | ||
from dvc.exceptions import FileMissingError | ||
from dvc.main import main | ||
from dvc.path_info import URLInfo | ||
from dvc.remote.config import RemoteConfig | ||
|
@@ -134,7 +136,7 @@ def test_missing(repo_dir, dvc_repo, remote_url): | |
# Remove cache to make foo missing | ||
shutil.rmtree(dvc_repo.cache.local.cache_dir) | ||
|
||
with pytest.raises(OutputFileMissingError): | ||
with pytest.raises(FileMissingError): | ||
api.read(repo_dir.FOO) | ||
|
||
|
||
|
@@ -143,3 +145,30 @@ def _set_remote_url_and_commit(repo, remote_url): | |
rconfig.modify("upstream", "url", remote_url) | ||
repo.scm.add([repo.config.config_file]) | ||
repo.scm.commit("modify remote") | ||
|
||
|
||
def test_open_scm_controlled(dvc_repo, repo_dir): | ||
stage, = dvc_repo.add(repo_dir.FOO) | ||
|
||
stage_content = open(stage.path, "r").read() | ||
with api.open(stage.path) as fd: | ||
assert fd.read() == stage_content | ||
|
||
|
||
def test_open_not_cached(dvc_repo): | ||
metric_file = "metric.txt" | ||
metric_content = "0.6" | ||
metric_code = "open('{}', 'w').write('{}')".format( | ||
metric_file, metric_content | ||
) | ||
dvc_repo.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(metric_file) | ||
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. Is this one needed for https://github.com/iterative/dvc/pull/2566/files#diff-16d20341660af559adf7d9e7306c760dR458 again? This seems weird. 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. Yes, but I don't think there is another way to test it. We want to test whether |
||
with pytest.raises(FileMissingError): | ||
api.read(metric_file) | ||
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. These two tests are almost the same. I would say simply move: os.remove(metric_file)
with pytest.raises(NotCachedOutputFileMissingError):
api.read(metric_file) to the end of the first one and remove the second test. Also, why do you create new code file, while we already have 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. New code is required due to issue regarding original code described in #2574 |
Uh oh!
There was an error while loading. Please reload this page.