Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test__serialize_pep440():
assert serialize_pep440("1.2.3") == "1.2.3"
assert serialize_pep440("1.2.3", epoch=0) == "0!1.2.3"
assert serialize_pep440("1.2.3", stage="a") == "1.2.3a0"
assert serialize_pep440("1.2.3", stage="a", revision=4) == "1.2.3a4"
assert serialize_pep440("1.2.3", post=4) == "1.2.3.post4"
assert serialize_pep440("1.2.3", dev=4) == "1.2.3.dev4"
assert serialize_pep440("1.2.3", metadata=[]) == "1.2.3"
assert serialize_pep440("1.2.3", metadata=["foo"]) == "1.2.3+foo"
assert serialize_pep440("1.2.3", metadata=["foo", "bar"]) == "1.2.3+foo.bar"
assert serialize_pep440("1.2.3", metadata=[4]) == "1.2.3+4"
assert (
serialize_pep440(
"1.2.3", epoch=0, stage="a", revision=4, post=5, dev=6, metadata=["foo", "bar"]
)
== "0!1.2.3a4.post5.dev6+foo.bar"
)
with pytest.raises(ValueError):
serialize_pep440("foo")
def test__serialize_pep440():
assert serialize_pep440("1.2.3") == "1.2.3"
assert serialize_pep440("1.2.3", epoch=0) == "0!1.2.3"
assert serialize_pep440("1.2.3", stage="a") == "1.2.3a0"
assert serialize_pep440("1.2.3", stage="a", revision=4) == "1.2.3a4"
assert serialize_pep440("1.2.3", post=4) == "1.2.3.post4"
assert serialize_pep440("1.2.3", dev=4) == "1.2.3.dev4"
assert serialize_pep440("1.2.3", metadata=[]) == "1.2.3"
assert serialize_pep440("1.2.3", metadata=["foo"]) == "1.2.3+foo"
assert serialize_pep440("1.2.3", metadata=["foo", "bar"]) == "1.2.3+foo.bar"
assert serialize_pep440("1.2.3", metadata=[4]) == "1.2.3+4"
assert (
serialize_pep440(
"1.2.3", epoch=0, stage="a", revision=4, post=5, dev=6, metadata=["foo", "bar"]
)
== "0!1.2.3a4.post5.dev6+foo.bar"
)
def test__serialize_pep440():
assert serialize_pep440("1.2.3") == "1.2.3"
assert serialize_pep440("1.2.3", epoch=0) == "0!1.2.3"
assert serialize_pep440("1.2.3", stage="a") == "1.2.3a0"
assert serialize_pep440("1.2.3", stage="a", revision=4) == "1.2.3a4"
assert serialize_pep440("1.2.3", post=4) == "1.2.3.post4"
assert serialize_pep440("1.2.3", dev=4) == "1.2.3.dev4"
assert serialize_pep440("1.2.3", metadata=[]) == "1.2.3"
assert serialize_pep440("1.2.3", metadata=["foo"]) == "1.2.3+foo"
assert serialize_pep440("1.2.3", metadata=["foo", "bar"]) == "1.2.3+foo.bar"
assert serialize_pep440("1.2.3", metadata=[4]) == "1.2.3+4"
assert (
serialize_pep440(
"1.2.3", epoch=0, stage="a", revision=4, post=5, dev=6, metadata=["foo", "bar"]
)
== "0!1.2.3a4.post5.dev6+foo.bar"
)
def test__serialize_pep440():
assert serialize_pep440("1.2.3") == "1.2.3"
assert serialize_pep440("1.2.3", epoch=0) == "0!1.2.3"
assert serialize_pep440("1.2.3", stage="a") == "1.2.3a0"
assert serialize_pep440("1.2.3", stage="a", revision=4) == "1.2.3a4"
assert serialize_pep440("1.2.3", post=4) == "1.2.3.post4"
assert serialize_pep440("1.2.3", dev=4) == "1.2.3.dev4"
assert serialize_pep440("1.2.3", metadata=[]) == "1.2.3"
assert serialize_pep440("1.2.3", metadata=["foo"]) == "1.2.3+foo"
assert serialize_pep440("1.2.3", metadata=["foo", "bar"]) == "1.2.3+foo.bar"
assert serialize_pep440("1.2.3", metadata=[4]) == "1.2.3+4"
assert (
serialize_pep440(
"1.2.3", epoch=0, stage="a", revision=4, post=5, dev=6, metadata=["foo", "bar"]
)
== "0!1.2.3a4.post5.dev6+foo.bar"
)
with pytest.raises(ValueError):
def test__serialize_pep440():
assert serialize_pep440("1.2.3") == "1.2.3"
assert serialize_pep440("1.2.3", epoch=0) == "0!1.2.3"
assert serialize_pep440("1.2.3", stage="a") == "1.2.3a0"
assert serialize_pep440("1.2.3", stage="a", revision=4) == "1.2.3a4"
assert serialize_pep440("1.2.3", post=4) == "1.2.3.post4"
assert serialize_pep440("1.2.3", dev=4) == "1.2.3.dev4"
assert serialize_pep440("1.2.3", metadata=[]) == "1.2.3"
assert serialize_pep440("1.2.3", metadata=["foo"]) == "1.2.3+foo"
assert serialize_pep440("1.2.3", metadata=["foo", "bar"]) == "1.2.3+foo.bar"
assert serialize_pep440("1.2.3", metadata=[4]) == "1.2.3+4"
assert (
serialize_pep440(
"1.2.3", epoch=0, stage="a", revision=4, post=5, dev=6, metadata=["foo", "bar"]
)
== "0!1.2.3a4.post5.dev6+foo.bar"
)
with pytest.raises(ValueError):
serialize_pep440("foo")
def test__serialize_pep440():
assert serialize_pep440("1.2.3") == "1.2.3"
assert serialize_pep440("1.2.3", epoch=0) == "0!1.2.3"
assert serialize_pep440("1.2.3", stage="a") == "1.2.3a0"
assert serialize_pep440("1.2.3", stage="a", revision=4) == "1.2.3a4"
assert serialize_pep440("1.2.3", post=4) == "1.2.3.post4"
assert serialize_pep440("1.2.3", dev=4) == "1.2.3.dev4"
assert serialize_pep440("1.2.3", metadata=[]) == "1.2.3"
assert serialize_pep440("1.2.3", metadata=["foo"]) == "1.2.3+foo"
assert serialize_pep440("1.2.3", metadata=["foo", "bar"]) == "1.2.3+foo.bar"
assert serialize_pep440("1.2.3", metadata=[4]) == "1.2.3+4"
assert (
serialize_pep440(
"1.2.3", epoch=0, stage="a", revision=4, post=5, dev=6, metadata=["foo", "bar"]
)
== "0!1.2.3a4.post5.dev6+foo.bar"
)
with pytest.raises(ValueError):
serialize_pep440("foo")
assert serialize_pep440("1.2.3", post=4) == "1.2.3.post4"
assert serialize_pep440("1.2.3", dev=4) == "1.2.3.dev4"
assert serialize_pep440("1.2.3", metadata=[]) == "1.2.3"
assert serialize_pep440("1.2.3", metadata=["foo"]) == "1.2.3+foo"
assert serialize_pep440("1.2.3", metadata=["foo", "bar"]) == "1.2.3+foo.bar"
assert serialize_pep440("1.2.3", metadata=[4]) == "1.2.3+4"
assert (
serialize_pep440(
"1.2.3", epoch=0, stage="a", revision=4, post=5, dev=6, metadata=["foo", "bar"]
)
== "0!1.2.3a4.post5.dev6+foo.bar"
)
with pytest.raises(ValueError):
serialize_pep440("foo")
def test__serialize_pep440():
assert serialize_pep440("1.2.3") == "1.2.3"
assert serialize_pep440("1.2.3", epoch=0) == "0!1.2.3"
assert serialize_pep440("1.2.3", stage="a") == "1.2.3a0"
assert serialize_pep440("1.2.3", stage="a", revision=4) == "1.2.3a4"
assert serialize_pep440("1.2.3", post=4) == "1.2.3.post4"
assert serialize_pep440("1.2.3", dev=4) == "1.2.3.dev4"
assert serialize_pep440("1.2.3", metadata=[]) == "1.2.3"
assert serialize_pep440("1.2.3", metadata=["foo"]) == "1.2.3+foo"
assert serialize_pep440("1.2.3", metadata=["foo", "bar"]) == "1.2.3+foo.bar"
assert serialize_pep440("1.2.3", metadata=[4]) == "1.2.3+4"
assert (
serialize_pep440(
"1.2.3", epoch=0, stage="a", revision=4, post=5, dev=6, metadata=["foo", "bar"]
)
== "0!1.2.3a4.post5.dev6+foo.bar"
)
with pytest.raises(ValueError):
serialize_pep440("foo")
def test__serialize_pep440():
assert serialize_pep440("1.2.3") == "1.2.3"
assert serialize_pep440("1.2.3", epoch=0) == "0!1.2.3"
assert serialize_pep440("1.2.3", stage="a") == "1.2.3a0"
assert serialize_pep440("1.2.3", stage="a", revision=4) == "1.2.3a4"
assert serialize_pep440("1.2.3", post=4) == "1.2.3.post4"
assert serialize_pep440("1.2.3", dev=4) == "1.2.3.dev4"
assert serialize_pep440("1.2.3", metadata=[]) == "1.2.3"
assert serialize_pep440("1.2.3", metadata=["foo"]) == "1.2.3+foo"
assert serialize_pep440("1.2.3", metadata=["foo", "bar"]) == "1.2.3+foo.bar"
assert serialize_pep440("1.2.3", metadata=[4]) == "1.2.3+4"
assert (
serialize_pep440(
"1.2.3", epoch=0, stage="a", revision=4, post=5, dev=6, metadata=["foo", "bar"]
)
== "0!1.2.3a4.post5.dev6+foo.bar"
)
with pytest.raises(ValueError):
serialize_pep440("foo")
style = Style(style)
version = Version.from_vcs(
vcs, config["pattern"], config["latest-tag"], config["subversion"]["tag-dir"]
)
if config["format-jinja"]:
default_context = {
"base": version.base,
"stage": version.stage,
"revision": version.revision,
"distance": version.distance,
"commit": version.commit,
"dirty": version.dirty,
"env": os.environ,
"bump_version": bump_version,
"serialize_pep440": serialize_pep440,
"serialize_pvp": serialize_pvp,
"serialize_semver": serialize_semver,
}
custom_context = {} # type: dict
for entry in config["format-jinja-imports"]:
if "module" in entry:
module = import_module(entry["module"])
if "item" in entry:
custom_context[entry["item"]] = getattr(module, entry["item"])
else:
custom_context[entry["module"]] = module
serialized = jinja2.Template(config["format-jinja"]).render(
**default_context, **custom_context
)
if style is not None:
check_version(serialized, style)