Exemple #1
0
def test_parse_config_missing(tmpdir):
    cfg = config.parse("does_not_exist/setup.cfg")
    assert cfg is None

    setup_path = tmpdir.mkdir("fail").join("setup.cfg")

    cfg = config.parse(str(setup_path))
    assert cfg is None
Exemple #2
0
def test_parse_config_missing(tmpdir):
    ctx = config.init_project_ctx("does_not_exist/setup.cfg")
    assert ctx

    cfg = config.parse(ctx)
    assert cfg is None

    setup_path = tmpdir.mkdir("fail").join("setup.cfg")
    ctx = config.init_project_ctx(setup_path)
    assert ctx

    cfg = config.parse(ctx)
    assert cfg is None
Exemple #3
0
def test_parse_project_cfg():
    project_path = util.FIXTURES_DIR / "project_b"
    config_path = util.FIXTURES_DIR / "project_b" / "setup.cfg"

    with config_path.open() as fh:
        config_data = fh.read()

    assert "v201307.0456-beta" in config_data

    ctx = config.init_project_ctx(project_path)
    assert ctx == config.ProjectContext(project_path, config_path, 'cfg', None)

    cfg = config.parse(ctx)

    assert cfg
    assert cfg.current_version == "v201307.0456-beta"
    assert cfg.commit is True
    assert cfg.tag is True
    assert cfg.push is True

    assert set(cfg.file_patterns.keys()) == {
        "setup.py",
        "README.rst",
        "setup.cfg",
        "src/module_v*/__init__.py",
    }
Exemple #4
0
def test_parse_empty_config(tmpdir):
    setup_path = tmpdir.mkdir("fail").join("setup.cfg")
    setup_path.write("")
    ctx = config.init_project_ctx(setup_path)
    assert ctx

    cfg = config.parse(ctx)
    assert cfg is None
Exemple #5
0
def test_parse_invalid_version(tmpdir):
    setup_path = tmpdir.mkdir("fail").join("setup.cfg")
    setup_path.write("\n".join((
        "[pycalver]",
        f"current_version = 0.1.0",
        "commit = False",
    )))

    cfg = config.parse(str(setup_path))
    assert cfg is None
Exemple #6
0
def test_parse_missing_version(tmpdir):
    setup_path = tmpdir.mkdir("fail").join("setup.cfg")
    setup_path.write("\n".join((
        "[pycalver]",
        # f"current_version = v201808.0001-dev",
        "commit = False",
    )))

    cfg = config.parse(str(setup_path))
    assert cfg is None
Exemple #7
0
def test_parse_invalid_version(tmpdir):
    setup_path = tmpdir.mkdir("fail").join("setup.cfg")
    setup_path.write("\n".join(
        ("[pycalver]", "current_version = 0.1.0", "commit = False")))

    ctx = config.init_project_ctx(setup_path)
    assert ctx

    cfg = config.parse(ctx)
    assert cfg is None
Exemple #8
0
def test_iter_file_paths():
    with util.Project(project="a") as project:
        ctx = config.init_project_ctx(project.dir)
        cfg = config.parse(ctx)
        assert cfg

        file_paths = {
            str(file_path) for file_path, patterns in rewrite._iter_file_paths(cfg.file_patterns)
        }

    assert file_paths == {"pycalver.toml", "README.md"}
Exemple #9
0
def test_error_bad_path():
    with util.Project(project="b") as project:
        ctx = config.init_project_ctx(project.dir)
        cfg = config.parse(ctx)
        assert cfg

        (project.dir / "setup.py").unlink()
        try:
            list(rewrite._iter_file_paths(cfg.file_patterns))
            assert False, "expected IOError"
        except IOError as ex:
            assert "setup.py" in str(ex)
Exemple #10
0
def test_error_bad_pattern():
    with util.Project(project="b") as project:
        ctx = config.init_project_ctx(project.dir)
        cfg = config.parse(ctx)
        assert cfg

        patterns = copy.deepcopy(cfg.file_patterns)
        patterns["setup.py"] = patterns["setup.py"][0] + "invalid"

        try:
            new_vinfo = version.parse_version_info("v201809.1234")
            list(rewrite.diff(new_vinfo, patterns))
            assert False, "expected rewrite.NoPatternMatch"
        except rewrite.NoPatternMatch as ex:
            assert "setup.py" in str(ex)
