To simply create a dvc or git controlled foo you need to:
def test_someting(erepo_dir, monkeypatch):
# for dvc
with monkeypatch.context() as m:
m.chdir(erepo_dir)
erepo_dir.dvc_gen("foo", "foo")
# for git
with monkeypatch.context() as m:
m.chdir(erepo_dir)
erepo_dir.scm_gen("foo", "foo", commit="add foo")
Which is far more bloaty then for tmp_dir. See here how @pared is struggling with it)
I see two options:
Make it work without chdir:
erepo_dir.dvc_gen("foo", "foo")
This will, however, bring an assymetry:
# creates erepo_dir / foo
erepo_dir.gen("foo", "foo")
# dvc adds erepo_dir / foo
erepo_dir.dvc_add("foo")
# dvc adds <curdir> / foo
erepo_dir.dvc.add("foo")
We don't really want to wrap scm and dvc objects.
Use chdir but make it simpler:
def test_someting(erepo_dir):
with erepo_dir.chdir():
erepo_dir.dvc_gen("foo", "foo")
Saved one line, no need to add monkeypatch to args, still have nesting and an extra line compared to option 1. Retain symmetry, may use scm and dvc with relpaths in the context.
What do you guys think? @pared, @efiop, @mroutis?
@Suor How about creating ErepoDir, that would be extending TmpDir, and would chdir before calling operation with super?
@pared this is the same as option 1 from test authors POV, asymmetry will be there unless we wrap dvc and scm too, which I don't want to do.
Hmm, in that case, I would vote for 2nd point. It does not introduce asymmetry, and also visually marks (indentation) when we are editing the erepo, so it becomes a bit more readable.
Second option :+1:
Resume: going for less magic, a.k.a. option 2.