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
def test_parse_default_pattern(): project_path = util.FIXTURES_DIR / "project_c" config_path = util.FIXTURES_DIR / "project_c" / "pyproject.toml" config_rel_path = "pyproject.toml" ctx = config.init_project_ctx(project_path) assert ctx == config.ProjectContext(project_path, config_path, config_rel_path, "toml", None) cfg = config.parse(ctx) assert cfg assert cfg.current_version == "v2017q1.54321" # assert cfg.version_pattern == "vYYYYqQ.BUILD" assert cfg.version_pattern == "v{year}q{quarter}.{build_no}" assert cfg.commit is True assert cfg.tag is True assert cfg.push is True raw_patterns_by_filepath = _parse_raw_patterns_by_filepath(cfg) assert raw_patterns_by_filepath == { "pyproject.toml": [r'current_version = "v{year}q{quarter}.{build_no}"'] }
def test_parse_project_cfg(): project_path = util.FIXTURES_DIR / "project_b" config_path = util.FIXTURES_DIR / "project_b" / "setup.cfg" config_rel_path = "setup.cfg" with config_path.open() as fobj: config_data = fobj.read() assert "v201307.0456-beta" in config_data ctx = config.init_project_ctx(project_path) assert ctx == config.ProjectContext(project_path, config_path, config_rel_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", }
def test_parse_project_toml(): project_path = util.FIXTURES_DIR / "project_a" config_path = util.FIXTURES_DIR / "project_a" / "bumpver.toml" config_rel_path = "bumpver.toml" with config_path.open() as fobj: config_data = fobj.read() assert "v2017.0123-alpha" in config_data ctx = config.init_project_ctx(project_path) assert ctx == config.ProjectContext(project_path, config_path, config_rel_path, "toml", None) cfg = config.parse(ctx) assert cfg assert cfg.current_version == "v2017.0123-alpha" assert cfg.commit is True assert cfg.tag is True assert cfg.push is True files = set(cfg.file_patterns.keys()) assert files == {"bumpver.toml", "README.md"}
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
def test_parse_invalid_version(tmpdir): setup_path = tmpdir.mkdir("fail").join("setup.cfg") setup_path.write("\n".join( ("[bumpver]", "current_version = 0.1.0", "commit = False"))) ctx = config.init_project_ctx(setup_path) assert ctx cfg = config.parse(ctx) assert cfg is None
def test_parse_default_cfg(): project_path = util.FIXTURES_DIR / "project_b" ctx = config.init_project_ctx(project_path) default_cfg = config.default_config(ctx) buf = mk_buf(default_cfg) raw_cfg = config._parse_cfg(buf) cfg = config._parse_config(raw_cfg) assert cfg
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_path_patterns_items(cfg.file_patterns)) assert False, "expected IOError" except IOError as ex: assert "setup.py" in str(ex)
def test_parse_missing_version(tmpdir): setup_path = tmpdir.mkdir("fail").join("setup.cfg") setup_path.write("\n".join(( "[bumpver]", # f"current_version = v201808.1001-dev", "commit = False", ))) ctx = config.init_project_ctx(setup_path) assert ctx cfg = config.parse(ctx) assert cfg is None
def test_iter_file_paths(): with util.Project(project="a") as project: ctx = config.init_project_ctx(project.dir) assert ctx cfg = config.parse(ctx) assert cfg _paths_and_patterns = rewrite.iter_path_patterns_items( cfg.file_patterns) file_paths = { str(file_path) for file_path, patterns in _paths_and_patterns } assert file_paths == {"bumpver.toml", "README.md"}
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 _paths_and_patterns = rewrite.iter_path_patterns_items( cfg.file_patterns) file_paths = { str(file_path) for file_path, patterns in _paths_and_patterns } assert file_paths == { "setup.cfg", "setup.py", "README.rst", "src/module_v1/__init__.py", "src/module_v2/__init__.py", }
def test_v1_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) original_pattern = patterns["setup.py"][0] invalid_pattern = v1patterns.compile_pattern( original_pattern.version_pattern, original_pattern.raw_pattern + ".invalid", ) patterns["setup.py"] = [invalid_pattern] try: old_vinfo = v1version.parse_version_info("v201808.0233") new_vinfo = v1version.parse_version_info("v201809.1234") list(v1rewrite.diff(old_vinfo, new_vinfo, patterns)) assert False, "expected rewrite.NoPatternMatch" except rewrite.NoPatternMatch as ex: assert "setup.py" in str(ex)
def test_parse_cfg_file(tmpdir): project_path = tmpdir.mkdir("minimal") setup_cfg = project_path.join("setup.cfg") setup_cfg.write(SETUP_CFG_FIXTURE) setup_cfg_rel_path = "setup.cfg" ctx = config.init_project_ctx(project_path) assert ctx == config.ProjectContext(project_path, setup_cfg, setup_cfg_rel_path, 'cfg', None) cfg = config.parse(ctx) assert cfg assert cfg.current_version == "v201808.0456-beta" assert cfg.version_pattern == "vYYYY0M.BUILD[-TAG]" assert cfg.tag is True assert cfg.commit is True assert cfg.push is True raw_patterns_by_filepath = _parse_raw_patterns_by_filepath(cfg) assert raw_patterns_by_filepath == { "setup.py": ["vYYYY0M.BUILD[-TAG]", "YYYY0M.BLD[PYTAGNUM]"], "setup.cfg": ['current_version = "vYYYY0M.BUILD[-TAG]"'], }
def test_parse_toml_file(tmpdir): project_path = tmpdir.mkdir("minimal") cfg_file = project_path.join("pycalver.toml") cfg_file.write(PYCALVER_TOML_FIXTURE_1) cfg_file_rel_path = "pycalver.toml" ctx = config.init_project_ctx(project_path) assert ctx == config.ProjectContext(project_path, cfg_file, cfg_file_rel_path, 'toml', None) cfg = config.parse(ctx) assert cfg assert cfg.current_version == "v2020.1003-alpha" assert cfg.version_pattern == "vYYYY.BUILD[-TAG]" assert cfg.tag is True assert cfg.commit is True assert cfg.push is True raw_patterns_by_filepath = _parse_raw_patterns_by_filepath(cfg) assert raw_patterns_by_filepath == { "README.md": ["vYYYY.BUILD[-TAG]", "YYYY.BLD[PYTAGNUM]"], "pycalver.toml": ['current_version = "vYYYY.BUILD[-TAG]"'], }