-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tests and chagne timer to use datetime
- Loading branch information
Showing
3 changed files
with
55 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from django.test import TestCase | ||
from search.utils import Timer | ||
|
||
import datetime | ||
|
||
class TimerTest(TestCase): | ||
|
||
def test_start_timer(self): | ||
timer = Timer() | ||
timer.start() | ||
timer.stop() | ||
self.assertTrue(timer.start_time is not None) | ||
self.assertTrue(timer.end_time is not None) | ||
|
||
def test_elapsed_time(self): | ||
start = datetime.datetime(2024, 1, 0, 0, 0, 0, 0) | ||
end = start + datetime.timedelta(seconds=5) | ||
|
||
timer = Timer() | ||
timer._start_time = start | ||
timer._end_time = end | ||
|
||
self.assertEqual(timer.elapsed_time, 5) | ||
self.assertEqual(timer.start_time, start) | ||
self.assertEqual(timer.end_time, end) | ||
|
||
def test_elapsed_time_string(self): | ||
start = datetime.datetime(2024, 1, 0, 0, 0, 0, 0) | ||
end = start + datetime.timedelta(seconds=5) | ||
|
||
timer = Timer() | ||
timer._start_time = start | ||
timer._end_time = end | ||
|
||
self.assertEqual(timer.elapsed_time, 5) | ||
self.assertEqual(timer.start_time_string, "2024-01-01T00:00:00") | ||
self.assertEqual(timer.end_time_string, "2024-01-01T00:00:05") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters