Skip to content

Commit

Permalink
time tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterprovoost committed Sep 13, 2023
1 parent 9517d5d commit b0f46e7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions obisqc/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def date_to_millis(d) -> int:
return int((d - datetime.date(1970, 1, 1)).total_seconds() * 1000)


def check_record(record: Record, min_year: int=0):
def check_record(record: Record, min_year: int = 1582):
"""Check the eventDate."""

if record.get("eventDate") is not None:
Expand Down Expand Up @@ -49,5 +49,5 @@ def check_record(record: Record, min_year: int=0):
record.set_missing("eventDate")


def check(records: List[Record], min_year: int = 0):
def check(records: List[Record], min_year: int = 1582):
return [check_record(record, min_year) for record in records]
28 changes: 20 additions & 8 deletions test/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def test_time_parsing(self):
def test_min_date(self):
records = [
Record(eventDate="1870-01-01T00:00:00"),
Record(eventDate="0001-04-11")
]

time.check(records, min_year=1900)
self.assertTrue(records[0].get_interpreted("date_start") is None)
self.assertTrue(records[0].get_interpreted("date_mid") is None)
Expand All @@ -39,13 +37,27 @@ def test_min_date(self):
self.assertTrue(records[0].is_invalid("eventDate"))
self.assertFalse(records[0].dropped)

records = [
Record(eventDate="0001-04-11"),
]
time.check(records, min_year=1000)
self.assertTrue(records[1].get_interpreted("date_start") is None)
self.assertTrue(records[1].get_interpreted("date_mid") is None)
self.assertTrue(records[1].get_interpreted("date_end") is None)
self.assertIn(Flag.DATE_BEFORE_MIN, records[1].flags)
self.assertTrue(records[1].is_invalid("eventDate"))
self.assertFalse(records[1].dropped)
self.assertTrue(records[0].get_interpreted("date_start") is None)
self.assertTrue(records[0].get_interpreted("date_mid") is None)
self.assertTrue(records[0].get_interpreted("date_end") is None)
self.assertIn(Flag.DATE_BEFORE_MIN, records[0].flags)
self.assertTrue(records[0].is_invalid("eventDate"))
self.assertFalse(records[0].dropped)

records = [
Record(eventDate="1590-04-11"),
]
time.check(records)
self.assertTrue(records[0].get_interpreted("date_start") is not None)
self.assertTrue(records[0].get_interpreted("date_mid") is not None)
self.assertTrue(records[0].get_interpreted("date_end") is not None)
self.assertNotIn(Flag.DATE_BEFORE_MIN, records[0].flags)
self.assertFalse(records[0].is_invalid("eventDate"))
self.assertFalse(records[0].dropped)

def test_future_date(self):
records = [
Expand Down

0 comments on commit b0f46e7

Please sign in to comment.