Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Remove deprecated utcnow #65

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading