def test_bump_cmd_bad(mutable_repo, caplog, capsys): mutable_repo.chdir() ############## ## No flag/setup.py # Both auto-discoveries fail # rc = cli.run('bump -v 0.0.1'.split()) assert rc != 0 check_text(caplog.text, require=[r"Cannot auto-discover versioning scheme,"], forbid=[ r"Auto-discovered versioning scheme", r"Auto-discovered \d+ sub-project\(s\)", r"Cannot auto-discover \(sub-\)project", ], is_regex=True) out, err = capsys.readouterr() assert not err and not out ############## ## --mono-project # no-current version # caplog.clear() make_setup_py_without_version(mutable_repo, 'base') rc = cli.run('bump --mono-project -v 1.1.1'.split()) assert rc != 0 check_text(caplog.text, require=[ r"Auto-discovered \d+ sub-project\(s\)", r"No version-engravings happened, bump aborted.", ], forbid=[ r"Auto-discovered versioning scheme", r"Cannot auto-discover versioning scheme," ], is_regex=True) out, err = capsys.readouterr() assert not err and not out
def main(): """ Cmd-line entrypoint to bump PEP-440 versions on sub-project in Git repos. - Invokes :func:`polyvers.cli.run()` with ``sys.argv[1:]``. - In order to set cmd-line arguments, invoke directly the function above. """ if not globals().get('__package__'): __package__ = "polyvers" # noqa: A001 F841 @ReservedAssignment req_ver = (3, 6) if sys.version_info < req_ver: raise NotImplementedError( "Sorry, Python >= %s is required, found: %s" % (req_ver, sys.version_info)) # ## Rename app! # # # if sys.argv: # import polyvers # polyvers.APPNAME = osp.basename(sys.argv[0]) from polyvers import cli cli.run(argv=sys.argv[1:])
def test_bump_cmd_mono_project(mutable_repo, caplog, capsys): mutable_repo.chdir() ############## ## --mono-project # caplog.clear() setupy_fpath = make_setup_py(mutable_repo, 'simple') rc = cli.run('bump -v --mono-project 0.0.1'.split()) # with capsys.disabled(): # print(caplog.text) assert rc == 0 check_text(caplog.text, require=[ r"Bumped projects", r"simple-0.0.0 --> 0.0.1", ], forbid=[ "Cannot auto-discover (sub-)project", "Cannot auto-discover versioning scheme," ]) out, err = capsys.readouterr() assert not out and not err gitlog = cmd.git.log(format="format:%s %d", all=True) # with capsys.disabled(): # print(gitlog) exp = tw.dedent("""\ chore(ver): bump simple-r0.0.0 -> 0.0.1 (tag: r0.0.1, latest) added 'setup.py' (HEAD -> master, tag: v0.0.1) some_msg (origin/master, origin/HEAD)""") assert exp in gitlog cmd.git.checkout('latest') # Branch-name from BumpCmd.release_branch. setuppy_text = setupy_fpath.read_text(encoding='utf-8') assert re.search("version *= *'0.0.1',", setuppy_text), setuppy_text
def test_config_cmd(cmd, match, illegal): ## VERY IMPORTANT TCs FOR ConfigCmd!!! lc = ListConsumer() rc = cli.run(cmd.split(), cmd_consumer=lc) assert rc == 0 check_text(lc.items, match, illegal)
def test_status_cmd_pvtags(mutable_repo, caplog, capsys): mutable_repo.chdir() ############## ## setup.py + --monorepo # caplog.clear() make_setup_py(mutable_repo, 'base') make_setup_py(mutable_repo / 'foo_project', 'foo') rc = cli.run('status --monorepo -v'.split()) assert rc == 0 check_text(caplog.text, require=[ "Auto-discovered 2 sub-project(s)", ], forbid=[ "Cannot auto-discover (sub-)project", "Cannot auto-discover versioning scheme," ]) out, err = capsys.readouterr() assert not err assert ['base', 'foo'] == yu.yloads(out) rc = cli.run('status --monorepo --all'.split()) assert rc == 0 out, err = capsys.readouterr() exp = yu.yloads( '- pname: base\n basepath: .\n gitver:\n history: []\n' '- pname: foo\n basepath: foo_project\n gitver:\n history: []\n') assert exp == yu.yloads(out) ############## ## TAG REPO # caplog.clear() cmd.git.tag('base-v0.1.0', m='annotate!') rc = cli.run('status -v'.split()) assert rc == 0 check_text(caplog.text, require=[ "Auto-discovered 2 sub-project(s)", "Auto-discovered versioning scheme", ], forbid=[ "Cannot auto-discover (sub-)project", "Cannot auto-discover versioning scheme," ]) out, err = capsys.readouterr() assert not err exp = ['base-v0.1.0', 'foo'] assert exp == yu.yloads(out) rc = cli.run('status --all'.split()) assert rc == 0 out, err = capsys.readouterr() exp = yu.yloads(""" - pname: base basepath: . gitver: base-v0.1.0 history: - base-v0.1.0 - pname: foo basepath: foo_project gitver: history: [] """) assert exp == yu.yloads(out) rc = cli.run('status --all base foo'.split()) assert rc == 0 out, err = capsys.readouterr() assert exp == yu.yloads(out) rc = cli.run('status --all base foo BAD'.split()) assert rc == 0 out, err = capsys.readouterr() assert exp == yu.yloads(out) rc = cli.run('status --all BAD'.split()) assert rc == 0 out, err = capsys.readouterr() assert not out rc = cli.run('status --all foo BAD'.split()) assert rc == 0 exp = yu.yloads(""" - pname: foo basepath: foo_project gitver: history: [] """) out, err = capsys.readouterr() assert exp == yu.yloads(out)
def test_status_cmd_vtags(mutable_repo, caplog, capsys): mutable_repo.chdir() ############## ## setup.py + --monorepo # caplog.clear() make_setup_py(mutable_repo, 'simple') rc = cli.run('status --mono-project -v'.split()) assert rc == 0 check_text(caplog.text, require=[ "Auto-discovered 1 sub-project(s)", ], forbid=[ "Cannot auto-discover (sub-)project", "Cannot auto-discover versioning scheme," ]) out, err = capsys.readouterr() assert not err assert '- simple\n' == out rc = cli.run('status --mono-project --all'.split()) assert rc == 0 out, err = capsys.readouterr() assert '- pname: simple\n basepath: .\n gitver:\n history: []\n' == out ############## ## TAG REPO # caplog.clear() cmd.git.tag('v0.1.0', m='annotate!') rc = cli.run('status -v'.split()) assert rc == 0 check_text(caplog.text, require=[ "Auto-discovered 1 sub-project(s)", "Auto-discovered versioning scheme", ], forbid=[ "Cannot auto-discover (sub-)project", "Cannot auto-discover versioning scheme," ]) out, err = capsys.readouterr() assert not err assert ['v0.1.0'] == yu.yloads(out) rc = cli.run('status --all'.split()) assert rc == 0 out, err = capsys.readouterr() exp = [{ 'pname': 'simple', 'basepath': '.', 'gitver': 'v0.1.0', 'history': ['v0.1.0'] }] assert exp == yu.yloads(out) rc = cli.run('status --all simple'.split()) assert rc == 0 out, err = capsys.readouterr() assert exp == yu.yloads(out) rc = cli.run('status --all simple foobar'.split()) assert rc == 0 out, err = capsys.readouterr() assert exp == yu.yloads(out) rc = cli.run('status --all foobar'.split()) assert rc == 0 out, err = capsys.readouterr() assert not yu.yloads(out)
def test_init_cmd_mono_project(mutable_vtags_repo, caplog): mutable_vtags_repo.chdir() exp_fpath = (mutable_vtags_repo / '.polyvers.yaml') rc = cli.run('init --pdata f=g -v'.split()) assert rc == 0 assert osp.exists(exp_fpath) got = exp_fpath.read_text('utf-8') assert '############' not in got os.remove(exp_fpath) cfg = trc.Config() cfg.Project.pvtag_format = cfg.Project.pvtag_regex = 'some' cfg.PolyversCmd.pdata = {'foo': 'foo_path'} rc = cli.run('init --mono-project --doc -v'.split(), config=cfg) assert rc == 0 assert osp.exists(exp_fpath) got = exp_fpath.read_text('utf-8') #print(got) cleaned_text = '# Spec(LoggingConfigurable) configuration' assert cleaned_text not in got exp_hierarchy = tw.dedent("""\ # ############################################################################ # Configuration hierarchy for `polyvers`: # InitCmd --> _SubCmd # Project --> Spec # StatusCmd --> _SubCmd # BumpCmd --> _SubCmd # LogconfCmd --> _SubCmd # _SubCmd --> PolyversCmd # PolyversCmd --> Cmd # Cmd --> Application, Spec # Application\\s* # Engrave --> Spec # Graft --> Spec # Spec\\s* # ############################################################################ #""") assert re.search(exp_hierarchy, got) exp_headers = tw.dedent("""\ # ############################################################################ # Project(Spec) configuration # ############################################################################ # Configurations for projects, in general, and specifically for each one.""" ) assert exp_headers in got exp_help = tw.dedent("""\ # ############################################################################ # PolyversCmd(Cmd) configuration # ############################################################################ # Bump independently PEP-440 versions of sub-project in Git monorepos. # SYNTAX: # {cmd_chain} <sub-cmd> ... #""") assert exp_help in got exp_value = tw.dedent(r''' |- (?xmi) ^(?P<pname>) {vprefix}(?P<version>\d[^-]*) (?:-(?P<descid>\d+-g[a-f\d]+))?$''') check_text(got, exp_value) os.remove(exp_fpath) caplog.clear() cfg.Spec.dry_run = True rc = cli.run('init -v --dry-run'.split(), config=cfg) assert rc == 0 assert not osp.exists(exp_fpath) assert 'WARNING PRETEND init: ' in caplog.text check_text(caplog.text, exp_value)