"""Tests for schema helpers.""" from datetime import date from datetime import datetime import pytest from moneyhub.utils import schema @pytest.mark.parametrize('value,expected', [ (datetime(2010, 9, 8, 7, 6, 5), date(2010, 9, 8)), (date(2010, 9, 8), date(2010, 9, 8)), ('2010-09-08', date(2010, 9, 8)), (None, None), ]) def test_convert_to_date(value, expected): """Test convert to date function.""" result = schema.convert_to_date(value) assert result == expected @pytest.mark.parametrize('value,expected', [ ('fail', "time data 'fail' does not match format '%Y-%m-%d'"), (123, "'123' is not a date-ish value"), ({'ok': False}, "'{'ok': False}' is not a date-ish value"), ]) def test_convert_to_date_error(value, expected): """Test convert to date function when an error occurs.""" with pytest.raises(ValueError) as err: schema.convert_to_date(value) assert str(err.value) == expected