Пример #1
0
def test_init_commit_repo(tmpdir):
    project = "my_project"
    struct = {project: {
        "my_file": "Some other content"}}
    structure.create_structure(struct)
    repo.init_commit_repo(project, struct)
    assert os.path.exists(os.path.join(project, ".git"))
Пример #2
0
def test_add_tag(tmpdir):  # noqa
    project = "my_project"
    struct = {project: {"my_file": "Some other content", "my_dir": {"my_file": "Some more content"}}}
    structure.create_structure(struct)
    repo.init_commit_repo(project, struct)
    repo.add_tag(project, "v0.0")
    repo.add_tag(project, "v0.1", "Message with whitespace")
Пример #3
0
def test_apply_update_rules(tmpdir):  # noqa
    NO_OVERWRITE = structure.FileOp.NO_OVERWRITE
    NO_CREATE = structure.FileOp.NO_CREATE
    rules = {
        "a": NO_OVERWRITE,
        "c": {
            "b": NO_OVERWRITE
        },
        "d": {
            "a": NO_OVERWRITE,
            "b": NO_CREATE,
            "c": NO_CREATE,
            "d": NO_OVERWRITE
        },
        "e": NO_CREATE
    }
    struct = {
        "a": "a",
        "b": "b",
        "c": {
            "a": "a",
            "b": "b"
        },
        "d": {
            "a": "a",
            "b": "b"
        },
        "e": "e"
    }
    dir_struct = {"a": "a", "c": {"b": "b"}}
    exp_struct = {"b": "b", "c": {"a": "a"}, "d": {"a": "a"}}
    structure.create_structure(dir_struct)
    res_struct = structure.apply_update_rules(rules, struct)
    assert res_struct == exp_struct
Пример #4
0
def test_apply_update_rules(tmpdir):  # noqa
    NO_OVERWRITE = structure.FileOp.NO_OVERWRITE
    NO_CREATE = structure.FileOp.NO_CREATE
    rules = {"a": NO_OVERWRITE,
             "c": {"b": NO_OVERWRITE},
             "d": {"a": NO_OVERWRITE,
                   "b": NO_CREATE,
                   "c": NO_CREATE,
                   "d": NO_OVERWRITE},
             "e": NO_CREATE}
    struct = {"a": "a",
              "b": "b",
              "c": {"a": "a",
                    "b": "b"},
              "d": {"a": "a",
                    "b": "b"},
              "e": "e"}
    dir_struct = {"a": "a",
                  "c": {"b": "b"}}
    exp_struct = {"b": "b",
                  "c": {"a": "a"},
                  "d": {"a": "a"}}
    structure.create_structure(dir_struct)
    res_struct = structure.apply_update_rules(rules, struct)
    assert res_struct == exp_struct
Пример #5
0
def test_init_commit_repo(tmpdir):  # noqa
    project = "my_project"
    struct = {project: {"my_file": "Some other content", "my_dir": {"my_file": "Some more content"}, "dummy": None}}
    structure.create_structure(struct)
    dummy_file = os.path.join(project, "dummy")
    with open(dummy_file, "w"):
        os.utime(dummy_file, None)
    repo.init_commit_repo(project, struct)
    assert os.path.exists(os.path.join(project, ".git"))
Пример #6
0
def test_get_git_root_with_nonegit(tmpfolder, nonegit_mock):
    project = "my_project"
    struct = {project: {
        "my_file": "Some other content",
        "my_dir": {"my_file": "Some more content"}}
    }
    structure.create_structure(struct, {})
    with utils.chdir(project):
        git_root = repo.get_git_root(default='.')
    assert git_root == '.'
Пример #7
0
def test_get_git_root_with_nonegit(tmpfolder, nonegit_mock):
    project = "my_project"
    struct = {
        "my_file": "Some other content",
        "my_dir": {"my_file": "Some more content"},
    }
    structure.create_structure(struct, {"project_path": project})
    with chdir(project):
        git_root = repo.get_git_root(default=".")
    assert git_root == "."
Пример #8
0
def test_get_git_root_with_nogit(tmpdir, nogit_mock): # noqa
    project = "my_project"
    struct = {project: {
        "my_file": "Some other content",
        "my_dir": {"my_file": "Some more content"}}
    }
    structure.create_structure(struct)
    with utils.chdir(project):
        git_root = repo.get_git_root(default='.')
    assert git_root == '.'
