From 659eb04705b2788693c8723f144e461b9b13a281 Mon Sep 17 00:00:00 2001 From: Alexander Schepanovski Date: Fri, 6 Dec 2019 16:00:05 +0100 Subject: [PATCH 1/5] test: write a usage text for dir_helpers --- tests/dir_helpers.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/dir_helpers.py b/tests/dir_helpers.py index 1d97897904..050925e661 100644 --- a/tests/dir_helpers.py +++ b/tests/dir_helpers.py @@ -1,3 +1,47 @@ +""" +The goal of this module is making dvc functional tests setup a breeze. This +includes a temporary dir, initializing git and dvc repos and bootstraping some +file structure. + +The cornerstone of these fixtures is `tmp_dir`, which creates a temporary dir +and changes path to it, it might be combined with `scm` and `dvc` to initialize +empty git and dvc repos. `tmp_dir` returns a Path instance, which should save +you from using `open()`, `os` and `os.path` utils many times: + + (tmp_dir / "some_file").write_text("some text") + # ... + assert "some text" == (tmp_dir / "some_file").read_text() + assert (tmp_dir / "some_file").exists() + +Additionally it provides `.gen()`, `.scm_gen()` and `.dvc_gen()` methoda to +bootstrap a required file structure in a single call: + + # Generate a dir with files + tmp_dir.gen({"dir": {"file": "file text", "second_file": "..."}}) + + # Generate a single file, dirs will be created along the way + tmp_dir.gen("dir/file", "file text") + + # Generate + git add + tmp_dir.scm_gen({"file1": "...", ...}) + + # Generate + git add + git commit + tmp_dir.scm_gen({"file1": "...", ...}, commit="add files") + + # Generate + dvc add + tmp_dir.dvc_gen({"file1": "...", ...}) + + # Generate + dvc add + git commit -am "..." + # This commits stages to git not the generated files. + tmp_dir.dvc_gen({"file1": "...", ...}, commit="add files") + +Making it easier to bootstrap things has a supergoal of incentivizing a move +from global repo template to creating everything inplace, which: + + - makes all path references local to test, enhancing readability + - allows using telling filenames, e.g. "git_tracked_file" instead of "foo" + - does not create whatever is not needed +""" from __future__ import unicode_literals import os From 5bec7007614e44545fbae34ff6bc5018ea32492b Mon Sep 17 00:00:00 2001 From: Alexander Schepanovski Date: Fri, 6 Dec 2019 18:35:03 +0100 Subject: [PATCH 2/5] test: accept Paths in tmp_dir.gen() --- tests/dir_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dir_helpers.py b/tests/dir_helpers.py index 050925e661..ac47f65a94 100644 --- a/tests/dir_helpers.py +++ b/tests/dir_helpers.py @@ -88,7 +88,7 @@ def _require(self, name): ) def gen(self, struct, text=""): - if isinstance(struct, basestring): + if isinstance(struct, (basestring, pathlib.PurePath)): struct = {struct: text} self._gen(struct) From 0cd6106189e373b54efa2d8f5b917f230dfabda1 Mon Sep 17 00:00:00 2001 From: Alexander Schepanovski Date: Mon, 9 Dec 2019 11:24:41 +0300 Subject: [PATCH 3/5] Update tests/dir_helpers.py Co-Authored-By: Mr. Outis --- tests/dir_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dir_helpers.py b/tests/dir_helpers.py index ac47f65a94..2645e5e294 100644 --- a/tests/dir_helpers.py +++ b/tests/dir_helpers.py @@ -13,7 +13,7 @@ assert "some text" == (tmp_dir / "some_file").read_text() assert (tmp_dir / "some_file").exists() -Additionally it provides `.gen()`, `.scm_gen()` and `.dvc_gen()` methoda to +Additionally it provides `.gen()`, `.scm_gen()` and `.dvc_gen()` methods to bootstrap a required file structure in a single call: # Generate a dir with files From a59041aeab54ef5be2b943ed93a2454bf3a9010f Mon Sep 17 00:00:00 2001 From: Alexander Schepanovski Date: Mon, 9 Dec 2019 11:33:35 +0300 Subject: [PATCH 4/5] test: update dir_helpers usage Co-Authored-By: Mr. Outis --- tests/dir_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dir_helpers.py b/tests/dir_helpers.py index 2645e5e294..74e920a01c 100644 --- a/tests/dir_helpers.py +++ b/tests/dir_helpers.py @@ -40,7 +40,7 @@ - makes all path references local to test, enhancing readability - allows using telling filenames, e.g. "git_tracked_file" instead of "foo" - - does not create whatever is not needed + - does not create unnecessary files """ from __future__ import unicode_literals From 1da133b9ed62964decce674fd6446e5ed52ee6e2 Mon Sep 17 00:00:00 2001 From: Alexander Schepanovski Date: Mon, 9 Dec 2019 11:34:10 +0300 Subject: [PATCH 5/5] test: update dir_helpers usage Co-Authored-By: Mr. Outis --- tests/dir_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dir_helpers.py b/tests/dir_helpers.py index 74e920a01c..105b6d9684 100644 --- a/tests/dir_helpers.py +++ b/tests/dir_helpers.py @@ -1,6 +1,6 @@ """ The goal of this module is making dvc functional tests setup a breeze. This -includes a temporary dir, initializing git and dvc repos and bootstraping some +includes a temporary dir, initializing git and dvc repos and bootstrapping some file structure. The cornerstone of these fixtures is `tmp_dir`, which creates a temporary dir