Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Changelog

Versions follow `Semantic Versioning <http://www.semver.org>`_

`4.1.0`_ - 2026-10-25
---------------------
_`Unreleased`_
--------------
Changed
~~~~~~~
* Dropped support for Python 3.10.
Expand All @@ -15,6 +15,8 @@ Fixed
~~~~~
* The ``typing-extensions`` dependency is now also installed on Python 3.11, where it is required
for ``typing_extensions.override``.
* Print generated and converted values when using ``python -m ulid``, matching the
``ulid`` console command.

`4.0.1`_ - 2026-07-20
---------------------
Expand Down Expand Up @@ -276,7 +278,7 @@ Changed
* The package now has no external dependencies.
* The test-coverage has been raised to 100%.

.. _4.1.0: https://github.com/mdomke/python-ulid/compare/4.0.1...4.1.0
.. _Unreleased: https://github.com/mdomke/python-ulid/compare/4.0.1...main
.. _4.0.1: https://github.com/mdomke/python-ulid/compare/4.0.0...4.0.1
.. _4.0.0: https://github.com/mdomke/python-ulid/compare/3.2.1...4.0.0
.. _3.2.1: https://github.com/mdomke/python-ulid/compare/3.2.0...3.2.1
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ ulid = "ulid.__main__:entrypoint"
source = "vcs"

[tool.hatch.build.targets.wheel]
core-metadata-version = "2.4"
Comment thread
mdomke marked this conversation as resolved.
Resolved
packages = [
"ulid",
]
[tool.hatch.build.targets.sdist]
core-metadata-version = "2.4"
exclude = [
".flox",
]
Expand Down
49 changes: 49 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import subprocess
import sys

import pytest

import ulid.__main__ as cli
Expand Down Expand Up @@ -79,3 +82,49 @@ def test_build(option: str):
ulid_out = ULID.from_str(output)
if includes_timestamp:
assert ulid_out.datetime == ulid.datetime


@pytest.mark.parametrize(
("args", "stdin", "expected"),
[
(["build", "--from-int", "0"], None, "00000000000000000000000000\n"),
(["build", "--from-int", "-"], "0\n", "00000000000000000000000000\n"),
(["show", "--int", "00000000000000000000000000"], None, "0\n"),
(["show", "--int", "-"], "00000000000000000000000000\n", "0\n"),
],
)
def test_module_outputs_result(args: list[str], stdin: str | None, expected: str) -> None:
result = subprocess.run(
[sys.executable, "-m", "ulid", *args],
input=stdin,
capture_output=True,
text=True,
check=True,
timeout=10,
)
assert result.stdout == expected
assert result.stderr == ""


@pytest.mark.parametrize("args", [[], ["--help"]])
def test_module_help(args: list[str]) -> None:
result = subprocess.run(
[sys.executable, "-m", "ulid", *args],
capture_output=True,
text=True,
check=True,
timeout=10,
)
assert result.stdout.startswith("usage: python -m ulid")
assert not result.stdout.endswith("None\n")
assert result.stderr == ""


def test_console_entrypoint(
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
) -> None:
monkeypatch.setattr(sys, "argv", ["ulid", "build", "--from-int", "0"])
cli.entrypoint()
captured = capsys.readouterr()
assert captured.out == "00000000000000000000000000\n"
assert captured.err == ""
6 changes: 3 additions & 3 deletions ulid/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ def show(args: argparse.Namespace) -> str:
).strip()


def entrypoint() -> None: # pragma: no cover
if (value := main(sys.argv[1:])) is not None:
def entrypoint(prog: str | None = None) -> None: # pragma: no cover
if (value := main(sys.argv[1:], prog)) is not None:
print(value) # noqa: T201


if __name__ == "__main__": # pragma: no cover
main(sys.argv[1:], "python -m ulid")
entrypoint("python -m ulid")