Dvc: test: erepo_dir bootstrapping is bloaty

Created on 17 Dec 2019  路  5Comments  路  Source: iterative/dvc

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:

  1. 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.

  2. 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?

p3-nice-to-have refactoring testing

All 5 comments

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yukw777 picture yukw777  路  45Comments

shcheklein picture shcheklein  路  36Comments

mdekstrand picture mdekstrand  路  43Comments

gcoter picture gcoter  路  38Comments

Casyfill picture Casyfill  路  56Comments