radiasoft / pykern

Apache License 2.0
5 stars 7 forks source link

Multiple cases, but same data dir #473

Open gurhar1133 opened 4 months ago

gurhar1133 commented 4 months ago

Sometimes there are multiple test cases that manipulate the same data in different ways. It is helpful to copy that same data_dir into separate subdirs in work_dir so that afterwards you can inspect the work_dir sub dirs to see what happened.

Example of what this could look like:

def test_ ... ():
    def _a(case_work_dir):
        ...

    def _bcase_work_dir):
        ...

    def _c(case_work_dir):
        ...

    pkunit.cases_from_same_data_dir(
        [
            _a,
            _b,
            _c,
        ]
    )
# in pkunit
def cases_from_same_data_dir(cases):
    w = pkunit.work_dir()
    for i in range(len(cases)):
        c = w.join(str(i + 1))
        shutil.copytree(pkunit.data_dir(), c)
        cases[i](c)

After the test runs I'll have a work_dir/1, work_dir/2, ..., work_dir/n to inspect. pkunit.case_dirs will call shutil.copytree on an existing work_subdir however which will run an error and not allow for the comparison of different cases effects on the data

Thoughts @robnagler ?

gurhar1133 commented 4 months ago

ping @robnagler

robnagler commented 4 months ago

Not a top priority, sorry.

gurhar1133 commented 4 months ago

Not a top priority, sorry.

NP