示例#1
0
def test_pretend_move(tmpfolder):
    # Given a file or directory exists,
    tmpfolder.join("a-file.txt").write("text")
    tmpfolder.join("another-file.txt").write("text")
    # When it is moved without pretend kwarg,
    tmpfolder.join("a-dir").ensure_dir()
    fs.move("a-file.txt", target="a-dir")
    # Then the src should be moved
    assert tmpfolder.join("a-dir/a-file.txt").check()
    # When it is moved with pretend kwarg,
    fs.move("another-file.txt", target="a-dir", pretend=True)
    # Then the src should not be moved
    assert not tmpfolder.join("a-dir/another-file.txt").check()
    assert tmpfolder.join("another-file.txt").check()
示例#2
0
def test_move_multiple_args(tmpfolder):
    # Given several files exist,
    tmpfolder.join("a-file.txt").write("text")
    tmpfolder.join("another-file.txt").write("text")
    assert not tmpfolder.join("a-dir/a-file.txt").check()
    assert not tmpfolder.join("a-dir/another-file.txt").check()
    # When they are moved together,
    tmpfolder.join("a-dir").ensure_dir()
    fs.move("a-file.txt", "another-file.txt", target="a-dir")
    # Then the original paths should not exist
    assert not tmpfolder.join("a-file.txt").check()
    assert not tmpfolder.join("another-file.txt").check()
    # And the new paths should exist
    assert tmpfolder.join("a-dir/a-file.txt").read() == "text"
    assert tmpfolder.join("a-dir/another-file.txt").read() == "text"
示例#3
0
def test_move(tmpfolder):
    # Given a file or directory exists,
    tmpfolder.join("a-file.txt").write("text")
    tmpfolder.join("a-folder").ensure_dir()
    tmpfolder.join("a-folder/another-file.txt").write("text")
    # When it is moved,
    tmpfolder.join("a-dir").ensure_dir()
    fs.move("a-file.txt", target="a-dir")
    fs.move("a-folder", target="a-dir")
    # Then the original path should not exist
    assert not tmpfolder.join("a-file.txt").check()
    assert not tmpfolder.join("a-folder").check()
    # And the new path should exist
    assert tmpfolder.join("a-dir/a-file.txt").check()
    assert tmpfolder.join("a-dir/a-folder/another-file.txt").check()
示例#4
0
def test_move_log(tmpfolder, caplog):
    caplog.set_level(logging.INFO)
    fname1 = uniqstr()  # Use a unique name to get easily identifiable logs
    fname2 = uniqstr()
    dname = uniqstr()
    # Given a file or directory exists,
    tmpfolder.join(fname1).write("text")
    tmpfolder.join(fname2).write("text")
    # When it is moved without log kwarg,
    tmpfolder.join(dname).ensure_dir()
    fs.move(fname1, target=dname)
    # Then no log should be created.
    logs = caplog.text
    assert not re.search(f"move.+{fname1}.+to.+{dname}", logs)
    # When it is moved with log kwarg,
    fs.move(fname2, target=dname, log=True)
    # Then log should be created.
    logs = caplog.text
    assert re.search(f"move.+{fname2}.+to.+{dname}", logs)
示例#5
0
def test_move_non_dir_target(tmpfolder):
    # Given a file exists,
    tmpfolder.join("a-file.txt").write("text")
    assert not tmpfolder.join("another-file.txt").check()
    # When it is moved,
    fs.move("a-file.txt", target="another-file.txt")
    # Then the original path should not exist
    assert not tmpfolder.join("a-file.txt").check()
    # And the new path should exist
    assert tmpfolder.join("another-file.txt").read() == "text"

    # Given a dir exists,
    tmpfolder.join("a-dir").ensure_dir()
    tmpfolder.join("a-dir/a-file.txt").write("text")
    assert not tmpfolder.join("another-dir/a-file.txt").check()
    # When it is moved to a path that do not exist yet,
    fs.move("a-dir", target="another-dir")
    # Then the dir should be renamed.
    assert not tmpfolder.join("a-dir").check()
    assert tmpfolder.join("another-dir/a-file.txt").read() == "text"
示例#6
0
def test_version_of_subdir(tmpfolder):
    projects = ["main_project", "inner_project"]
    for project in projects:
        opts = cli.parse_args([project])
        opts = api.bootstrap_options(opts)
        _, opts = actions.get_default_options({}, opts)
        struct, _ = structure.define_structure({}, opts)
        struct, _ = structure.create_structure(struct, opts)
        repo.init_commit_repo(project, struct)
    rm_rf(Path("inner_project", ".git"))
    move("inner_project", target="main_project/inner_project")

    # setuptools_scm required explicitly setting the git root when setup.py is
    # not at the root of the repository
    nested_setup_py = Path(tmpfolder, "main_project/inner_project/setup.py")
    content = nested_setup_py.read_text()
    content = content.replace(
        "use_scm_version={", 'use_scm_version={"root": "..", "relative_to": __file__, '
    )
    nested_setup_py.write_text(content)
    nested_pyproject_toml = Path(tmpfolder, "main_project/inner_project/pyproject.toml")
    config = toml.loads(nested_pyproject_toml.read_text())
    config["tool"]["setuptools_scm"]["root"] = ".."
    nested_pyproject_toml.write_text(toml.dumps(config))

    with chdir("main_project"):
        main_version = (
            subprocess.check_output([sys.executable, "setup.py", "--version"])
            .strip()
            .splitlines()[-1]
        )
        with chdir("inner_project"):
            inner_version = (
                subprocess.check_output([sys.executable, "setup.py", "--version"])
                .strip()
                .splitlines()[-1]
            )
    assert main_version.strip() == inner_version.strip()