test & doc: Check that the doc examples' output matches
This commit is contained in:
parent
8e26d7846c
commit
92c64d77b3
10 changed files with 30 additions and 10 deletions
1
docs/developer-guides/check-date-leap.py.exp
Normal file
1
docs/developer-guides/check-date-leap.py.exp
Normal file
|
|
@ -0,0 +1 @@
|
|||
2016-12-31 has a leap second!
|
||||
3
docs/developer-guides/check-date-leap.py.exp.license
Normal file
3
docs/developer-guides/check-date-leap.py.exp.license
Normal 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.
|
||||
|
|
@ -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
|
||||
|
|
|
|||
1
docs/developer-guides/convert-tai-to-utc.py.exp
Normal file
1
docs/developer-guides/convert-tai-to-utc.py.exp
Normal file
|
|
@ -0,0 +1 @@
|
|||
2024-07-18T22:00:00+00:00
|
||||
3
docs/developer-guides/convert-tai-to-utc.py.exp.license
Normal file
3
docs/developer-guides/convert-tai-to-utc.py.exp.license
Normal 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.
|
||||
1
docs/developer-guides/convert-utc-to-tai.py.exp
Normal file
1
docs/developer-guides/convert-utc-to-tai.py.exp
Normal file
|
|
@ -0,0 +1 @@
|
|||
2024-07-18T22:00:37+00:00
|
||||
3
docs/developer-guides/convert-utc-to-tai.py.exp.license
Normal file
3
docs/developer-guides/convert-utc-to-tai.py.exp.license
Normal 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.
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue