def test_no_scm(_): with conftest.capture_output() as logged: fmt = "branch(a,b):{major}.{minor}.{patch}{post} !{.$*FOO*}.{$BAR1*:}{$*BAR2:}{$BAZ:z}{dirty}" meta = new_meta(fmt) versioning = meta.versioning assert "project not under a supported SCM" in logged assert versioning.enabled assert versioning.problem == "project not under a supported SCM" assert meta.version == "0.0.0" assert versioning.strategy assert versioning.strategy.branches == ["a", "b"] assert not versioning.strategy.problem assert str(versioning.strategy) == fmt assert "BAZ:z" in str(versioning.strategy.extra_bits) check_render(versioning, "1.0.0.z") check_render(versioning, "1.0.0.post2.z", distance=2) check_render(versioning, "1.0.0.post2.z.dirty", distance=2, dirty=True) os.environ["TEST_FOO1"] = "bar" os.environ["TEST_FOO2"] = "baz" check_render(versioning, "1.0.0.post2.bar.z.dirty", distance=2, dirty=True) del os.environ["TEST_FOO1"] del os.environ["TEST_FOO2"] with pytest.raises(setupmeta.UsageError): versioning.bump("patch")
def test_invalid_part(): with conftest.capture_output() as logged: versioning = dict(foo="bar", main="{foo}.{major}.{minor}{", extra=extra_version, separator="-") meta = new_meta(versioning, scm=conftest.MockGit()) versioning = meta.versioning assert "invalid" in str(versioning.strategy.main_bits) assert meta.version is None assert versioning.problem == "invalid versioning part 'foo'" assert str( versioning.strategy ) == "branch(master):{foo}.{major}.{minor}{-function 'extra_version'" check_render(versioning, "invalid.1.0") check_render(versioning, "invalid.1.0-d2", distance=2) check_render(versioning, "invalid.1.0-extra", distance=2, dirty=True) assert "Ignored fields for 'versioning': {'foo': 'bar'}" in logged with pytest.raises(setupmeta.UsageError): versioning.bump("minor") with pytest.raises(setupmeta.UsageError): versioning.get_bump("minor")
def check_strategy_distance(dirty): meta = new_meta("distance", scm=conftest.MockGit(dirty)) versioning = meta.versioning assert versioning.enabled assert not versioning.problem assert not versioning.strategy.problem assert "major" in str(versioning.strategy.main_bits) assert "commitid" in str(versioning.strategy.extra_bits) assert str(versioning.strategy ) == "branch(master):{major}.{minor}.{distance}+{commitid}" if dirty: assert meta.version == "0.1.3+g123" with pytest.raises(setupmeta.UsageError): # Can't effectively bump if checkout is dirty versioning.bump("minor", commit=True) else: assert meta.version == "0.1.3" with pytest.raises(setupmeta.UsageError): # Can't bump 'patch' with 'distance' format versioning.bump("patch") check_bump(versioning)
def test_no_scm(_): fmt = "branch(a,b):{major}.{minor}.{patch}{post} !{.$*FOO*}.{$BAR1*:}{$*BAR2:}{$BAZ:z}{dirty}" meta = new_meta(fmt) versioning = meta.versioning assert versioning.enabled assert versioning.problem == "project not under a supported SCM" assert meta.version == '0.0.0' assert versioning.strategy assert versioning.strategy.branches == ['a', 'b'] assert not versioning.strategy.problem assert str(versioning.strategy) == fmt assert 'BAZ:z' in str(versioning.strategy.extra_bits) check_render(versioning, '1.0.0.z') check_render(versioning, '1.0.0.post2.z', distance=2) check_render(versioning, '1.0.0.post2.z.dirty', distance=2, dirty=True) os.environ['TEST_FOO1'] = 'bar' os.environ['TEST_FOO2'] = 'baz' check_render(versioning, '1.0.0.post2.bar.z.dirty', distance=2, dirty=True) del os.environ['TEST_FOO1'] del os.environ['TEST_FOO2'] with pytest.raises(setupmeta.UsageError): versioning.bump('patch')
def test_disabled(): meta = new_meta(False) versioning = meta.versioning assert not versioning.enabled assert versioning.problem == "setupmeta versioning not enabled" with pytest.raises(Exception): versioning.bump("major", commit=False)
def test_bump_patch(): with conftest.capture_output() as logged: meta = new_meta("post", scm=conftest.MockGit(False, describe="v0.1.2.rc-5-g123")) versioning = meta.versioning versioning.bump("patch") assert "Would run: git tag -a v0.1.3" in logged assert "Not committing" in logged assert "Not pushing" in logged
def test_invalid_main(): meta = new_meta(dict(main=extra_version, extra='', separator=' '), scm=conftest.MockGit()) versioning = meta.versioning assert str(versioning.strategy) == "branch(master):function 'extra_version' " check_render(versioning, '') check_render(versioning, 'd2', distance=2) check_render(versioning, 'extra', distance=2, dirty=True) with pytest.raises(setupmeta.UsageError): versioning.bump('minor')
def test_missing_tags(): with conftest.capture_output() as logged: meta = new_meta("distance", scm=conftest.MockGit(False, local_tags="v1.0\nv1.1", remote_tags="v1.0\nv2.0")) versioning = meta.versioning assert versioning.enabled assert not versioning.problem assert not versioning.strategy.problem with pytest.raises(setupmeta.UsageError): # Can't effectively bump when remote tags are not all present locally versioning.bump("minor", commit=True) assert "patch version component should be .0" in logged
def test_invalid_main(): with conftest.capture_output() as logged: meta = new_meta(dict(main=extra_version, extra="", separator=" "), scm=conftest.MockGit()) versioning = meta.versioning assert str(versioning.strategy) == "branch(master):function 'extra_version' " check_render(versioning, "") check_render(versioning, "d2", distance=2) check_render(versioning, "extra", distance=2, dirty=True) with pytest.raises(setupmeta.UsageError): versioning.bump("minor") assert "you have pending changes" in logged
def test_invalid_part(): versioning = dict(foo='bar', main='{foo}.{major}.{minor}{', extra=extra_version, separator='-',) meta = new_meta(versioning, scm=conftest.MockGit()) versioning = meta.versioning assert 'invalid' in str(versioning.strategy.main_bits) assert meta.version is None assert versioning.problem == "invalid versioning part 'foo'" assert str(versioning.strategy) == "branch(master):{foo}.{major}.{minor}{-function 'extra_version'" check_render(versioning, 'invalid.1.0') check_render(versioning, 'invalid.1.0-d2', distance=2) check_render(versioning, 'invalid.1.0-extra', distance=2, dirty=True) with pytest.raises(setupmeta.UsageError): versioning.bump('minor')
def check_strategy_build_id(dirty): meta = new_meta("build-id", scm=conftest.MockGit(dirty)) versioning = meta.versioning assert versioning.enabled assert not versioning.problem assert not versioning.strategy.problem assert "major" in str(versioning.strategy.main_bits) assert "commitid" in str(versioning.strategy.extra_bits) assert str(versioning.strategy) == "branch(master):{major}.{minor}.{distance}+!h{$*BUILD_ID:local}.{commitid}{dirty}" if dirty: assert meta.version == "0.1.3+h543.g123.dirty" with pytest.raises(setupmeta.UsageError): # Can't effectively bump when checkout is dirty versioning.bump("minor", commit=True) else: assert meta.version == "0.1.3+h543.g123" check_bump(versioning)
def check_bump(versioning): with conftest.capture_output() as out: versioning.bump("major") assert "Not committing bump, use --commit to commit" in out assert 'git tag -a v1.0.0 -m "Version 1.0.0"' in out with conftest.capture_output() as out: versioning.bump("minor", push=True) assert "Not committing bump, use --commit to commit" in out assert 'git tag -a v0.2.0 -m "Version 0.2.0"' in out assert "git push --tags origin" in out with pytest.raises(setupmeta.UsageError): versioning.bump("foo")