Coverage for src/tests/core/domain/value_objects/test_local_timestamp.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2024-01-01 00:00 +0000

1"""Module for testing LocalTimestamp.""" 

2 

3from kwai_core.domain.value_objects.timestamp import Timestamp 

4 

5 

6def test_create_now(): 

7 """Test the create_now factory method.""" 

8 timestamp = Timestamp.create_now() 

9 

10 assert timestamp is not None, "There should be a timestamp." 

11 

12 

13def test_add_delta(): 

14 """Test the add delta method.""" 

15 timestamp = Timestamp.create_now() 

16 new_timestamp = timestamp.add_delta(hours=1) 

17 

18 assert timestamp.timestamp.hour + 1 == new_timestamp.timestamp.hour, ( 

19 "The difference in hour should be 1." 

20 ) 

21 

22 

23def test_create_with_delta(): 

24 """Test the create_with_delta factory method.""" 

25 timestamp = Timestamp.create_with_delta(hours=1) 

26 

27 assert timestamp is not None, "There should be a timestamp." 

28 

29 

30def test_create_from_string(): 

31 """Test creating a local timestamp with a string.""" 

32 timestamp = Timestamp.create_from_string("1969-03-09 09:00:00") 

33 assert timestamp is not None, "There should be a timestamp" 

34 assert timestamp.year == 1969, "The year should be 1969" 

35 assert timestamp.month == 3, "The month should be 3" 

36 assert timestamp.day == 9, "The day should be 9" 

37 assert timestamp.hours == 9, "The hour should be 9" 

38 assert timestamp.minutes == 0, "The minutes should be 0" 

39 assert timestamp.seconds == 0, "The seconds should be 0"