Coverage for src/tests/core/domain/value_objects/test_date.py: 100%
33 statements
« prev ^ index » next coverage.py v7.11.0, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2024-01-01 00:00 +0000
1"""Module for testing the Date value object."""
3import datetime
5from kwai_core.domain.value_objects.date import Date
8def test_create_from_string():
9 """Test the factory method create_from_string."""
10 date = Date.create_from_string("1860-10-04")
11 assert str(date) == "1860-10-04"
14def test_create_with_year():
15 """Test the factory method create with only a year."""
16 date = Date.create(2024)
17 assert date.year == 2024
18 assert date.month == 1
19 assert date.day == 1
22def test_create():
23 """Test the factory method create with all arguments."""
24 date = Date.create(2024, 3, 9)
25 assert date.year == 2024
26 assert date.month == 3
27 assert date.day == 9
30def test_create_from_date():
31 """Test the factory method to create a date from datetime.date."""
32 date = Date.create_from_date(datetime.date.today())
33 assert date.year == datetime.date.today().year
34 assert date.month == datetime.date.today().month
35 assert date.day == datetime.date.today().day
38def test_day():
39 """Test the day property."""
40 date = Date.create_from_string("1860-10-04")
41 assert date.day == 4
44def test_month():
45 """Test the year property."""
46 date = Date.create_from_string("1860-10-04")
47 assert date.month == 10
50def test_year():
51 """Test the year property."""
52 date = Date.create_from_string("1860-10-04")
53 assert date.year == 1860
56def test_age():
57 """Test age method."""
58 birth_date = Date.create_from_string("1860-10-04")
59 date_of_death = Date.create_from_string("1938-05-04")
60 assert birth_date.get_age(date_of_death) == 77