Пример #9
0
def test_get_files(tmpdir):  # noqa
    struct = {'subdir': {'script.py': '#Python script...'},
              'root_script.py': '#Root Python script...'}
    create_structure(struct)
    files = utils.get_files("*.py")
    assert 'root_script.py' in files
    assert 'subdir/script.py' not in files
    files = utils.get_files("**.py")
    assert 'root_script.py' in files
    assert 'subdir/script.py' in files
Пример #10
0
def test_add_tag(tmpdir):  # noqa
    project = "my_project"
    struct = {project: {
        "my_file": "Some other content",
        "my_dir": {"my_file": "Some more content"}}
    }
    structure.create_structure(struct)
    repo.init_commit_repo(project, struct)
    repo.add_tag(project, "v0.0")
    repo.add_tag(project, "v0.1", "Message with whitespace")
Пример #11
0
def test_dirty_workspace(tmpfolder):
    project = "my_project"
    struct = {"dummyfile": "NO CONTENT"}
    structure.create_structure(struct, dict(project_path=project))
    repo.init_commit_repo(project, struct)
    path = tmpfolder / project
    assert info.is_git_workspace_clean(path)
    with open(str(path / "dummyfile"), "w") as fh:
        fh.write("CHANGED\n")
    assert not info.is_git_workspace_clean(path)
Пример #12
0
def test_add_tag(tmpfolder):
    project = "my_project"
    struct = {
        "my_file": "Some other content",
        "my_dir": {"my_file": "Some more content"},
    }
    structure.create_structure(struct, dict(project_path=project))
    repo.init_commit_repo(project, struct)
    repo.add_tag(project, "v0.0")
    repo.add_tag(project, "v0.1", "Message with whitespace")
Пример #13
0
def test_create_structure_when_updating(tmpdir):  # noqa
    struct = {"my_file": "Some content",
              "my_folder": {
                  "my_dir_file": "Some other content"
              },
              "empty_folder": {}}
    structure.create_structure(struct, update=False)
    struct["my_folder"]["my_dir_file"] = "Changed content"
    structure.create_structure(struct, update=True)
    with open("my_folder/my_dir_file") as fh:
        assert fh.read() == "Changed content"
Пример #14
0
def test_get_git_root(tmpfolder):
    project = "my_project"
    struct = {project: {
        "my_file": "Some other content",
        "my_dir": {"my_file": "Some more content"}}
    }
    structure.create_structure(struct, {})
    repo.init_commit_repo(project, struct)
    with utils.chdir(project):
        git_root = repo.get_git_root()
    assert os.path.basename(git_root) == project
Пример #15
0
def test_create_structure_when_updating(tmpfolder):
    struct = {"my_file": "Some content",
              "my_folder": {
                  "my_dir_file": "Some other content"
              },
              "empty_folder": {}}
    structure.create_structure(struct, dict(update=False))
    struct["my_folder"]["my_dir_file"] = "Changed content"
    structure.create_structure(struct, dict(update=True))
    with open("my_folder/my_dir_file") as fh:
        assert fh.read() == "Changed content"
Пример #16
0
def test_get_git_root(tmpdir): # noqa
    project = "my_project"
    struct = {project: {
        "my_file": "Some other content",
        "my_dir": {"my_file": "Some more content"}}
    }
    structure.create_structure(struct)
    repo.init_commit_repo(project, struct)
    with utils.chdir(project):
        git_root = repo.get_git_root()
    assert os.path.basename(git_root) == project
Пример #17
0
def test_get_git_root(tmpfolder):
    project = "my_project"
    struct = {
        "my_file": "Some other content",
        "my_dir": {"my_file": "Some more content"},
    }
    structure.create_structure(struct, {"project_path": project})
    repo.init_commit_repo(project, struct)
    with chdir(project):
        git_root = repo.get_git_root()
    assert Path(git_root).name == project
Пример #18
0
def test_init_commit_repo(tmpdir):  # noqa
    project = "my_project"
    struct = {project: {
        "my_file": "Some other content",
        "my_dir": {"my_file": "Some more content"},
        "dummy": None}
    }
    structure.create_structure(struct)
    dummy_file = os.path.join(project, "dummy")
    with open(dummy_file, 'w'):
        os.utime(dummy_file, None)
    repo.init_commit_repo(project, struct)
    assert os.path.exists(os.path.join(project, ".git"))