Exemple #11
0
def test_iter_file_globs():
    with util.Project(project="b") as project:
        ctx = config.init_project_ctx(project.dir)
        cfg = config.parse(ctx)
        assert cfg

        file_paths = {
            str(file_path) for file_path, patterns in rewrite._iter_file_paths(cfg.file_patterns)
        }

    assert file_paths == {
        "setup.cfg",
        "setup.py",
        "README.rst",
        "src/module_v1/__init__.py",
        "src/module_v2/__init__.py",
    }
Exemple #12
0
def test_parse_cfg_file(tmpdir):
    project_path = tmpdir.mkdir("minimal")
    setup_cfg = project_path.join("setup.cfg")
    setup_cfg.write(SETUP_CFG_FIXTURE)

    ctx = config.init_project_ctx(project_path)
    assert ctx == config.ProjectContext(project_path, setup_cfg, 'cfg', None)

    cfg = config.parse(ctx)

    assert cfg
    assert cfg.current_version == "v201808.0456-beta"
    assert cfg.tag is True
    assert cfg.commit is True
    assert cfg.push is True

    assert cfg.file_patterns == {
        "setup.py": ["{pycalver}", "{pep440_pycalver}"],
        "setup.cfg": ['current_version = "{pycalver}"'],
    }
Exemple #13
0
def test_parse_toml_file(tmpdir):
    project_path = tmpdir.mkdir("minimal")
    setup_cfg = project_path.join("pycalver.toml")
    setup_cfg.write(PYCALVER_TOML_FIXTURE_1)

    ctx = config.init_project_ctx(project_path)
    assert ctx == config.ProjectContext(project_path, setup_cfg, 'toml', None)

    cfg = config.parse(ctx)

    assert cfg
    assert cfg.current_version == "v201808.0123-alpha"
    assert cfg.tag is True
    assert cfg.commit is True
    assert cfg.push is True

    assert cfg.file_patterns == {
        "README.md": ["{pycalver}", "{pep440_pycalver}"],
        "pycalver.toml": ['current_version = "{pycalver}"'],
    }
Exemple #14
0
def test_parse(tmpdir):
    setup_path = tmpdir.mkdir("minimal").join("setup.cfg")
    setup_path.write("\n".join((
        "[pycalver]",
        f"current_version = v201808.0001-dev",
        "commit = False",
        "tag = False",
        "",
        "[pycalver:file:setup.cfg]",
        "patterns = ",
        "    current_version = {version}",
    )))

    cfg = config.parse(str(setup_path))

    assert cfg
    assert cfg.current_version == "v201808.0001-dev"
    assert not cfg.tag
    assert not cfg.commit

    assert cfg.file_patterns == {"setup.cfg": ["current_version = {version}"]}
Exemple #15
0
def test_parse_default_pattern(tmpdir):
    project_path = util.FIXTURES_DIR / "project_c"
    config_path = util.FIXTURES_DIR / "project_c" / "pyproject.toml"

    ctx = config.init_project_ctx(project_path)

    assert ctx == config.ProjectContext(project_path, config_path, "toml",
                                        None)

    cfg = config.parse(ctx)

    assert cfg

    assert cfg.current_version == "v2017q1.54321"
    assert cfg.commit is True
    assert cfg.tag is True
    assert cfg.push is True

    assert cfg.file_patterns == {
        "pyproject.toml":
        [r'current_version = "v{year}q{quarter}.{build_no}"']
    }
Exemple #16
0
def test_parse_project_toml():
    project_path = util.FIXTURES_DIR / "project_a"
    config_path = util.FIXTURES_DIR / "project_a" / "pycalver.toml"

    with config_path.open() as fh:
        config_data = fh.read()

    assert "v201710.0123-alpha" in config_data

    ctx = config.init_project_ctx(project_path)
    assert ctx == config.ProjectContext(project_path, config_path, "toml",
                                        None)

    cfg = config.parse(ctx)

    assert cfg

    assert cfg.current_version == "v201710.0123-alpha"
    assert cfg.commit is True
    assert cfg.tag is True
    assert cfg.push is True

    assert set(cfg.file_patterns.keys()) == {"pycalver.toml", "README.md"}
Exemple #17
0
def test_parse_empty_config(tmpdir):
    setup_path = tmpdir.mkdir("fail").join("setup.cfg")
    setup_path.write("")

    cfg = config.parse(str(setup_path))
    assert cfg is None