Skip to content

Commit 202e33b

Browse files
committed
Adjust dict_match and remove arrow usage.
1 parent 64360f4 commit 202e33b

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ repository ="https://github.com/stac-utils/stac-pydantic.git"
3232

3333
[project.optional-dependencies]
3434
dev = [
35-
"arrow>=1.2.3",
3635
"pytest>=7.4.2",
3736
"pytest-cov>=4.1.0",
3837
"pytest-icdiff>=0.8",

tests/conftest.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import json
2-
import operator
32
import os
43
from copy import deepcopy
54
from typing import List, Optional, Type
65

7-
import arrow
86
import dictdiffer
97
import pytest
108
import requests
119
from click.testing import CliRunner
12-
from pydantic import BaseModel
10+
from pydantic import BaseModel, TypeAdapter
11+
12+
from stac_pydantic.shared import UtcDatetime
1313

1414

1515
def request(url: str, path: Optional[List[str]] = None):
@@ -30,6 +30,10 @@ def request(url: str, path: Optional[List[str]] = None):
3030
return json.loads(full_file)
3131

3232

33+
# Use a TypeAdapter to parse any datetime strings in a consistent manner
34+
UtcDatetimeAdapter = TypeAdapter(UtcDatetime)
35+
36+
3337
def dict_match(d1: dict, d2: dict):
3438
test = dictdiffer.diff(d1, d2)
3539
for diff in test:
@@ -39,16 +43,17 @@ def dict_match(d1: dict, d2: dict):
3943
# same for bbox
4044
elif "bbox" in diff[1]:
4145
assert list(diff[2][0]) == list(diff[2][1])
42-
# test data is pretty variable with how it represents datetime, RFC3339 is quite flexible
43-
# but stac-pydantic only supports a single datetime format, so just validate to the day.
46+
# RFC3339 is quite flexible and the test data uses various options to represent datetimes.
47+
# The datetime string stac-pydantic outputs may not be identical to the input. So we need
48+
# to compare the values as datetime objects.
4449
elif "datetime" in diff[1]:
45-
dates = []
46-
for date in diff[2]:
47-
if isinstance(date, str):
48-
date = arrow.get(date)
49-
dates.append(date)
50-
dates.sort(reverse=True)
51-
assert operator.sub(*dates).days == 0
50+
dates = [
51+
UtcDatetimeAdapter.validate_strings(date)
52+
if isinstance(date, str)
53+
else date
54+
for date in diff[2]
55+
]
56+
assert dates[0] == dates[1]
5257
# any other differences are errors
5358
elif "stac_extensions" in diff[1]:
5459
url1, url2 = map(str, diff[2])

0 commit comments

Comments
 (0)