Пример #19
0
def test_pretend_init_commit_repo(tmpfolder):
    with tmpfolder.mkdir("my_porject").as_cwd():
        struct = {
            "my_file": "Some other content",
            "my_dir": {"my_file": "Some more content"},
            "dummy": None,
        }
        structure.create_structure(struct, {})
        dummy_file = Path("dummy")
        with dummy_file.open(mode="w"):
            os.utime(str(dummy_file), None)
        repo.init_commit_repo(".", struct, pretend=True)
        assert not Path(".git").exists()
Пример #20
0
def test_pretend_init_commit_repo(tmpfolder):
    project = "my_project"
    struct = {project: {
        "my_file": "Some other content",
        "my_dir": {"my_file": "Some more content"},
        "dummy": None}
    }
    structure.create_structure(struct, {})
    dummy_file = os.path.join(project, "dummy")
    with open(dummy_file, 'w'):
        os.utime(dummy_file, None)
    repo.init_commit_repo(project, struct, pretend=True)
    assert not os.path.exists(os.path.join(project, ".git"))
Пример #21
0
def test_get_files(tmpdir):  # noqa
    struct = {
        'subdir': {
            'script.py': '#Python script...'
        },
        'root_script.py': '#Root Python script...'
    }
    create_structure(struct)
    files = utils.get_files("*.py")
    assert 'root_script.py' in files
    assert 'subdir/script.py' not in files
    files = utils.get_files("**.py")
    assert 'root_script.py' in files
    assert 'subdir/script.py' in files
Пример #22
0
def test_create_structure(tmpdir):  # noqa
    struct = {"my_file": "Some content",
              "my_folder": {
                  "my_dir_file": "Some other content"
              },
              "empty_folder": {}}
    structure.create_structure(struct)

    assert isdir("my_folder")
    assert isdir("empty_folder")
    assert isfile("my_folder/my_dir_file")
    assert isfile("my_file")
    assert open("my_file").read() == "Some content"
    assert open("my_folder/my_dir_file").read() == "Some other content"
Пример #23
0
def test_create_structure(tmpdir):  # noqa
    struct = {"my_file": "Some content",
              "my_folder": {
                  "my_dir_file": "Some other content"
              },
              "empty_folder": {}}
    structure.create_structure(struct)

    assert isdir("my_folder")
    assert isdir("empty_folder")
    assert isfile("my_folder/my_dir_file")
    assert isfile("my_file")
    assert open("my_file").read() == "Some content"
    assert open("my_folder/my_dir_file").read() == "Some other content"
Пример #24
0
def test_create_structure(tmpfolder):
    struct = {"my_file": "Some content",
              "my_folder": {
                  "my_dir_file": "Some other content",
                  "empty_file": "",
                  "file_not_created": None
              },
              "empty_folder": {}}
    expected = {"my_file": "Some content",
                "my_folder": {
                    "my_dir_file": "Some other content",
                    "empty_file": ""
                },
                "empty_folder": {}}
    changed, _ = structure.create_structure(struct, {})

    assert changed == expected
    assert isdir("my_folder")
    assert isdir("empty_folder")
    assert isfile("my_folder/my_dir_file")
    assert isfile("my_folder/empty_file")
    assert not isfile("my_folder/file_not_created")
    assert isfile("my_file")
    assert open("my_file").read() == "Some content"
    assert open("my_folder/my_dir_file").read() == "Some other content"
    assert open("my_folder/empty_file").read() == ""
Пример #25
0
def test_create_structure(tmpfolder):
    struct = {
        "my_file": "Some content",
        "my_folder": {
            "my_dir_file": "Some other content",
            "empty_file": "",
            "file_not_created": None
        },
        "empty_folder": {}
    }
    expected = {
        "my_file": "Some content",
        "my_folder": {
            "my_dir_file": "Some other content",
            "empty_file": ""
        },
        "empty_folder": {}
    }
    changed, _ = structure.create_structure(struct, {})

    assert changed == expected
    assert isdir("my_folder")
    assert isdir("empty_folder")
    assert isfile("my_folder/my_dir_file")
    assert isfile("my_folder/empty_file")
    assert not isfile("my_folder/file_not_created")
    assert isfile("my_file")
    assert open("my_file").read() == "Some content"
    assert open("my_folder/my_dir_file").read() == "Some other content"
    assert open("my_folder/empty_file").read() == ""
