Skip to content

Commit 030090b

Browse files
committed
Added doctest
1 parent df38c19 commit 030090b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/password_validator/password_validator.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import re
32

43
from . import lib
@@ -11,8 +10,10 @@ class PasswordValidator:
1110
Example:
1211
>>> schema = PasswordValidator()
1312
>>> schema.has().letters().has().digits().no().spaces()
13+
<src.password_validator.password_validator.PasswordValidator object at ...>
1414
>>> schema.validate('testPassword123')
1515
True
16+
1617
Returns:
1718
PasswordValidator: Schema object
1819
'''
@@ -30,6 +31,7 @@ def validate(self, pwd):
3031
False
3132
>>> PasswordValidator().letters().validate('abc')
3233
True
34+
3335
Args:
3436
pwd (str): Password to validate against the schema
3537
Returns:
@@ -63,6 +65,7 @@ def has(self, regexp=None):
6365
True
6466
>>> PasswordValidator().has(r'[a-z]+').validate('test')
6567
True
68+
6669
Args:
6770
regexp (str, optional): The regular expression or string to mandate on the password
6871
Returns:
@@ -107,6 +110,7 @@ def uppercase(self):
107110
True
108111
>>> PasswordValidator().uppercase().validate('test')
109112
False
113+
110114
Returns:
111115
PasswordValidator: Updated schema object
112116
'''
@@ -121,6 +125,7 @@ def lowercase(self):
121125
True
122126
>>> PasswordValidator().lowercase().validate('TEST')
123127
False
128+
124129
Returns:
125130
PasswordValidator: Updated schema object
126131
'''
@@ -136,6 +141,7 @@ def letters(self):
136141
True
137142
>>> PasswordValidator().no().letters().validate('test')
138143
False
144+
139145
Returns:
140146
PasswordValidator: Updated schema object
141147
'''
@@ -151,6 +157,7 @@ def digits(self):
151157
False
152158
>>> PasswordValidator().no().digits().validate('test123')
153159
False
160+
154161
Returns:
155162
PasswordValidator: Updated schema object
156163
'''
@@ -166,6 +173,7 @@ def min(self, length):
166173
True
167174
>>> PasswordValidator().min(8).validate('test')
168175
False
176+
169177
Args:
170178
length (int): Minimum length allowed
171179
Returns:
@@ -184,6 +192,7 @@ def max(self, length):
184192
False
185193
>>> PasswordValidator().max(8).validate('test')
186194
True
195+
187196
Args:
188197
length (int): Maximum length allowed
189198
Returns:
@@ -201,6 +210,7 @@ def spaces(self):
201210
True
202211
>>> PasswordValidator().no().spaces().validate('a bc')
203212
False
213+
204214
Returns:
205215
PasswordValidator: Updated schema object
206216
'''

tests/test_doctest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import unittest
2+
import doctest
3+
from src.password_validator import password_validator
4+
5+
def load_tests(loader, tests, ignore):
6+
tests.addTests(doctest.DocTestSuite(password_validator, optionflags=doctest.ELLIPSIS))
7+
return tests

0 commit comments

Comments
 (0)