diff --git a/README.rst b/README.rst index 8d66ffd5..b5f92163 100644 --- a/README.rst +++ b/README.rst @@ -17,21 +17,6 @@ This is tested on Python 3.12+. Usage ----- -.. invisible-code-block: python - - from mock_vws import MockVWS - from mock_vws.database import VuforiaDatabase - - mock = MockVWS(real_http=False) - database = VuforiaDatabase( - server_access_key='my_access_key', - server_secret_key='my_secret_key', - client_access_key='my_access_key', - client_secret_key='my_secret_key', - ) - mock.add_database(database=database) - mock.__enter__() - .. code-block:: python from urllib.parse import urljoin @@ -44,8 +29,8 @@ Usage method = 'GET' date = rfc_1123_date() authorization_header = authorization_header( - access_key='my_access_key', - secret_key='my_secret_key', + access_key='[server-access-key]', + secret_key='[server-secret-key]', method=method, content=content, content_type='', @@ -64,10 +49,6 @@ Usage assert response.status_code == 200, response.text -.. invisible-code-block: python - - mock.__exit__() - Full Documentation ------------------ diff --git a/conftest.py b/conftest.py index 4d4d8fb0..49995e9e 100644 --- a/conftest.py +++ b/conftest.py @@ -1,9 +1,12 @@ -"""Setup for Sybil.""" +"""Setup for test suite.""" +from collections.abc import Generator from doctest import ELLIPSIS import pytest from beartype import beartype +from mock_vws import MockVWS +from mock_vws.database import VuforiaDatabase from sybil import Sybil from sybil.parsers.rest import ( CaptureParser, @@ -11,6 +14,26 @@ PythonCodeBlockParser, ) + +@pytest.fixture +def mock_vws() -> Generator[None, None, None]: + """ + Yield a mock VWS. + + The keys used here match the keys in the documentation. + """ + database = VuforiaDatabase( + server_access_key="[server-access-key]", + server_secret_key="[server-secret-key]", + client_access_key="[client-access-key]", + client_secret_key="[client-secret-key]", + ) + # We use a low processing time so that tests run quickly. + with MockVWS(processing_time_seconds=0.2) as mock: + mock.add_database(database=database) + yield + + sybil_obj = Sybil( parsers=[ DocTestParser(optionflags=ELLIPSIS), @@ -18,6 +41,7 @@ CaptureParser(), ], patterns=["*.rst", "*.py"], + fixtures=["mock_vws"], ) pytest_collect_file = sybil_obj.pytest() diff --git a/docs/source/index.rst b/docs/source/index.rst index eb248dec..9f7e1a5e 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -13,21 +13,6 @@ This is tested on Python 3.12+. Example usage ------------- -.. invisible-code-block: python - - from mock_vws import MockVWS - from mock_vws.database import VuforiaDatabase - - mock = MockVWS(real_http=False) - database = VuforiaDatabase( - server_access_key='my_access_key', - server_secret_key='my_secret_key', - client_access_key='my_access_key', - client_secret_key='my_secret_key', - ) - mock.add_database(database=database) - mock.__enter__() - .. code-block:: python from urllib.parse import urljoin @@ -40,8 +25,8 @@ Example usage method = 'GET' date = rfc_1123_date() authorization_header = authorization_header( - access_key='my_access_key', - secret_key='my_secret_key', + access_key='[server-access-key]', + secret_key='[server-secret-key]', method=method, content=content, content_type='', @@ -60,10 +45,6 @@ Example usage assert response.status_code == 200, response.text -.. invisible-code-block: python - - mock.__exit__() - Reference --------- diff --git a/pyproject.toml b/pyproject.toml index 3484780c..d6091550 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -102,6 +102,11 @@ lint.ignore = [ "S101", ] +lint.per-file-ignores."conftest.py" = [ + # Allow hardcoded secrets in tests. + "S106", +] + # Do not automatically remove commented out code. # We comment out code during development, and with VSCode auto-save, this code # is sometimes annoyingly removed.