Пример #26
0
def test_pretend_init_commit_repo(tmpfolder):
    project = "my_project"
    struct = {
        project: {
            "my_file": "Some other content",
            "my_dir": {
                "my_file": "Some more content"
            },
            "dummy": None,
        }
    }
    structure.create_structure(struct, {})
    dummy_file = os.path.join(project, "dummy")
    with open(dummy_file, "w"):
        os.utime(dummy_file, None)
    repo.init_commit_repo(project, struct, pretend=True)
    assert not os.path.exists(os.path.join(project, ".git"))
Пример #27
0
def test_version_of_subdir(tmpdir): # noqa
    projects = ["main_project", "inner_project"]
    for project in projects:
        opts = cli.parse_args([project])
        opts = cli.get_default_opts(opts['project'], **opts)
        struct = structure.make_structure(opts)
        structure.create_structure(struct)
        repo.init_commit_repo(project, struct)
    shutil.rmtree(os.path.join('inner_project', '.git'))
    shutil.move('inner_project', 'main_project/inner_project')
    with utils.chdir('main_project'):
        main_version = subprocess.check_output([
            'python', 'setup.py', '--version']).strip()
        with utils.chdir('inner_project'):
            inner_version = subprocess.check_output([
                'python', 'setup.py', '--version']).strip()
    assert main_version == inner_version
Пример #28
0
def test_version_of_subdir(tmpdir):  # noqa
    projects = ["main_project", "inner_project"]
    for project in projects:
        opts = cli.parse_args([project])
        opts = cli.get_default_opts(opts['project'], **opts)
        struct = structure.make_structure(opts)
        structure.create_structure(struct)
        repo.init_commit_repo(project, struct)
    shutil.rmtree(os.path.join('inner_project', '.git'))
    shutil.move('inner_project', 'main_project/inner_project')
    with utils.chdir('main_project'):
        main_version = subprocess.check_output(
            ['python', 'setup.py', '--version']).strip()
        with utils.chdir('inner_project'):
            inner_version = subprocess.check_output(
                ['python', 'setup.py', '--version']).strip()
    assert main_version == inner_version
Пример #29
0
def test_version_of_subdir(tmpfolder):
    projects = ["main_project", "inner_project"]
    for project in projects:
        opts = cli.parse_args([project])
        _, opts = api.get_default_options({}, opts)
        struct, _ = structure.define_structure({}, opts)
        struct, _ = structure.apply_update_rules(struct, opts)
        structure.create_structure(struct, {})
        repo.init_commit_repo(project, struct)
    shutil.rmtree(os.path.join('inner_project', '.git'))
    shutil.move('inner_project', 'main_project/inner_project')
    with utils.chdir('main_project'):
        main_version = subprocess.check_output(
            ['python', 'setup.py', '--version']).strip().splitlines()[-1]
        with utils.chdir('inner_project'):
            inner_version = subprocess.check_output(
                ['python', 'setup.py', '--version']).strip().splitlines()[-1]
    assert main_version.strip() == inner_version.strip()
Пример #30
0
def test_version_of_subdir(tmpfolder):
    projects = ["main_project", "inner_project"]
    for project in projects:
        opts = cli.parse_args([project])
        _, opts = api.get_default_options({}, opts)
        struct, _ = structure.define_structure({}, opts)
        struct, _ = structure.apply_update_rules(struct, opts)
        structure.create_structure(struct, {})
        repo.init_commit_repo(project, struct)
    shutil.rmtree(os.path.join('inner_project', '.git'))
    shutil.move('inner_project', 'main_project/inner_project')
    with utils.chdir('main_project'):
        main_version = subprocess.check_output([
            'python', 'setup.py', '--version']).strip().splitlines()[-1]
        with utils.chdir('inner_project'):
            inner_version = subprocess.check_output([
                'python', 'setup.py', '--version']).strip().splitlines()[-1]
    assert main_version.strip() == inner_version.strip()
Пример #31
0
def test_apply_update_rules(tmpfolder):
    NO_OVERWRITE = structure.FileOp.NO_OVERWRITE
    NO_CREATE = structure.FileOp.NO_CREATE
    opts = dict(update=True)

    struct = {"a": ("a", NO_OVERWRITE),
              "b": "b",
              "c": {"a": "a",
                    "b": ("b", NO_OVERWRITE)},
              "d": {"a": ("a", NO_OVERWRITE),
                    "b": ("b", NO_CREATE)},
              "e": ("e", NO_CREATE)}
    dir_struct = {"a": "a",
                  "c": {"b": "b"}}
    exp_struct = {"b": "b",
                  "c": {"a": "a"},
                  "d": {"a": "a"}}
    structure.create_structure(dir_struct, opts)
    res_struct, _ = update.apply_update_rules(struct, opts)
    assert res_struct == exp_struct
