Skip to content

Commit ad774a9

Browse files
authored
Bring back tests to AIP (#54)
* Add date_utils tests * Update ignore files
1 parent cfd8ccb commit ad774a9

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ Dockerfile_MacM1
3131
images/
3232
.github
3333
data/
34+
tests/

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.idea/
22
.env
3-
*__pycache__*
4-
src/data/__pycache__/
3+
__pycache__/
54
*-run.sh
65
venv/
76
*.venv/
87
*.swp
8+

tests/__init__.py

Whitespace-only changes.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import unittest
2+
import logging
3+
from datetime import date
4+
from lib.aip.utils.date_utils import validate_and_convert_date
5+
6+
7+
# Suppress logging messages below CRITICAL level
8+
# to just get the result of the tests.
9+
logging.disable(logging.CRITICAL)
10+
11+
class TestValidateAndConvertDate(unittest.TestCase):
12+
13+
def test_valid_date(self):
14+
# Test with a valid date
15+
self.assertEqual(validate_and_convert_date("2024-10-27"), date(2024, 10, 27))
16+
17+
def test_empty_string(self):
18+
# Test with an empty string
19+
with self.assertRaises(ValueError):
20+
validate_and_convert_date("")
21+
22+
def test_invalid_format(self):
23+
# Test with various invalid formats
24+
with self.assertRaises(ValueError):
25+
validate_and_convert_date("2024/10/27")
26+
27+
with self.assertRaises(ValueError):
28+
validate_and_convert_date("27-10-2024")
29+
30+
with self.assertRaises(ValueError):
31+
validate_and_convert_date("October 27, 2024")
32+
33+
def test_nonexistent_date(self):
34+
# Test not existing date Feb 30th
35+
with self.assertRaises(ValueError):
36+
validate_and_convert_date("2024-02-30")
37+
38+
# Test not existing month 13
39+
with self.assertRaises(ValueError):
40+
validate_and_convert_date("2024-13-01")
41+
42+
def test_none_value(self):
43+
# Test with None as input
44+
with self.assertRaises(TypeError):
45+
validate_and_convert_date(None)
46+
47+
def test_edge_case(self):
48+
# Test leap years
49+
self.assertEqual(validate_and_convert_date("2024-02-29"), date(2024, 2, 29))
50+
51+
if __name__ == '__main__':
52+
unittest.main()

0 commit comments

Comments
 (0)