Skip to content

Commit

Permalink
fix!: ⏰ Remove deprecated utcnow
Browse files Browse the repository at this point in the history
This still fails some tests because of differences in 3.12. There's also
an issue with times being truncated, which may be a formatting issue
that cannot be addressed right now.
  • Loading branch information
teald committed Dec 26, 2024
1 parent f2afa04 commit 514aa9e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions astrodata/provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

import json
from datetime import datetime
from datetime import datetime, timezone

from astropy.table import Table

Expand Down Expand Up @@ -38,7 +38,7 @@ def add_provenance(ad, filename, md5, primitive, timestamp=None):
md5 = "" if md5 is None else md5

if timestamp is None:
timestamp = datetime.utcnow().isoformat()
timestamp = datetime.now(timezone.utc).isoformat()

if hasattr(ad, "PROVENANCE"):
existing_provenance = ad.PROVENANCE
Expand Down
24 changes: 12 additions & 12 deletions tests/unit/test_provenance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
import json
import os

Expand Down Expand Up @@ -31,7 +31,7 @@ def ad2():


def test_add_get_provenance(ad):
timestamp = datetime.utcnow().isoformat()
timestamp = datetime.now(timezone.utc).isoformat()
filename = "filename"
md5 = "md5"
primitive = "provenance_added_by"
Expand All @@ -58,7 +58,7 @@ def test_add_get_provenance(ad):


def test_add_duplicate_provenance(ad):
timestamp = datetime.utcnow().isoformat()
timestamp = datetime.now(timezone.utc).isoformat()
filename = "filename"
md5 = "md5"
primitive = "provenance_added_by"
Expand All @@ -71,7 +71,7 @@ def test_add_duplicate_provenance(ad):


def test_add_get_history(ad):
timestamp_start = datetime.utcnow()
timestamp_start = datetime.now(timezone.utc)
timestamp_end = (timestamp_start + timedelta(days=1)).isoformat()
timestamp_start = timestamp_start.isoformat()
primitive = "primitive"
Expand Down Expand Up @@ -103,7 +103,7 @@ def test_add_get_history(ad):


def test_add_dupe_history(ad):
timestamp_start = datetime.utcnow()
timestamp_start = datetime.now(timezone.utc)
timestamp_end = (timestamp_start + timedelta(days=1)).isoformat()
timestamp_start = timestamp_start.isoformat()
primitive = "primitive"
Expand All @@ -117,7 +117,7 @@ def test_add_dupe_history(ad):


def test_clone_provenance(ad, ad2):
timestamp = datetime.utcnow().isoformat()
timestamp = datetime.now(timezone.utc).isoformat()
filename = "filename"
md5 = "md5"
primitive = "provenance_added_by"
Expand All @@ -131,7 +131,7 @@ def test_clone_provenance(ad, ad2):


def test_clone_history(ad, ad2):
timestamp_start = datetime.utcnow()
timestamp_start = datetime.now(timezone.utc)
timestamp_end = (timestamp_start + timedelta(days=1)).isoformat()
timestamp_start = timestamp_start.isoformat()
primitive = "primitive"
Expand Down Expand Up @@ -167,7 +167,7 @@ def test_convert_provhistory(tmp_path, BPM_PROVHISTORY):
assert hasattr(ad, "PROVHISTORY")

# When we add history, that should get converted to HISTORY
now = datetime.utcnow().isoformat()
now = datetime.now(timezone.utc).isoformat()
add_history(ad, now, now, "primitive", "args")
assert not hasattr(ad, "PROVHISTORY")
assert hasattr(ad, "HISTORY")
Expand Down Expand Up @@ -195,26 +195,26 @@ def test_provenance_summary(ad):
summary = astrodata.provenance.provenance_summary(ad).casefold()
assert "no provenance" in summary

timestamp = datetime.utcnow().isoformat()
timestamp = datetime.now(timezone.utc).isoformat()
filename = "filename"
md5 = "md5"
primitive = "primitive_name"

add_provenance(ad, filename, md5, primitive, timestamp=timestamp)

timestamp_end = datetime.utcnow().isoformat()
timestamp_end = datetime.now(timezone.utc).isoformat()
args = json.dumps({"arg1": 1, "arg2": 3})

add_history(ad, timestamp, timestamp_end, primitive, args)

timestamp = datetime.utcnow().isoformat()
timestamp = datetime.now(timezone.utc).isoformat()
filename = "filename"
md5 = "md5"
primitive = "snudder_primitive_name"

add_provenance(ad, filename, md5, primitive, timestamp=timestamp)

timestamp_end = datetime.utcnow().isoformat()
timestamp_end = datetime.now(timezone.utc).isoformat()
args = json.dumps({"arg1": 1, "arg2": 2})

add_history(ad, timestamp, timestamp_end, primitive, args)
Expand Down

0 comments on commit 514aa9e

Please sign in to comment.