Exemplo n.º 1
0
    def test_cleanup_dirs_without_configfile(self, tmp_path):
        # -- SETUP:
        setup_workdir(tmp_path, [
            ".venv_DEFAULT/.dir",
            "downloads/.dir",
        ])
        my_dir1 = tmp_path / ".venv_DEFAULT"
        my_dir2 = tmp_path / "downloads"
        assert my_dir1.exists() and my_dir1.is_dir()
        assert my_dir2.exists() and my_dir2.is_dir()

        tasks_dir = tmp_path / "tasks.py"
        tasks_dir.write_text(TASKS_FILE_TEXT_USING_CLEANUP_MODULE_ONLY)
        config_dir = tmp_path / "invoke.yaml"
        assert not config_dir.exists()

        # -- EXECUTE AND VERIFY:
        with use_subprocess_coverage(tmp_path):
            with cd(str(tmp_path)):
                output = ensure_text(run_with_output("invoke cleanup.all"))

        assert not my_dir1.exists()
        assert not my_dir2.exists()
        expected1 = "RMTREE: .venv_DEFAULT"
        expected2 = "RMTREE: downloads"
        assert expected1 in output
        assert expected2 in output
Exemplo n.º 2
0
    def test_invoke_calls_other_cleanup_task(self, tmp_path):
        tasks_file = tmp_path / "tasks.py"
        tasks_file.write_text(u"""
from __future__ import absolute_import, print_function
from invoke import task, Collection
import invoke_cleanup as cleanup

@task
def foo_clean(ctx):
    print("CALLED: foo_clean")

namespace = Collection(foo_clean)
namespace.add_collection(Collection.from_module(cleanup), name="cleanup")
namespace.configure(cleanup.namespace.configuration())

from invoke_cleanup import cleanup_all_tasks
cleanup_all_tasks.add_task(foo_clean, name="foo_clean")
cleanup_all_tasks.configure(namespace.configuration())
""")

        # -- EXECUTE AND VERIFY:
        with use_subprocess_coverage(tmp_path):
            with cd(str(tmp_path)):
                output = ensure_text(run_with_output("invoke cleanup.all"))

        expected1 = "CLEANUP TASK: foo-clean"
        expected2 = "CALLED: foo_clean"
        assert expected1 in output
        assert expected2 in output
Exemplo n.º 3
0
    def test_with_configfile_and_cleanup_files_overrides_default(
            self, tmp_path):
        # -- SETUP:
        setup_workdir(tmp_path, [
            "one.xxx",
            "more/two.zzz",
        ])
        my_file1 = tmp_path / "one.xxx"
        my_file2 = tmp_path / "more/two.zzz"
        assert my_file1.exists() and my_file1.is_file()
        assert my_file2.exists() and my_file2.is_file()

        tasks_file = tmp_path / "tasks.py"
        tasks_file.write_text(TASKS_FILE_TEXT_USING_CLEANUP_MODULE_ONLY)
        config_file = tmp_path / "invoke.yaml"
        config_file.write_text(u"""
cleanup_all:
    files:
      - "**/*.xxx"
      - "**/*.zzz"
""")

        # -- EXECUTE AND VERIFY:
        with use_subprocess_coverage(tmp_path):
            with cd(str(tmp_path)):
                output = ensure_text(run_with_output("invoke cleanup.all"))

        assert not my_file1.exists()
        assert not my_file2.exists()
        expected1 = "REMOVE: one.xxx"
        expected2 = "REMOVE: more/two.zzz"
        assert expected1 in output
        assert expected2 in output
Exemplo n.º 4
0
    def test_invoke_calls_other_task_that_uses_cleanup_dirs(self, tmp_path):
        # -- SETUP:
        setup_workdir(tmp_path, [
            "one.xxx/.dir",
            "more/two.xxx/.dir",
        ])
        my_dir1 = tmp_path / "one.xxx"
        my_dir2 = tmp_path / "more/two.xxx"
        assert my_dir1.exists() and my_dir1.is_dir()
        assert my_dir2.exists() and my_dir2.is_dir()

        tasks_file = tmp_path / "tasks.py"
        tasks_file.write_text(u"""
from __future__ import absolute_import, print_function
from invoke import task, Collection
import invoke_cleanup as cleanup
from invoke_cleanup import cleanup_dirs

@task
def foo_clean(ctx):
    print("CALLED: foo_clean")
    cleanup_dirs(["**/*.xxx"])

namespace = Collection(foo_clean)
namespace.add_collection(Collection.from_module(cleanup), name="cleanup")
namespace.configure(cleanup.namespace.configuration())

from invoke_cleanup import cleanup_all_tasks
cleanup_all_tasks.add_task(foo_clean, name="foo_clean")
cleanup_all_tasks.configure(namespace.configuration())
""")

        # -- EXECUTE AND VERIFY:
        with cd(str(tmp_path)):
            output = ensure_text(run_with_output("invoke cleanup.all"))

        assert not my_dir1.exists()
        assert not my_dir2.exists()
        expected1 = "RMTREE: one.xxx"
        expected2 = "RMTREE: more/two.xxx"
        assert expected1 in output
        assert expected2 in output
