Skip to content

Commit b2510d1

Browse files
d-chrisyozachar
andauthored
feat: adds doctest (#417)
* running `doctest` failes Fixes #416 * check docstring examples with pytest * changed line-length due doctest output - bsc_address.py:20:101: E501 Line too long (103 > 100) - all tox env passed * chore: ignore line lenght in specific docs * specifing testpath for pytest * fix: lint rule name * chore: update pytest in requirements file * chore: install module before pytest * fix: ru_inn docttest --------- Co-authored-by: Yozachar <[email protected]>
1 parent f7742c5 commit b2510d1

32 files changed

+155
-149
lines changed

.github/workflows/pycqa.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ jobs:
4848
cache: "pip"
4949
# testing
5050
- name: Install 'testing' dependencies
51-
run: pip install -r package/requirements.testing.txt
51+
run: |
52+
pip install -r package/requirements.testing.txt
53+
pip install .
5254
- name: Testing
5355
run: pytest .

package/requirements.testing.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ pycryptodome==3.20.0 \
4141
--hash=sha256:f35d6cee81fa145333137009d9c8ba90951d7d77b67c79cbe5f03c7eb74d8fe2 \
4242
--hash=sha256:f47888542a0633baff535a04726948e876bf1ed880fddb7c10a736fa99146ab3 \
4343
--hash=sha256:fb3b87461fa35afa19c971b0a2b7456a7b1db7b4eba9a8424666104925b78128
44-
pytest==8.2.2 \
45-
--hash=sha256:c434598117762e2bd304e526244f67bf66bbd7b5d6cf22138be51ff661980343 \
46-
--hash=sha256:de4bb8104e201939ccdc688b27a89a7be2079b22e2bd2b07f806b6ba71117977
44+
pytest==8.3.2 \
45+
--hash=sha256:4ba08f9ae7dcf84ded419494d229b48d0903ea6407b030eaec46df5e6a73bba5 \
46+
--hash=sha256:c132345d12ce551242c87269de812483f5bcc87cdbb4722e48487ba194f9fdce
4747
tomli==2.0.1; python_version < "3.11" \
4848
--hash=sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc \
4949
--hash=sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f

pyproject.toml

+4
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ pythonPlatform = "All"
126126
typeCheckingMode = "strict"
127127

128128
[tool.pytest.ini_options]
129+
minversion = "6.0"
129130
pythonpath = ["src"]
131+
testpaths = "tests"
132+
addopts = ["--doctest-modules"]
133+
130134

131135
[tool.ruff]
132136
lint.select = [

src/validators/_extremes.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ class AbsMax:
1212
Inspired by https://pypi.python.org/pypi/Extremes.
1313
1414
Examples:
15-
>>> from sys import maxint
16-
>>> AbsMax > AbsMin
17-
# Output: True
18-
>>> AbsMax > maxint
19-
# Output: True
20-
>>> AbsMax > 99999999999999999
21-
# Output: True
15+
>>> from sys import maxsize
16+
>>> AbsMax() > AbsMin()
17+
True
18+
>>> AbsMax() > maxsize
19+
True
20+
>>> AbsMax() > 99999999999999999
21+
True
2222
"""
2323

2424
def __ge__(self, other: Any):
@@ -33,13 +33,13 @@ class AbsMin:
3333
Inspired by https://pypi.python.org/pypi/Extremes.
3434
3535
Examples:
36-
>>> from sys import maxint
37-
>>> AbsMin < -maxint
38-
# Output: True
39-
>>> AbsMin < None
40-
# Output: True
41-
>>> AbsMin < ''
42-
# Output: True
36+
>>> from sys import maxsize
37+
>>> AbsMin() < -maxsize
38+
True
39+
>>> AbsMin() < None
40+
True
41+
>>> AbsMin() < ''
42+
True
4343
"""
4444

4545
def __le__(self, other: Any):

src/validators/between.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ def between(
2929
Examples:
3030
>>> from datetime import datetime
3131
>>> between(5, min_val=2)
32-
# Output: True
32+
True
3333
>>> between(13.2, min_val=13, max_val=14)
34-
# Output: True
34+
True
3535
>>> between(500, max_val=400)
36-
# Output: ValidationError(func=between, args=...)
36+
ValidationError(func=between, args={'value': 500, 'max_val': 400})
3737
>>> between(
3838
... datetime(2000, 11, 11),
3939
... min_val=datetime(1999, 11, 11)
4040
... )
41-
# Output: True
41+
True
4242
4343
Args:
4444
value:

src/validators/card.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ def card_number(value: str, /):
1717
1818
Examples:
1919
>>> card_number('4242424242424242')
20-
# Output: True
20+
True
2121
>>> card_number('4242424242424241')
22-
# Output: ValidationError(func=card_number, args={'value': '4242424242424241'})
22+
ValidationError(func=card_number, args={'value': '4242424242424241'})
2323
2424
Args:
2525
value:
@@ -46,9 +46,9 @@ def visa(value: str, /):
4646
4747
Examples:
4848
>>> visa('4242424242424242')
49-
# Output: True
49+
True
5050
>>> visa('2223003122003222')
51-
# Output: ValidationError(func=visa, args={'value': '2223003122003222'})
51+
ValidationError(func=visa, args={'value': '2223003122003222'})
5252
5353
Args:
5454
value:
@@ -68,9 +68,9 @@ def mastercard(value: str, /):
6868
6969
Examples:
7070
>>> mastercard('5555555555554444')
71-
# Output: True
71+
True
7272
>>> mastercard('4242424242424242')
73-
# Output: ValidationError(func=mastercard, args={'value': '4242424242424242'})
73+
ValidationError(func=mastercard, args={'value': '4242424242424242'})
7474
7575
Args:
7676
value:
@@ -90,9 +90,9 @@ def amex(value: str, /):
9090
9191
Examples:
9292
>>> amex('378282246310005')
93-
# Output: True
93+
True
9494
>>> amex('4242424242424242')
95-
# Output: ValidationError(func=amex, args={'value': '4242424242424242'})
95+
ValidationError(func=amex, args={'value': '4242424242424242'})
9696
9797
Args:
9898
value:
@@ -112,9 +112,9 @@ def unionpay(value: str, /):
112112
113113
Examples:
114114
>>> unionpay('6200000000000005')
115-
# Output: True
115+
True
116116
>>> unionpay('4242424242424242')
117-
# Output: ValidationError(func=unionpay, args={'value': '4242424242424242'})
117+
ValidationError(func=unionpay, args={'value': '4242424242424242'})
118118
119119
Args:
120120
value:
@@ -134,9 +134,9 @@ def diners(value: str, /):
134134
135135
Examples:
136136
>>> diners('3056930009020004')
137-
# Output: True
137+
True
138138
>>> diners('4242424242424242')
139-
# Output: ValidationError(func=diners, args={'value': '4242424242424242'})
139+
ValidationError(func=diners, args={'value': '4242424242424242'})
140140
141141
Args:
142142
value:
@@ -156,9 +156,9 @@ def jcb(value: str, /):
156156
157157
Examples:
158158
>>> jcb('3566002020360505')
159-
# Output: True
159+
True
160160
>>> jcb('4242424242424242')
161-
# Output: ValidationError(func=jcb, args={'value': '4242424242424242'})
161+
ValidationError(func=jcb, args={'value': '4242424242424242'})
162162
163163
Args:
164164
value:
@@ -178,9 +178,9 @@ def discover(value: str, /):
178178
179179
Examples:
180180
>>> discover('6011111111111117')
181-
# Output: True
181+
True
182182
>>> discover('4242424242424242')
183-
# Output: ValidationError(func=discover, args={'value': '4242424242424242'})
183+
ValidationError(func=discover, args={'value': '4242424242424242'})
184184
185185
Args:
186186
value:

src/validators/country.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ def calling_code(value: str, /):
245245
246246
Examples:
247247
>>> calling_code('+91')
248-
# Output: True
248+
True
249249
>>> calling_code('-31')
250-
# Output: ValidationError(func=calling_code, args={'value': '-31'})
250+
ValidationError(func=calling_code, args={'value': '-31'})
251251
252252
Args:
253253
value:
@@ -273,15 +273,15 @@ def country_code(value: str, /, *, iso_format: str = "auto", ignore_case: bool =
273273
274274
Examples:
275275
>>> country_code('GB', iso_format='alpha3')
276-
# Output: False
276+
ValidationError(func=country_code, args={'value': 'GB', 'iso_format': 'alpha3'})
277277
>>> country_code('USA')
278-
# Output: True
278+
True
279279
>>> country_code('840', iso_format='numeric')
280-
# Output: True
280+
True
281281
>>> country_code('iN', iso_format='alpha2')
282-
# Output: False
282+
ValidationError(func=country_code, args={'value': 'iN', 'iso_format': 'alpha2'})
283283
>>> country_code('ZWE', iso_format='alpha3')
284-
# Output: True
284+
True
285285
286286
Args:
287287
value:
@@ -327,9 +327,9 @@ def currency(value: str, /, *, skip_symbols: bool = True, ignore_case: bool = Fa
327327
328328
Examples:
329329
>>> currency('USD')
330-
# Output: True
330+
True
331331
>>> currency('ZWX')
332-
# Output: ValidationError(func=currency, args={'value': 'ZWX'})
332+
ValidationError(func=currency, args={'value': 'ZWX'})
333333
334334
Args:
335335
value:

src/validators/cron.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ def cron(value: str, /):
4444
4545
Examples:
4646
>>> cron('*/5 * * * *')
47-
# Output: True
47+
True
4848
>>> cron('30-20 * * * *')
49-
# Output: ValidationError(func=cron, ...)
49+
ValidationError(func=cron, args={'value': '30-20 * * * *'})
5050
5151
Args:
5252
value:

src/validators/crypto_addresses/bsc_address.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def bsc_address(value: str, /):
1515
1616
Examples:
1717
>>> bsc_address('0x4e5acf9684652BEa56F2f01b7101a225Ee33d23f')
18-
# Output: True
18+
True
1919
>>> bsc_address('0x4g5acf9684652BEa56F2f01b7101a225Eh33d23z')
20-
# Output: ValidationError(func=bsc_address, args=...)
20+
ValidationError(func=bsc_address, args={'value': '0x4g5acf9684652BEa56F2f01b7101a225Eh33d23z'})
2121
2222
Args:
2323
value:
@@ -26,7 +26,7 @@ def bsc_address(value: str, /):
2626
Returns:
2727
(Literal[True]): If `value` is a valid bsc address.
2828
(ValidationError): If `value` is an invalid bsc address.
29-
"""
29+
""" # noqa: E501
3030
if not value:
3131
return False
3232

src/validators/crypto_addresses/btc_address.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def btc_address(value: str, /):
3333
3434
Examples:
3535
>>> btc_address('3Cwgr2g7vsi1bXDUkpEnVoRLA9w4FZfC69')
36-
# Output: True
36+
True
3737
>>> btc_address('1BvBMsEYstWetqTFn5Au4m4GFg7xJaNVN2')
38-
# Output: ValidationError(func=btc_address, args=...)
38+
ValidationError(func=btc_address, args={'value': '1BvBMsEYstWetqTFn5Au4m4GFg7xJaNVN2'})
3939
4040
Args:
4141
value:

src/validators/crypto_addresses/eth_address.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def eth_address(value: str, /):
3838
3939
Examples:
4040
>>> eth_address('0x9cc14ba4f9f68ca159ea4ebf2c292a808aaeb598')
41-
# Output: True
41+
True
4242
>>> eth_address('0x8Ba1f109551bD432803012645Ac136ddd64DBa72')
43-
# Output: ValidationError(func=eth_address, args=...)
43+
ValidationError(func=eth_address, args={'value': '0x8Ba1f109551bD432803012645Ac136ddd64DBa72'})
4444
4545
Args:
4646
value:
@@ -49,7 +49,7 @@ def eth_address(value: str, /):
4949
Returns:
5050
(Literal[True]): If `value` is a valid ethereum address.
5151
(ValidationError): If `value` is an invalid ethereum address.
52-
"""
52+
""" # noqa: E501
5353
if not _keccak_flag:
5454
raise ImportError(
5555
"Do `pip install validators[crypto-eth-addresses]` to perform `eth_address` validation."

src/validators/crypto_addresses/trx_address.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def trx_address(value: str, /):
4242
4343
Examples:
4444
>>> trx_address('TLjfbTbpZYDQ4EoA4N5CLNgGjfbF8ZWz38')
45-
# Output: True
45+
True
4646
>>> trx_address('TR2G7Rm4vFqF8EpY4U5xdLdQ7XgJ2U8Vd')
47-
# Output: ValidationError(func=trx_address, args=...)
47+
ValidationError(func=trx_address, args={'value': 'TR2G7Rm4vFqF8EpY4U5xdLdQ7XgJ2U8Vd'})
4848
4949
Args:
5050
value:

src/validators/domain.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ def domain(
4545
4646
Examples:
4747
>>> domain('example.com')
48-
# Output: True
48+
True
4949
>>> domain('example.com/')
50-
# Output: ValidationError(func=domain, ...)
50+
ValidationError(func=domain, args={'value': 'example.com/'})
5151
>>> # Supports IDN domains as well::
5252
>>> domain('xn----gtbspbbmkef.xn--p1ai')
53-
# Output: True
53+
True
5454
5555
Args:
5656
value:

src/validators/email.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def email(
3131
3232
Examples:
3333
>>> email('[email protected]')
34-
# Output: True
34+
True
3535
>>> email('bogus@@')
36-
# Output: ValidationError(email=email, args={'value': 'bogus@@'})
36+
ValidationError(func=email, args={'value': 'bogus@@'})
3737
3838
Args:
3939
value:

src/validators/encoding.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ def base16(value: str, /):
1313
1414
Examples:
1515
>>> base16('a3f4b2')
16-
# Output: True
16+
True
1717
>>> base16('a3f4Z1')
18-
# Output: ValidationError(func=base16, args={'value': 'a3f4Z1'})
18+
ValidationError(func=base16, args={'value': 'a3f4Z1'})
1919
2020
Args:
2121
value:
@@ -34,9 +34,9 @@ def base32(value: str, /):
3434
3535
Examples:
3636
>>> base32('MFZWIZLTOQ======')
37-
# Output: True
37+
True
3838
>>> base32('MfZW3zLT9Q======')
39-
# Output: ValidationError(func=base32, args={'value': 'MfZW3zLT9Q======'})
39+
ValidationError(func=base32, args={'value': 'MfZW3zLT9Q======'})
4040
4141
Args:
4242
value:
@@ -55,9 +55,9 @@ def base58(value: str, /):
5555
5656
Examples:
5757
>>> base58('14pq6y9H2DLGahPsM4s7ugsNSD2uxpHsJx')
58-
# Output: True
58+
True
5959
>>> base58('cUSECm5YzcXJwP')
60-
# Output: ValidationError(func=base58, args={'value': 'cUSECm5YzcXJwP'})
60+
True
6161
6262
Args:
6363
value:
@@ -76,9 +76,9 @@ def base64(value: str, /):
7676
7777
Examples:
7878
>>> base64('Y2hhcmFjdGVyIHNldA==')
79-
# Output: True
79+
True
8080
>>> base64('cUSECm5YzcXJwP')
81-
# Output: ValidationError(func=base64, args={'value': 'cUSECm5YzcXJwP'})
81+
ValidationError(func=base64, args={'value': 'cUSECm5YzcXJwP'})
8282
8383
Args:
8484
value:

0 commit comments

Comments
 (0)