1
0
personal-data/test/test_parsing.py

44 lines
1.1 KiB
Python
Raw Normal View History

2024-05-15 22:18:29 +00:00
import datetime
2024-05-15 22:29:06 +00:00
from decimal import Decimal
2024-05-15 22:47:42 +00:00
2024-05-15 22:18:29 +00:00
import pytest
from personal_data.csv_import import csv_str_to_value
2024-05-15 22:18:29 +00:00
PARSE_MAPPINGS = [
(
'2024-04-28 21:35:40+00:00',
2024-09-01 14:55:45 +00:00
datetime.datetime(2024, 4, 28, 21, 35, 40, tzinfo=datetime.UTC),
2024-05-15 22:18:29 +00:00
),
(
'2024-07-06 19:30:11+02:00',
datetime.datetime(2024, 7, 6, 19, 30, 11, tzinfo=datetime.timezone(datetime.timedelta(seconds=7200))),
),
(
'2023-10-21 11:43:27+02:00',
datetime.datetime(2023, 10, 21, 11, 43, 27, tzinfo=datetime.timezone(datetime.timedelta(seconds=7200))),
),
2024-05-15 22:18:29 +00:00
(
'0003791e9f5f3691b8bbbe0d12a7ae9c3f2e89db38',
'0003791e9f5f3691b8bbbe0d12a7ae9c3f2e89db38',
),
('', None),
2024-05-15 22:29:06 +00:00
('0', Decimal(0)),
('200', Decimal(200)),
('52.5474', Decimal('52.5474')),
2024-05-15 22:18:29 +00:00
('true', True),
('True', True),
('TRUE', True),
('false', False),
('False', False),
('FALSE', False),
('none', None),
('None', None),
('NONE', None),
]
@pytest.mark.parametrize('text,parsed', PARSE_MAPPINGS)
2024-09-02 09:33:09 +00:00
def test_csv_str_to_value(text, parsed):
assert csv_str_to_value(text) == parsed, text