1
1
import re
2
+ from datetime import date , datetime
2
3
3
4
import pytest
4
5
@@ -19,36 +20,31 @@ def test_str(self, person):
19
20
assert re .match (patterns .DATA_PROVIDER_STR_REGEX , str (person ))
20
21
21
22
@pytest .mark .parametrize (
22
- "minimum, maximum " ,
23
+ "min_year, max_year " ,
23
24
[
24
- (16 , 18 ),
25
- (18 , 21 ),
26
- (22 , 28 ),
25
+ (1900 , 1950 ),
26
+ (1951 , 2001 ),
27
+ (2001 , 2023 ),
27
28
],
28
29
)
29
- def test_age (self , _person , minimum , maximum ):
30
- result = _person .age (minimum , maximum )
31
- assert (result >= minimum ) and (result <= maximum )
30
+ def test_birthdate (self , _person , min_year , max_year ):
31
+ birthdate = _person .birthdate (min_year , max_year )
32
+ assert min_year <= birthdate .year <= max_year
33
+ assert isinstance (birthdate , date )
32
34
33
- def test_age_store (self , _person ):
34
- result = _person ._store ["age" ]
35
- assert result == 0
36
-
37
- def test_age_update (self , _person ):
38
- result = _person .age () - _person ._store ["age" ]
39
- assert result == 0
40
-
41
- def test_work_experience (self , _person ):
42
- result = _person .work_experience (working_start_age = 0 ) - _person ._store ["age" ]
43
- assert result == 0
44
-
45
- def test_work_experience_store (self , _person ):
46
- result = _person .work_experience () - _person .work_experience ()
47
- assert result == 0
35
+ @pytest .mark .parametrize (
36
+ "min_year, max_year" ,
37
+ [
38
+ (1899 , 1950 ),
39
+ (datetime .now ().year + 1 , datetime .now ().year + 3 ),
40
+ ],
41
+ )
42
+ def test_birthdate_with_invalid_params (self , _person , min_year , max_year ):
43
+ with pytest .raises (ValueError ):
44
+ _person .birthdate (min_year , max_year )
48
45
49
- def test_work_experience_extreme (self , _person ):
50
- result = _person .work_experience (working_start_age = 100000 )
51
- assert result == 0
46
+ def test_is_leap_year (self , _person ):
47
+ assert _person ._is_leap_year (2024 )
52
48
53
49
def test_password (self , _person ):
54
50
result = _person .password (length = 15 )
@@ -344,14 +340,6 @@ def p1(self, seed):
344
340
def p2 (self , seed ):
345
341
return Person (seed = seed )
346
342
347
- def test_age (self , p1 , p2 ):
348
- assert p1 .age () == p2 .age ()
349
- assert p1 .age (12 , 42 ) == p2 .age (12 , 42 )
350
-
351
- def test_work_experience (self , p1 , p2 ):
352
- assert p1 .work_experience () == p2 .work_experience ()
353
- assert p1 .work_experience (19 ) == p2 .work_experience (19 )
354
-
355
343
def test_password (self , p1 , p2 ):
356
344
assert p1 .password () == p2 .password ()
357
345
assert p1 .password (length = 12 , hashed = True ) == p2 .password (
@@ -413,6 +401,12 @@ def test_full_name(self, p1, p2):
413
401
def test_gender_code (self , p1 , p2 ):
414
402
assert p1 .gender_code () == p2 .gender_code ()
415
403
404
+ def test_birthdate (self , p1 , p2 ):
405
+ assert p1 .birthdate () == p2 .birthdate ()
406
+ assert p1 .birthdate (min_year = 1900 , max_year = 2023 ) == p2 .birthdate (
407
+ min_year = 1900 , max_year = 2023
408
+ )
409
+
416
410
def test_gender_symbol (self , p1 , p2 ):
417
411
assert p1 .gender_symbol () == p2 .gender_symbol ()
418
412
0 commit comments