-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
the `README`'s `doctest` now passes Signed-off-by: Bryant Finney <[email protected]>
- Loading branch information
1 parent
161e7d2
commit f08b9d8
Showing
8 changed files
with
223 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"""Load fixtures for the test suite.""" | ||
|
||
pytest_plugins = 'tests.fixtures' |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""The test suite for the `dicom_echo` package.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Define `pytest` fixtures for use throughout the `tests` package and `doctest` tests.""" | ||
|
||
from __future__ import annotations | ||
|
||
import socket | ||
import subprocess | ||
from typing import Iterator | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def dicom_storescp() -> str: | ||
"""Return the path to the `dicom-storescp` executable.""" | ||
import shutil | ||
|
||
if (dicom_storescp := shutil.which('dicom-storescp')) is None: | ||
pytest.skip('`dicom-storescp` not found. To install it, run `cargo install dicom-storescp`') | ||
|
||
return dicom_storescp | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def localhost() -> Iterator[tuple[str, int]]: | ||
"""Query the OS for the first available port; return the hostname of the socket as well.""" | ||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: | ||
sock.bind(('', 0)) | ||
host, port = sock.getsockname() | ||
sock.close() | ||
yield (host, port) | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def scpserver(dicom_storescp: str, localhost: tuple[str, int]) -> Iterator[str]: | ||
"""Start a DICOM SCP server for use with tests.""" | ||
host, port = localhost | ||
with subprocess.Popen([dicom_storescp, '-p', str(port)], text=True) as sub_proc: | ||
with pytest.raises(subprocess.TimeoutExpired): | ||
sub_proc.wait(timeout=0.01) | ||
|
||
assert None is sub_proc.returncode | ||
|
||
try: | ||
yield f'{host}:{port}' | ||
finally: | ||
sub_proc.terminate() |