Exemplo n.º 5
0
    def test_with_configfile_and_cleanup_directories_overrides_default(
            self, tmp_path):
        # -- SETUP:
        setup_workdir(
            tmp_path,
            [
                # -- HINT: DEFAULT cleanup.directories = [] EMPTY-LIST
                ".venv_DEFAULT/.dir",
                "one.xxx/.dir",
                "more/two.zzz/.dir",
            ])
        my_dir0 = tmp_path / ".venv_DEFAULT"
        my_dir1 = tmp_path / "one.xxx"
        my_dir2 = tmp_path / "more/two.zzz"
        assert my_dir0.exists() and my_dir0.is_dir()
        assert my_dir1.exists() and my_dir1.is_dir()
        assert my_dir2.exists() and my_dir2.is_dir()

        tasks_dir = tmp_path / "tasks.py"
        tasks_dir.write_text(TASKS_FILE_TEXT_USING_CLEANUP_MODULE_ONLY)
        config_dir = tmp_path / "invoke.yaml"
        config_dir.write_text(u"""
cleanup_all:
    directories:
      - "**/*.xxx"
      - "**/*.zzz"
""")

        # -- EXECUTE AND VERIFY:
        with use_subprocess_coverage(tmp_path):
            with cd(str(tmp_path)):
                output = ensure_text(run_with_output("invoke cleanup.all"))

        assert my_dir0.exists(
        ), "OOPS: DEFAULT cleanup_all.directories was NOT_OVERWRITTEN"
        assert not my_dir1.exists()
        assert not my_dir2.exists()
        expected1 = "RMTREE: one.xxx"
        expected2 = "RMTREE: more/two.zzz"
        assert expected1 in output
        assert expected2 in output
Exemplo n.º 6
0
    def test_with_configfile_and_cleanup_extra_directories_extends_default(
            self, tmp_path):
        # -- SETUP:
        setup_workdir(tmp_path, [
            ".venv_CONFIG/.dir",
            "one.xxx/.dir",
            "more/two.zzz/.dir",
        ])
        my_dir0 = tmp_path / ".venv_CONFIG"
        my_dir1 = tmp_path / "one.xxx"
        my_dir2 = tmp_path / "more/two.zzz"
        assert my_dir1.exists() and my_dir1.is_dir()
        assert my_dir2.exists() and my_dir2.is_dir()

        tasks_dir = tmp_path / "tasks.py"
        tasks_dir.write_text(TASKS_FILE_TEXT_USING_CLEANUP_MODULE_ONLY)
        config_dir = tmp_path / "invoke.yaml"
        config_dir.write_text(u"""
cleanup:
    directories:
      - ".venv*"
    extra_directories:
      - "**/*.xxx"
      - "**/*.zzz"
""")

        # -- EXECUTE AND VERIFY:
        with use_subprocess_coverage(tmp_path):
            with cd(str(tmp_path)):
                output = ensure_text(run_with_output("invoke cleanup.all"))

        assert not my_dir0.exists()
        assert not my_dir1.exists()
        assert not my_dir2.exists()
        expected0 = "RMTREE: .venv_CONFIG"
        expected1 = "RMTREE: one.xxx"
        expected2 = "RMTREE: more/two.zzz"
        assert expected0 in output
        assert expected1 in output
        assert expected2 in output
Exemplo n.º 7
0
def run_with_output_in_directory(directory):
    with use_subprocess_coverage(directory):
        with use_setup_python_path():
            with cd(str(directory)):
                output = ensure_text(run_with_output("invoke cleanup"))
    return output