Skip to content

Commit d9c3fb6

Browse files
committed
docs: touch up the docs; finish defining a test
links to `unittest.mock` and `dicom_echo.Counter` now resolve correctly Signed-off-by: Bryant Finney <[email protected]>
1 parent 6d57d1a commit d9c3fb6

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ cmd = """
723723
typer
724724
typing
725725
unittest
726+
unittest.mock
726727
--docformat google
727728
--footer "$PACKAGE_VERSION"
728729
--mermaid

src/dicom_echo/__init__.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,22 @@
1616
from __future__ import annotations
1717

1818
import sys
19+
from typing import Literal
1920

2021
if not sys.argv[0].endswith('pdoc'):
2122
from dicom_echo.backend import ( # pylint: disable=no-name-in-module
2223
DEFAULT_CALLED_AE_TITLE,
2324
DEFAULT_CALLING_AE_TITLE,
2425
)
2526
from dicom_echo.backend import send as __send # pylint: disable=no-name-in-module
26-
else:
27-
DEFAULT_CALLED_AE_TITLE = 'ANY-SCP' # pyright: ignore[reportConstantRedefinition]
28-
DEFAULT_CALLING_AE_TITLE = 'ECHOSCU' # pyright: ignore[reportConstantRedefinition]
27+
else: # pragma: no cover
28+
# copy `backend.pyi` contents so the documentation can be built without cargo
29+
30+
DEFAULT_CALLED_AE_TITLE: Literal['ANY-SCP'] = 'ANY-SCP' # type: ignore[no-redef]
31+
"""By default, specify this AE title for the target SCP."""
32+
33+
DEFAULT_CALLING_AE_TITLE: Literal['ECHOSCU'] = 'ECHOSCU' # type: ignore[no-redef]
34+
"""By default, specify this AE title for the SCU sending the `C-ECHO` message."""
2935

3036
def __send(
3137
address: str,
@@ -41,7 +47,7 @@ def __send(
4147
return 0
4248

4349

44-
__all__ = ['DEFAULT_CALLED_AE_TITLE', 'DEFAULT_CALLING_AE_TITLE', 'send']
50+
__all__ = ['DEFAULT_CALLED_AE_TITLE', 'DEFAULT_CALLING_AE_TITLE', 'Counter', 'send']
4551

4652
__version__ = '0.0.0'
4753
__version_tuple__ = (0, 0, 0)
@@ -58,27 +64,22 @@ def increment(self) -> int:
5864
return self.count
5965

6066

61-
class Sentinel:
62-
"""Explicitly define a class for the sentinel object for type annotations."""
63-
64-
6567
counter = Counter()
66-
sentinel = Sentinel()
6768

6869

6970
def send(
7071
address: str,
7172
/,
7273
called_ae_title: str = DEFAULT_CALLED_AE_TITLE,
7374
calling_ae_title: str = DEFAULT_CALLING_AE_TITLE,
74-
message_id: int | Sentinel = sentinel,
75+
message_id: int | Counter = counter,
7576
) -> int:
7677
"""Send a `C-ECHO` message to the given address.
7778
78-
If `message_id` is not overwritten, a global counter will be incremented and passed.
79+
If `message_id` is not provided, a global counter will be incremented and passed.
7980
8081
Reference: [DICOM Standard Part 7, Section 9.1.5](https://www.dicomstandard.org/standards/view/message-exchange#sect_9.1.5)
8182
"""
82-
if isinstance(message_id, Sentinel):
83+
if isinstance(message_id, Counter):
8384
message_id = counter.increment()
8485
return __send(address, called_ae_title=called_ae_title, calling_ae_title=calling_ae_title, message_id=message_id)

tests/test_pycli.py

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from __future__ import annotations
44

5+
import subprocess
6+
import sys
57
from typing import TYPE_CHECKING
68

79
import rich.emoji
@@ -54,6 +56,10 @@ def test_version() -> None:
5456

5557
def test_version_called_as_module() -> None:
5658
"""Test the CLI output when the utility is invoked as a Python module."""
59+
out = subprocess.check_output([sys.executable, '-m', 'dicom_echo', '--version'], text=True)
60+
61+
assert 'dicom_echo' in out
62+
assert echo.__version__ in out
5763

5864

5965
def test_host_aetitle(mock_send_rc0: MagicMock) -> None:

0 commit comments

Comments
 (0)