Skip to content

Commit

Permalink
test: add an explicit test for datetime and date complete flow
Browse files Browse the repository at this point in the history
Tests that when a datetime or date goes into splitgill (and therefore goes through the prepare_data function) it comes out correct when parsed.
  • Loading branch information
jrdh committed Aug 7, 2024
1 parent f343721 commit 8886c23
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion tests/indexing/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,44 @@
from datetime import datetime
from datetime import datetime, date, timezone, timedelta
from itertools import chain
from typing import List, Any

import pytest
from shapely import from_wkt

from diffing import prepare_data
from indexing.options import ParsingOptionsBuilder
from splitgill.indexing.fields import ParsedType, DataType
from splitgill.indexing.geo import match_hints, match_geojson
from splitgill.indexing.parser import parse, parse_value, type_for
from splitgill.model import ParsingOptions
from splitgill.utils import to_timestamp


def test_in_and_out_of_dates():
# check that using the default options, we can put a date through prepare_data and
# get the correct date back out when we parse it
options = ParsingOptionsBuilder().build()
tz = timezone(timedelta(hours=7))
candidates = [
date(2021, 1, 5),
datetime(2021, 1, 5, 6, 23, 17),
datetime(2021, 1, 5, 6, 23, 17, 234567),
datetime(2021, 1, 5, 6, 23, 17, tzinfo=tz),
datetime(2021, 1, 5, 6, 23, 17, 234567, tzinfo=tz),
]

for candidate in candidates:
parsed = parse_value(prepare_data(candidate), options)
assert ParsedType.DATE in parsed
if isinstance(candidate, datetime):
if candidate.tzinfo is None:
candidate = candidate.replace(tzinfo=timezone.utc)
else:
candidate = datetime(candidate.year, candidate.month, candidate.day)

assert parsed[ParsedType.DATE] == to_timestamp(candidate)


class TestParse:
def test_no_nesting(self, basic_options: ParsingOptions):
data = {"x": "beans"}
Expand Down

0 comments on commit 8886c23

Please sign in to comment.