mirror of https://github.com/eyhc1/rendercv.git
add tests
This commit is contained in:
parent
b56fb1d31f
commit
f2a8e152c6
|
@ -123,6 +123,11 @@ def compute_time_span_string(start_date: Date, end_date: Date) -> str:
|
||||||
# calculate the number of days between start_date and end_date:
|
# calculate the number of days between start_date and end_date:
|
||||||
timespan_in_days = (end_date - start_date).days
|
timespan_in_days = (end_date - start_date).days
|
||||||
|
|
||||||
|
if timespan_in_days < 0:
|
||||||
|
raise ValueError(
|
||||||
|
"The start date is after the end date. Please check the dates!"
|
||||||
|
)
|
||||||
|
|
||||||
# calculate the number of years between start_date and end_date:
|
# calculate the number of years between start_date and end_date:
|
||||||
how_many_years = timespan_in_days // 365
|
how_many_years = timespan_in_days // 365
|
||||||
if how_many_years == 0:
|
if how_many_years == 0:
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
import unittest
|
||||||
|
from rendercv import data_model, rendering
|
||||||
|
|
||||||
|
from datetime import date as Date
|
||||||
|
|
||||||
|
|
||||||
|
class TestRendercv(unittest.TestCase):
|
||||||
|
def test_check_spelling(self):
|
||||||
|
sentences = [
|
||||||
|
"This is a sentence.",
|
||||||
|
"This is a sentance with special characters &@#&^@*#&)((!@#_)()).",
|
||||||
|
"12312309 Thisdf sdfsd is a sentence *safds\{\}[[[]]]",
|
||||||
|
]
|
||||||
|
|
||||||
|
for sentence in sentences:
|
||||||
|
data_model.check_spelling(sentence)
|
||||||
|
|
||||||
|
def test_compute_time_span_string(self):
|
||||||
|
start_date = Date(year=2020, month=1, day=1)
|
||||||
|
end_date = Date(year=2021, month=1, day=1)
|
||||||
|
expected = "1 year 1 month"
|
||||||
|
result = data_model.compute_time_span_string(start_date, end_date)
|
||||||
|
self.assertEqual(result, expected)
|
||||||
|
|
||||||
|
start_date = Date(year=2020, month=1, day=1)
|
||||||
|
end_date = Date(year=2020, month=2, day=1)
|
||||||
|
expected = "1 month"
|
||||||
|
result = data_model.compute_time_span_string(start_date, end_date)
|
||||||
|
self.assertEqual(result, expected)
|
||||||
|
|
||||||
|
start_date = Date(year=2020, month=1, day=1)
|
||||||
|
end_date = Date(year=2023, month=3, day=2)
|
||||||
|
expected = "3 years 2 months"
|
||||||
|
result = data_model.compute_time_span_string(start_date, end_date)
|
||||||
|
self.assertEqual(result, expected)
|
||||||
|
|
||||||
|
start_date = Date(year=2020, month=1, day=1)
|
||||||
|
end_date = Date(year=1982, month=1, day=1)
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
data_model.compute_time_span_string(start_date, end_date)
|
||||||
|
|
||||||
|
def test_format_date(self):
|
||||||
|
date = Date(year=2020, month=1, day=1)
|
||||||
|
expected = "Jan. 2020"
|
||||||
|
result = data_model.format_date(date)
|
||||||
|
self.assertEqual(result, expected)
|
||||||
|
|
||||||
|
date = Date(year=1983, month=12, day=1)
|
||||||
|
expected = "Dec. 1983"
|
||||||
|
result = data_model.format_date(date)
|
||||||
|
self.assertEqual(result, expected)
|
||||||
|
|
||||||
|
date = Date(year=2045, month=6, day=1)
|
||||||
|
expected = "June 2045"
|
||||||
|
result = data_model.format_date(date)
|
||||||
|
self.assertEqual(result, expected)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue