Skip to content

Commit ca15844

Browse files
committed
Improve docs layout, and add example to itertools.count
1 parent 0313dae commit ca15844

File tree

8 files changed

+83
-21
lines changed

8 files changed

+83
-21
lines changed

doc-source/api/count_demo.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# stdlib
2+
import itertools
3+
4+
# this package
5+
import domdf_python_tools.iterative
6+
7+
print(domdf_python_tools.iterative.count(14.5, 0.1))
8+
9+
for val in zip(domdf_python_tools.iterative.count(14.5, 0.1), itertools.count(14.5, 0.1)):
10+
print(val)
11+
print(val[0] % 0.1, val[1] % 0.1)
12+
input(">>>")

doc-source/api/utils.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
:mod:`~domdf_python_tools.utils`
33
=================================
44

5-
.. autosummary-widths:: 7/16
5+
.. autosummary-widths:: 1/2
66
:html: 35/100
77

88
.. automodule:: domdf_python_tools.utils

doc-source/latex_unicode.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ def run(self) -> List[Node]:
258258
return nodes
259259

260260

261-
262261
class AutoUnitDirective(SphinxDirective):
263262
required_arguments = 1
264263

doc-source/requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
git+https://github.com/sphinx-toolbox/sphinx-toolbox-experimental.git
22
autodocsumm>=0.2.0
3-
default-values>=0.4.2
3+
default-values>=0.5.0
44
domdf-sphinx-theme>=0.3.0
55
extras-require>=0.2.0
66
pandas>=1.1.2
@@ -17,7 +17,7 @@ sphinx-notfound-page>=0.5
1717
sphinx-prompt>=1.1.0
1818
sphinx-pyproject>=0.1.0
1919
sphinx-tabs>=1.1.13
20-
sphinx-toolbox>=2.10.0
20+
sphinx-toolbox>=2.13.0b3
2121
sphinxcontrib-httpdomain>=1.7.0
2222
sphinxemoji>=0.1.6
23-
toctree-plus>=0.1.0
23+
toctree-plus>=0.5.0

domdf_python_tools/iterative.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,12 @@ def count(start: AnyNum = 0, step: AnyNum = 1) -> Iterator[AnyNum]:
447447
448448
:func:`itertools.count`.
449449
450-
The difference is that this returns more exact floats, whereas the values from :func:`itertools.count` drift.
450+
The difference is that this returns more exact floats,
451+
whereas the values from :func:`itertools.count` drift.
452+
453+
.. only:: html
454+
455+
A demonstration of the drift can be seen in this file: :download:`count_demo.py`.
451456
452457
.. latex:clearpage::
453458
"""

domdf_python_tools/paths.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,13 @@ def copytree(
150150
"""
151151
Alternative to :func:`shutil.copytree` to support copying to a directory that already exists.
152152
153-
Based on https://stackoverflow.com/a/12514470/3092681 by https://stackoverflow.com/users/23252/atzz
153+
Based on https://stackoverflow.com/a/12514470 by https://stackoverflow.com/users/23252/atzz
154154
155155
In Python 3.8 and above :func:`shutil.copytree` takes a ``dirs_exist_ok`` argument,
156156
which has the same result.
157157
158+
.. latex:clearpage::
159+
158160
:param src: Source file to copy
159161
:param dst: Destination to copy file to
160162
:param symlinks: Whether to represent symbolic links in the source as symbolic

