test & doc: Check that the doc examples' output matches

This commit is contained in:
Jeff Epler 2024-07-20 10:46:04 -05:00
parent 8e26d7846c
commit 92c64d77b3
10 changed files with 30 additions and 10 deletions

View file

@ -0,0 +1 @@
2016-12-31 has a leap second!

View file

@ -0,0 +1,3 @@
# SPDX-FileCopyrightText: 2024 Thomas Touhey
# SPDX-License-Identifier: Unlicense
# Placed in a separate file so that it does not appear in the produced docs.

View file

@ -16,6 +16,4 @@ second, you can use the following code:
The output of this program is the following:
.. code-block:: text
2016-12-31 has a leap second!
.. literalinclude:: check-date-leap.py.exp

View file

@ -0,0 +1 @@
2024-07-18T22:00:00+00:00

View file

@ -0,0 +1,3 @@
# SPDX-FileCopyrightText: 2024 Thomas Touhey
# SPDX-License-Identifier: Unlicense
# Placed in a separate file so that it does not appear in the produced docs.

View file

@ -0,0 +1 @@
2024-07-18T22:00:37+00:00

View file

@ -0,0 +1,3 @@
# SPDX-FileCopyrightText: 2024 Thomas Touhey
# SPDX-License-Identifier: Unlicense
# Placed in a separate file so that it does not appear in the produced docs.

View file

@ -17,6 +17,4 @@ For example:
This program will provide you with the following output:
.. code-block:: text
2024-07-18T22:00:00g+00:00
.. literalinclude:: convert-tai-to-utc.py.exp

View file

@ -17,6 +17,4 @@ For example:
This program will provide you with the following output:
.. code-block:: text
2024-07-18T22:00:37+00:00
.. literalinclude:: convert-utc-to-tai.py.exp

View file

@ -9,8 +9,10 @@
"""Test most leapseconddata functionality"""
# pylint: disable=missing-class-docstring,missing-function-docstring
import contextlib
import datetime
import io
import pathlib
import unittest
import leapseconddata
@ -132,6 +134,18 @@ class LeapSecondDataTest(unittest.TestCase):
assert when_tai.tzinfo is leapseconddata.tai
assert when_tai2.tzinfo is leapseconddata.tai
def assertPrints(self, code, expected): # noqa: N802
buf = io.StringIO()
with contextlib.redirect_stdout(buf):
exec(code, {}, {})
self.assertEqual(expected, buf.getvalue())
def test_doc(self):
docs = pathlib.Path(__file__).parent / "docs"
for expected in docs.rglob("**/*.py.exp"):
py = expected.with_suffix("") # Pop off the ".exp" suffix
self.assertPrints(py.read_text(encoding="utf-8"), expected.read_text(encoding="utf-8"))
if __name__ == "__main__": # pragma: no cover
unittest.main()