Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
Refactor deprecated datetime.utcnow()
Browse files Browse the repository at this point in the history
  • Loading branch information
Sinclert committed Oct 10, 2023
1 parent 3a74d90 commit 9783d35
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 34 deletions.
3 changes: 2 additions & 1 deletion src/dialect_map_core/controllers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from abc import ABC
from abc import abstractmethod
from datetime import datetime
from datetime import timezone
from typing import Generic
from typing import List
from typing import Tuple
Expand Down Expand Up @@ -220,7 +221,7 @@ def archive(self, id: str) -> str:

record = self.get(id)
record.archived = True
record.archived_at = datetime.utcnow()
record.archived_at = datetime.now(timezone.utc)

self.session.commit()
return id
Expand Down
5 changes: 3 additions & 2 deletions tests/controllers/test_category_ctl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

from datetime import datetime
from datetime import timezone

import pytest

Expand Down Expand Up @@ -59,7 +60,7 @@ def test_create(self, controller: CategoryController):
category_id=category_id,
description=category_ds,
archived=False,
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)

creation_id = controller.create(category)
Expand All @@ -80,7 +81,7 @@ def test_delete(self, controller: CategoryController):
category_id=category_id,
description=category_ds,
archived=False,
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)

creation_id = controller.create(category)
Expand Down
15 changes: 8 additions & 7 deletions tests/controllers/test_jargon_ctl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

from datetime import datetime
from datetime import timezone

import pytest

Expand Down Expand Up @@ -83,7 +84,7 @@ def test_create(self, controller: JargonController):
jargon_term=jargon_term,
jargon_regex=jargon_regex,
archived=False,
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)

creation_id = controller.create(jargon)
Expand All @@ -110,7 +111,7 @@ def test_create_with_non_existent_jargon_group(
jargon_term="My test jargon",
jargon_regex="[Mm]y test jargon",
archived=False,
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)

assert pytest.raises(database.error, controller.create, jargon)
Expand All @@ -129,7 +130,7 @@ def test_delete(self, controller: JargonController):
jargon_term=jargon_term,
jargon_regex=jargon_regex,
archived=False,
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)

creation_id = controller.create(jargon)
Expand Down Expand Up @@ -191,7 +192,7 @@ def test_create(self, controller: JargonGroupController):
group_id=group_id,
description=group_ds,
archived=False,
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)

creation_id = controller.create(group)
Expand All @@ -215,15 +216,15 @@ def test_create_nested(self, session: BaseDatabaseSession):
"group_id": group_id,
"description": "My nested group",
"archived": False,
"created_at": datetime.utcnow(),
"created_at": datetime.now(timezone.utc),
"jargons": [
{
"group_id": group_id,
"jargon_id": jargon_id,
"jargon_term": "One string",
"jargon_regex": "[Oo]ne string",
"archived": False,
"created_at": datetime.utcnow(),
"created_at": datetime.now(timezone.utc),
},
],
}
Expand Down Expand Up @@ -252,7 +253,7 @@ def test_delete(self, controller: JargonGroupController):
group_id=group_id,
description=group_ds,
archived=False,
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)

creation_id = controller.create(group)
Expand Down
9 changes: 5 additions & 4 deletions tests/controllers/test_membership_ctl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

from datetime import datetime
from datetime import timezone

import pytest

Expand Down Expand Up @@ -60,7 +61,7 @@ def test_create(self, controller: MembershipController):
arxiv_id="paper-01234",
arxiv_rev=2,
category_id="category-01234",
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)

creation_id = controller.create(membership)
Expand All @@ -85,7 +86,7 @@ def test_create_with_non_existent_paper(
arxiv_id="non-existing-paper",
arxiv_rev=100,
category_id="category-01234",
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)

assert pytest.raises(database.error, controller.create, membership)
Expand All @@ -106,7 +107,7 @@ def test_create_with_non_existent_category(
arxiv_id="paper-01234",
arxiv_rev=2,
category_id="non-existing-category",
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)

assert pytest.raises(database.error, controller.create, membership)
Expand All @@ -123,7 +124,7 @@ def test_delete(self, controller: MembershipController):
arxiv_id="paper-01234",
arxiv_rev=2,
category_id="category-01234",
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)

creation_id = controller.create(membership)
Expand Down
9 changes: 5 additions & 4 deletions tests/controllers/test_metrics_ctl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

from datetime import datetime
from datetime import timezone

import pytest

Expand Down Expand Up @@ -57,7 +58,7 @@ def test_create_with_non_existent_jargon(
category_id="category-01234",
abs_freq=10,
rel_freq=0.05,
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)