domdf_python_tools/secrets.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ class Secret(str):
5252
True
5353
5454
.. versionadded:: 0.4.6
55+
5556
.. autosummary-widths:: 1/2
57+
:html: 2/10
5658
"""
5759

5860
__slots__ = ("value", )

tests/test_dates.py

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313

1414
# 3rd party
1515
import pytest
16-
from coincidence import count
16+
from coincidence.params import count
1717

1818
# this package
1919
from domdf_python_tools import dates
20-
from domdf_python_tools.dates import calc_easter, month_full_names
2120

2221
# TODO: test get_timezone
2322

@@ -159,25 +158,68 @@ def test_utc_offset_no_pytz():
159158

160159
# TODO: Finish
161160

161+
# import sys
162+
# from importlib.abc import MetaPathFinder
163+
#
164+
# class NoPytzPath(MetaPathFinder):
165+
#
166+
# def find_spec(self, fullname, path, target=None):
167+
# if fullname == "pytz":
168+
# raise ModuleNotFoundError(f"No module named '{fullname}'")
169+
#
170+
#
171+
# class TestDatesNoPytz:
172+
#
173+
# def test_import_pytz(self, fake_no_pytz):
174+
# with pytest.raises(ImportError):
175+
# import pytz
176+
# # this package
177+
# from domdf_python_tools import dates
178+
#
179+
# with pytest.raises(ImportError):
180+
# # 3rd party
181+
# import pytz
182+
#
183+
# def test_utc_offset_no_pytz(self, fake_no_pytz):
184+
# # this package
185+
# from domdf_python_tools import dates
186+
#
187+
# print(sys.modules.keys())
188+
#
189+
# with pytest.raises(
190+
# ImportError,
191+
# match=r"'get_utc_offset' requires pytz \(.*\), but it could not be imported",
192+
# ):
193+
# dates.get_utc_offset # pylint: disable=pointless-statement
194+
#
195+
# with pytest.raises(
196+
# ImportError,
197+
# match=r"'get_utc_offset' requires pytz \(.*\), but it could not be imported",
198+
# ):
199+
#
200+
# # this package
201+
# from domdf_python_tools.dates import get_utc_offset # noqa: F401
202+
203+
204+
@pytest.mark.parametrize("month_idx, month", enumerate(dates.month_full_names))
205+
def test_parse_month(month_idx: int, month: str):
206+
month_idx += 1 # to make 1-indexed
162207

163-
def test_parse_month():
164-
for month_idx, month in enumerate(month_full_names):
165-
166-
month_idx += 1 # to make 1-indexed
208+
for i in range(3, len(month)):
209+
assert dates.parse_month(month.lower()[:i]) == month
210+
assert dates.parse_month(month.upper()[:i]) == month
211+
assert dates.parse_month(month.capitalize()[:i]) == month
167212

168-
for i in range(3, len(month)):
169-
assert dates.parse_month(month.lower()[:i]) == month
170-
assert dates.parse_month(month.upper()[:i]) == month
171-
assert dates.parse_month(month.capitalize()[:i]) == month
213+
assert dates.parse_month(month_idx) == month
172214

173-
assert dates.parse_month(month_idx) == month
174215

216+
def test_parse_month_errors():
175217
for value in ["abc", 0, '0', -1, "-1", 13, "13"]:
176218
with pytest.raises(ValueError, match=fr"The given month \({value!r}\) is not recognised."):
177219
dates.parse_month(value) # type: ignore
178220

179221

180-
@pytest.mark.parametrize("month_idx, month", enumerate(month_full_names))
222+
@pytest.mark.parametrize("month_idx, month", enumerate(dates.month_full_names))
181223
def test_get_month_number_from_name(month_idx: int, month: str):
182224
month_idx += 1 # to make 1-indexed
183225

@@ -212,7 +254,7 @@ def test_get_month_number_errors(value: Union[str, int], match: str):
212254

213255

214256
def test_check_date():
215-
for month_idx, month in enumerate(month_full_names):
257+
for month_idx, month in enumerate(dates.month_full_names):
216258

217259
month_idx += 1 # to make 1-indexed
218260

@@ -282,4 +324,4 @@ def test_check_date():
282324
]
283325
)
284326
def test_calc_easter(date):
285-
assert calc_easter(date.year) == date
327+
assert dates.calc_easter(date.year) == date

0 commit comments

Comments
 (0)