77
88from dvc import api
99from dvc .api import SummonError
10+ from dvc .compat import fspath
1011from dvc .exceptions import FileMissingError
1112from dvc .main import main
1213from dvc .path_info import URLInfo
@@ -82,16 +83,15 @@ def test_open_external(remote_url, erepo_dir):
8283
8384
8485@pytest .mark .parametrize ("remote_url" , all_remote_params , indirect = True )
85- def test_missing (remote_url , tmp_dir , erepo_dir , monkeypatch ):
86- _set_remote_url_and_commit (erepo_dir .dvc , remote_url )
87- with monkeypatch .context () as m :
88- m .chdir (fspath (erepo_dir ))
86+ def test_missing (remote_url , tmp_dir , dvc ):
87+ tmp_dir .dvc_gen ("foo" , "foo" )
88+ run_dvc ("remote" , "add" , "-d" , "upstream" , remote_url )
8989
9090 # Remove cache to make foo missing
91- shutil .rmtree (erepo_dir . dvc .cache .local .cache_dir )
91+ shutil .rmtree (dvc .cache .local .cache_dir )
9292
9393 with pytest .raises (FileMissingError ):
94- api .read ("foo" , repo = fspath ( erepo_dir ) )
94+ api .read ("foo" )
9595
9696
9797def _set_remote_url_and_commit (repo , remote_url ):
@@ -108,27 +108,23 @@ def test_open_scm_controlled(tmp_dir, erepo_dir):
108108 assert fd .read () == "file content"
109109
110110
111- def test_open_not_cached (dvc , erepo_dir , monkeypatch ):
111+ def test_open_not_cached (dvc ):
112+ metric_file = "metric.txt"
112113 metric_content = "0.6"
113- with monkeypatch .context () as m :
114- m .chdir (erepo_dir )
115- erepo_dir .dvc .run (
116- metrics_no_cache = ["metric.txt" ],
117- cmd = (
118- 'python -c "{}"' .format (
119- "open('{}', 'w').write('{}')" .format (
120- "metric.txt" , metric_content
121- )
122- )
123- ),
124- )
125-
126- with api .open ("metric.txt" , repo = fspath (erepo_dir )) as fd :
114+ metric_code = "open('{}', 'w').write('{}')" .format (
115+ metric_file , metric_content
116+ )
117+ dvc .run (
118+ metrics_no_cache = [metric_file ],
119+ cmd = ('python -c "{}"' .format (metric_code )),
120+ )
121+
122+ with api .open (metric_file ) as fd :
127123 assert fd .read () == metric_content
128124
129- os .remove (fspath ( erepo_dir / "metric.txt" ) )
125+ os .remove (metric_file )
130126 with pytest .raises (FileMissingError ):
131- api .read ("metric.txt" , repo = fspath ( erepo_dir ) )
127+ api .read (metric_file )
132128
133129
134130def test_summon (tmp_dir , dvc , erepo_dir ):
0 commit comments