assert pytest.raises(database.error, controller.create, cat_metrics)
Expand All @@ -79,7 +80,7 @@ def test_create_with_non_existent_category(
category_id="non-existing-category",
abs_freq=10,
rel_freq=0.05,
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)

assert pytest.raises(database.error, controller.create, cat_metrics)
Expand Down Expand Up @@ -143,7 +144,7 @@ def test_create_with_non_existent_jargon(
arxiv_rev=1,
abs_freq=10,
rel_freq=0.05,
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)

assert pytest.raises(database.error, controller.create, paper_metrics)
Expand All @@ -166,7 +167,7 @@ def test_create_with_non_existent_category(
arxiv_rev=1,
abs_freq=10,
rel_freq=0.05,
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)

assert pytest.raises(database.error, controller.create, paper_metrics)
17 changes: 9 additions & 8 deletions tests/controllers/test_paper_ctl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

from datetime import datetime
from datetime import timezone

import pytest

Expand Down Expand Up @@ -54,8 +55,8 @@ def test_create(self, controller: PaperController):
arxiv_rev=paper_rev,
title="Test Paper",
submission_date=datetime.today().date(),
created_at=datetime.utcnow(),
updated_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
updated_at=datetime.now(timezone.utc),
)

creation_id = controller.create(paper)
Expand All @@ -77,8 +78,8 @@ def test_delete(self, controller: PaperController):
arxiv_rev=paper_rev,
title="Test Paper",
submission_date=datetime.today().date(),
created_at=datetime.utcnow(),
updated_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
updated_at=datetime.now(timezone.utc),
)

creation_id = controller.create(paper)
Expand All @@ -100,8 +101,8 @@ def test_delete_rev(self, controller: PaperController):
arxiv_rev=paper_rev,
title="Test Paper",
submission_date=datetime.today().date(),
created_at=datetime.utcnow(),
updated_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
updated_at=datetime.now(timezone.utc),
)

controller.create(paper)
Expand Down Expand Up @@ -156,7 +157,7 @@ def test_create_with_non_existent_paper(
arxiv_id="non-existing-paper",
arxiv_rev=1,
author_name="John Doe",
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)

assert pytest.raises(database.error, controller.create, author)
Expand Down Expand Up @@ -207,7 +208,7 @@ def test_create_with_non_existent_paper(
arxiv_rev=1,
arxiv_ref_count=0,
total_ref_count=0,
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)

assert pytest.raises(database.error, controller.create, counter)
9 changes: 5 additions & 4 deletions tests/controllers/test_reference_ctl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

from datetime import datetime
from datetime import timezone

import pytest

Expand Down Expand Up @@ -84,7 +85,7 @@ def test_create(self, controller: ReferenceController):
source_arxiv_rev=2,
target_arxiv_id="paper-56789",
target_arxiv_rev=2,
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)

creation_id = controller.create(ref)
Expand All @@ -110,7 +111,7 @@ def test_create_with_non_existent_source_paper(
source_arxiv_rev=2,
target_arxiv_id="paper-56789",
target_arxiv_rev=2,
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)

assert pytest.raises(database.error, controller.create, ref)
Expand All @@ -132,7 +133,7 @@ def test_create_with_non_existent_target_paper(
source_arxiv_rev=2,
target_arxiv_id="non-existing-paper",
target_arxiv_rev=2,
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)

assert pytest.raises(database.error, controller.create, ref)
Expand All @@ -150,7 +151,7 @@ def test_delete(self, controller: ReferenceController):
source_arxiv_rev=2,
target_arxiv_id="paper-56789",
target_arxiv_rev=2,
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)

creation_id = controller.create(ref)
Expand Down
9 changes: 5 additions & 4 deletions tests/storage/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from contextlib import suppress
from datetime import datetime
from datetime import timezone

import pytest

Expand Down Expand Up @@ -71,15 +72,15 @@ def test_valid_transaction_committed(
category_id="example-1",
description="example",
archived=False,
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)
)
ctl.create(
Category(
category_id="example-2",
description="example",
archived=False,
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)
)

Expand All @@ -105,15 +106,15 @@ def test_valid_transaction_uncommitted(
category_id="example-3",
description="example",
archived=False,
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)
)
ctl.create(
Category(
category_id="example-4",
description="example",
archived=False,
created_at=datetime.utcnow(),
created_at=datetime.now(timezone.utc),
)
)

Expand Down

0 comments on commit 9783d35

Please sign in to comment.