Пример #32
0
def test_version_of_subdir(tmpfolder):
    projects = ["main_project", "inner_project"]
    for project in projects:
        opts = cli.parse_args([project])
        opts = cli.process_opts(opts)
        _, opts = api.get_default_options({}, opts)
        struct, _ = structure.define_structure({}, opts)
        struct, _ = update.apply_update_rules(struct, opts)
        structure.create_structure(struct, {})
        repo.init_commit_repo(project, struct)
    utils.rm_rf(os.path.join("inner_project", ".git"))
    shutil.move("inner_project", "main_project/inner_project")
    with utils.chdir("main_project"):
        main_version = (subprocess.check_output(
            [sys.executable, "setup.py",
             "--version"]).strip().splitlines()[-1])
        with utils.chdir("inner_project"):
            inner_version = (subprocess.check_output(
                [sys.executable, "setup.py",
                 "--version"]).strip().splitlines()[-1])
    assert main_version.strip() == inner_version.strip()
Пример #33
0
def test_apply_update_rules(tmpfolder):
    NO_OVERWRITE = structure.FileOp.NO_OVERWRITE
    NO_CREATE = structure.FileOp.NO_CREATE
    opts = dict(update=True)

    struct = {
        "a": ("a", NO_OVERWRITE),
        "b": "b",
        "c": {
            "a": "a",
            "b": ("b", NO_OVERWRITE)
        },
        "d": {
            "a": ("a", NO_OVERWRITE),
            "b": ("b", NO_CREATE)
        },
        "e": ("e", NO_CREATE)
    }
    dir_struct = {"a": "a", "c": {"b": "b"}}
    exp_struct = {"b": "b", "c": {"a": "a"}, "d": {"a": "a"}}
    structure.create_structure(dir_struct, opts)
    res_struct, _ = update.apply_update_rules(struct, opts)
    assert res_struct == exp_struct
Пример #34
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()
Пример #35
0
def test_check_files_exist(tmpdir):  # noqa
    struct = {"a": "a", "b": "b", "c": {"a": "a", "b": "b"}, "d": {"a": "a"}}
    dir_struct = {"a": "a", "c": {"b": "b"}}
    structure.create_structure(dir_struct)
    res = structure.check_files_exist(struct)
    assert res == dir_struct
Пример #36
0
def test_create_structure_when_dir_exists(tmpfolder):
    struct = {"my_folder": {"my_dir_file": "Some other content"}}
    os.mkdir("my_folder")
    with pytest.raises(OSError):
        structure.create_structure(struct, dict(update=False))
Пример #37
0
def test_create_structure_with_wrong_type(tmpfolder):
    with pytest.raises(RuntimeError):
        struct = {"strange_thing": 1}
        structure.create_structure(struct, {})
Пример #38
0
def test_create_structure_create_project_folder(tmpfolder):
    struct = {"my_folder": {"my_dir_file": "Some other content"}}
    opts = dict(project_path="my_project", update=False)
    structure.create_structure(struct, opts)
    assert isdir("my_project")
Пример #39
0
def test_create_structure_with_wrong_type(tmpdir):  # noqa
    with pytest.raises(RuntimeError):
        struct = {"strange_thing": 1}
        structure.create_structure(struct)
Пример #40
0
def test_check_files_exist(tmpdir):  # noqa
    struct = {"a": "a", "b": "b", "c": {"a": "a", "b": "b"}, "d": {"a": "a"}}
    dir_struct = {"a": "a", "c": {"b": "b"}}
    structure.create_structure(dir_struct)
    res = structure.check_files_exist(struct)
    assert res == dir_struct
Пример #41
0
def test_create_structure_when_dir_exists(tmpdir):  # noqa
    struct = {"my_folder": {"my_dir_file": "Some other content"}}
    os.mkdir("my_folder")
    with pytest.raises(OSError):
        structure.create_structure(struct, update=False)
Пример #42
0
def test_create_structure_with_wrong_type(tmpdir):  # noqa
    with pytest.raises(RuntimeError):
        struct = {"strange_thing": 1}
        structure.create_structure(struct)
Пример #43
0
def test_create_structure_with_wrong_type(tmpfolder):
    with pytest.raises(RuntimeError):
        struct = {"strange_thing": 1}
        structure.create_structure(struct, {})