Skip to content
Merged
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 docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ The report is generated in the background, and the URL it is served from expires
"""Get the number of recognitions of each target this month."""

import calendar
import datetime
import datetime as dt
import os

from vws import VWS
Expand All @@ -92,7 +92,7 @@ The report is generated in the background, and the URL it is served from expires
database_id=database_id,
)

now = datetime.datetime.now(tz=datetime.UTC)
now = dt.datetime.now(tz=dt.UTC)

report_request = vws_client.request_database_reco_counts_report(
year=now.year,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ dev = [
"pytest-beartype==0.3.0",
"pytest-cov==7.1.0",
"pyyaml==6.0.3",
"ruff==0.16.10",
"ruff==0.17.0",
# We add shellcheck-py not only for shell scripts and shell code blocks,
# but also because having it installed means that ``actionlint-py`` will
# use it to lint shell commands in GitHub workflow files.
Expand Down
28 changes: 14 additions & 14 deletions src/vws/reports.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Classes for representing Vuforia reports."""

import csv
import datetime
import datetime as dt
import io
from collections.abc import Mapping, Sequence
from dataclasses import dataclass
Expand Down Expand Up @@ -118,7 +118,7 @@ class TargetSummaryReport:
status: TargetStatuses
database_name: str
target_name: str
upload_date: datetime.date
upload_date: dt.date
active_flag: bool
tracking_rating: int
total_recos: int
Expand All @@ -136,7 +136,7 @@ def from_response_dict(
),
database_name=_checked(response_dict["database_name"], str),
target_name=_checked(response_dict["target_name"], str),
upload_date=datetime.date.fromisoformat(
upload_date=dt.date.fromisoformat(
_checked(response_dict["upload_date"], str)
),
active_flag=bool(response_dict["active_flag"]),
Expand Down Expand Up @@ -175,7 +175,7 @@ class TargetData:

name: str
application_metadata: str | None
target_timestamp: datetime.datetime
target_timestamp: dt.datetime


@beartype
Expand All @@ -201,9 +201,9 @@ def from_response_dict(
target_data_dict = _checked(
response_dict["target_data"], dict[str, JSONValue]
)
target_timestamp = datetime.datetime.fromtimestamp(
target_timestamp = dt.datetime.fromtimestamp(
timestamp=_number(target_data_dict["target_timestamp"]),
tz=datetime.UTC,
tz=dt.UTC,
)
target_data = TargetData(
name=_checked(target_data_dict["name"], str),
Expand Down Expand Up @@ -337,14 +337,14 @@ class ModelTargetDatasetStatusReport:

status: ModelTargetDatasetStatuses
dataset_uuid: str
created_at: datetime.datetime
eta: datetime.datetime | None
created_at: dt.datetime
eta: dt.datetime | None
"""When Vuforia expects to finish generating the dataset.

This is given only while the dataset is processing.
"""

completed_at: datetime.datetime | None
completed_at: dt.datetime | None
"""When Vuforia finished generating the dataset.

This is given only once the dataset is no longer processing.
Expand Down Expand Up @@ -397,15 +397,15 @@ def from_response_dict(
],
)

eta: datetime.datetime | None = None
eta: dt.datetime | None = None
if "eta" in response_dict:
eta = datetime.datetime.fromisoformat(
eta = dt.datetime.fromisoformat(
_checked(response_dict["eta"], str),
)

completed_at: datetime.datetime | None = None
completed_at: dt.datetime | None = None
if "completedAt" in response_dict:
completed_at = datetime.datetime.fromisoformat(
completed_at = dt.datetime.fromisoformat(
_checked(response_dict["completedAt"], str),
)

Expand All @@ -414,7 +414,7 @@ def from_response_dict(
value=_checked(response_dict["status"], str),
),
dataset_uuid=_checked(response_dict["uuid"], str),
created_at=datetime.datetime.fromisoformat(
created_at=dt.datetime.fromisoformat(
_checked(response_dict["createdAt"], str),
),
eta=eta,
Expand Down
14 changes: 7 additions & 7 deletions tests/async_vws/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

import calendar
import datetime
import datetime as dt
import time
import uuid
from http import HTTPStatus
Expand Down Expand Up @@ -120,14 +120,14 @@ async def test_get_target(
async def test_reco_counts_report(
*,
async_vws_client: AsyncVWS,
current_month: datetime.date,
current_month: dt.date,
report_period: Literal["current", "previous"],
) -> None:
"""A report can be requested, waited for and downloaded."""
report_month = (
current_month
if report_period == "current"
else current_month - datetime.timedelta(days=1)
else current_month - dt.timedelta(days=1)
)
client = async_vws_client
report_request = await client.request_database_reco_counts_report(
Expand All @@ -147,7 +147,7 @@ async def test_reco_counts_report(


@pytest.mark.asyncio
async def test_not_ready(*, current_month: datetime.date) -> None:
async def test_not_ready(*, current_month: dt.date) -> None:
"""Downloading a report before Vuforia has generated it raises an
error.
"""
Expand Down Expand Up @@ -175,7 +175,7 @@ async def test_not_ready(*, current_month: datetime.date) -> None:


@pytest.mark.asyncio
async def test_wait_timeout(*, current_month: datetime.date) -> None:
async def test_wait_timeout(*, current_month: dt.date) -> None:
"""Waiting for a report which is not generated in time raises an
error.
"""
Expand Down Expand Up @@ -241,7 +241,7 @@ async def test_month_not_accepted(
@pytest.mark.asyncio
async def test_database_id_does_not_match_keys(
*,
current_month: datetime.date,
current_month: dt.date,
) -> None:
"""A database ID which does not match the given keys is
rejected.
Expand Down Expand Up @@ -284,7 +284,7 @@ async def test_download_error() -> None:


@pytest.mark.asyncio
async def test_no_database_id(*, current_month: datetime.date) -> None:
async def test_no_database_id(*, current_month: dt.date) -> None:
"""A client which was given no database ID cannot request a
report.
"""
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

import datetime
import datetime as dt
import io
from collections.abc import AsyncGenerator, Generator
from contextlib import ExitStack
Expand Down Expand Up @@ -197,9 +197,9 @@ def fixture_model_target_model() -> ModelTargetModel:


@pytest.fixture(name="current_month")
def fixture_current_month() -> datetime.date:
def fixture_current_month() -> dt.date:
"""The current month, as the first day of that month."""
now = datetime.datetime.now(tz=datetime.UTC)
now = dt.datetime.now(tz=dt.UTC)
return now.date().replace(day=1)


Expand Down
6 changes: 3 additions & 3 deletions tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

import datetime
import datetime as dt
import json
import secrets
import uuid
Expand Down Expand Up @@ -190,7 +190,7 @@ def test_default_timeout(
response_delay_seconds=response_delay_seconds,
sleep_fn=lambda seconds: (
frozen_datetime.tick(
delta=datetime.timedelta(seconds=seconds),
delta=dt.timedelta(seconds=seconds),
),
None,
)[1],
Expand Down Expand Up @@ -248,7 +248,7 @@ def test_custom_timeout(
response_delay_seconds=response_delay_seconds,
sleep_fn=lambda seconds: (
frozen_datetime.tick(
delta=datetime.timedelta(seconds=seconds),
delta=dt.timedelta(seconds=seconds),
),
None,
)[1],
Expand Down
6 changes: 3 additions & 3 deletions tests/vws/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

import datetime
import datetime as dt
from typing import TYPE_CHECKING, BinaryIO, Literal

import pytest
Expand Down Expand Up @@ -45,7 +45,7 @@ def test_default_timeout(
response_delay_seconds=response_delay_seconds,
sleep_fn=lambda seconds: (
frozen_datetime.tick(
delta=datetime.timedelta(seconds=seconds),
delta=dt.timedelta(seconds=seconds),
),
None,
)[1],
Expand Down Expand Up @@ -114,7 +114,7 @@ def test_custom_timeout(
response_delay_seconds=response_delay_seconds,
sleep_fn=lambda seconds: (
frozen_datetime.tick(
delta=datetime.timedelta(seconds=seconds),
delta=dt.timedelta(seconds=seconds),
),
None,
)[1],
Expand Down
16 changes: 8 additions & 8 deletions tests/vws/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

import calendar
import datetime
import datetime as dt
import time
import uuid
from http import HTTPStatus
Expand Down Expand Up @@ -103,7 +103,7 @@ def test_get_target_summary_report(
status=TargetStatuses.SUCCESS,
database_name=report.database_name,
target_name=target_name,
upload_date=datetime.date(year=2018, month=4, day=25),
upload_date=dt.date(year=2018, month=4, day=25),
active_flag=True,
tracking_rating=report.tracking_rating,
total_recos=0,
Expand Down Expand Up @@ -167,14 +167,14 @@ def test_get_target(vws_client: VWS) -> None:
def test_reco_counts_report(
*,
vws_client: VWS,
current_month: datetime.date,
current_month: dt.date,
report_period: Literal["current", "previous"],
) -> None:
"""A report can be requested, waited for and downloaded."""
report_month = (
current_month
if report_period == "current"
else current_month - datetime.timedelta(days=1)
else current_month - dt.timedelta(days=1)
)
report_request = vws_client.request_database_reco_counts_report(
year=report_month.year,
Expand All @@ -192,7 +192,7 @@ def test_reco_counts_report(
assert report.raw_csv.startswith(b"target_id,reco_count")


def test_not_ready(*, current_month: datetime.date) -> None:
def test_not_ready(*, current_month: dt.date) -> None:
"""Downloading a report before Vuforia has generated it raises an
error.
"""
Expand All @@ -219,7 +219,7 @@ def test_not_ready(*, current_month: datetime.date) -> None:
assert exc.value.response.status_code == HTTPStatus.NOT_FOUND


def test_wait_timeout(*, current_month: datetime.date) -> None:
def test_wait_timeout(*, current_month: dt.date) -> None:
"""Waiting for a report which is not generated in time raises an
error.
"""
Expand Down Expand Up @@ -283,7 +283,7 @@ def test_month_not_accepted(

def test_database_id_does_not_match_keys(
*,
current_month: datetime.date,
current_month: dt.date,
) -> None:
"""A database ID which does not match the given keys is
rejected.
Expand Down Expand Up @@ -326,7 +326,7 @@ def test_download_error() -> None:
assert exc.value.response.status_code == HTTPStatus.FORBIDDEN


def test_no_database_id(*, current_month: datetime.date) -> None:
def test_no_database_id(*, current_month: dt.date) -> None:
"""A client which was given no database ID cannot request a
report.
"""
Expand Down
Loading