Skip to content

Commit cb8a5fb

Browse files
adamtheturtleclaude
andcommitted
Take the reco counts report month as a calendar.Month
Vuforia accepts only the current month and the previous month, so a month out of the 1-12 range is now rejected by the type rather than by the server. A month taken from a ``datetime`` needs wrapping in ``calendar.Month``, because ``datetime.month`` is a plain ``int`` and ``beartype`` rejects it otherwise. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent e6c52dc commit cb8a5fb

6 files changed

Lines changed: 38 additions & 22 deletions

File tree

docs/source/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ The report is generated in the background, and the URL it is served from expires
7676
7777
"""Get the number of recognitions of each target this month."""
7878
79+
import calendar
7980
import datetime
8081
import os
8182
@@ -95,7 +96,7 @@ The report is generated in the background, and the URL it is served from expires
9596
9697
report_request = vws_client.request_database_reco_counts_report(
9798
year=now.year,
98-
month=now.month,
99+
month=calendar.Month(value=now.month),
99100
)
100101
101102
report = vws_client.wait_for_reco_counts_report(

src/vws/_reco_counts.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Internal helpers for the database reco counts report endpoints."""
22

3+
import calendar # noqa: TC003
34
import json
45
from http import HTTPStatus
56

@@ -39,7 +40,7 @@ def reco_counts_report_path(*, database_id: str | None) -> str:
3940

4041

4142
@beartype(conf=BeartypeConf(is_pep484_tower=True))
42-
def reco_counts_report_body(*, year: int, month: int) -> bytes:
43+
def reco_counts_report_body(*, year: int, month: calendar.Month) -> bytes:
4344
"""Get the request body for requesting a reco counts report.
4445
4546
Args:

src/vws/async_vws.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import asyncio
44
import base64
5+
import calendar # noqa: TC003
56
import json
67
import time
78
from http import HTTPMethod, HTTPStatus
@@ -459,7 +460,7 @@ async def request_database_reco_counts_report(
459460
self,
460461
*,
461462
year: int,
462-
month: int,
463+
month: calendar.Month,
463464
) -> RecoCountsReportRequest:
464465
"""Request a per-target recognition count report for the database.
465466
@@ -471,7 +472,8 @@ async def request_database_reco_counts_report(
471472
year: The year to get recognition counts for.
472473
month: The month of the year to get recognition counts for.
473474
Vuforia accepts only the current month and the previous
474-
month.
475+
month. A month taken from a :class:`datetime.datetime` needs
476+
wrapping, as in ``calendar.Month(value=now.month)``.
475477
476478
Returns:
477479
The URL to download the report from, and the transaction ID of

src/vws/vws.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tools for interacting with Vuforia APIs."""
22

33
import base64
4+
import calendar # noqa: TC003
45
import json
56
import time
67
from http import HTTPMethod, HTTPStatus
@@ -432,7 +433,7 @@ def request_database_reco_counts_report(
432433
self,
433434
*,
434435
year: int,
435-
month: int,
436+
month: calendar.Month,
436437
) -> RecoCountsReportRequest:
437438
"""Request a per-target recognition count report for the database.
438439
@@ -444,7 +445,8 @@ def request_database_reco_counts_report(
444445
year: The year to get recognition counts for.
445446
month: The month of the year to get recognition counts for.
446447
Vuforia accepts only the current month and the previous
447-
month.
448+
month. A month taken from a :class:`datetime.datetime` needs
449+
wrapping, as in ``calendar.Month(value=now.month)``.
448450
449451
Returns:
450452
The URL to download the report from, and the transaction ID of

tests/test_async_vws.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for async helper functions for managing a Vuforia database."""
22

33
import base64
4+
import calendar
45
import datetime # noqa: TC003
56
import io # noqa: TC003
67
import time
@@ -516,7 +517,7 @@ async def test_reco_counts_report(
516517
client = async_vws_client
517518
report_request = await client.request_database_reco_counts_report(
518519
year=report_month.year,
519-
month=report_month.month,
520+
month=calendar.Month(value=report_month.month),
520521
)
521522
assert report_request.transaction_id
522523
assert report_request.presigned_url
@@ -546,7 +547,7 @@ async def test_not_ready(*, current_month: datetime.date) -> None:
546547
report_request = (
547548
await client.request_database_reco_counts_report(
548549
year=current_month.year,
549-
month=current_month.month,
550+
month=calendar.Month(value=current_month.month),
550551
)
551552
)
552553

@@ -576,7 +577,7 @@ async def test_wait_timeout(*, current_month: datetime.date) -> None:
576577
report_request = (
577578
await client.request_database_reco_counts_report(
578579
year=current_month.year,
579-
month=current_month.month,
580+
month=calendar.Month(value=current_month.month),
580581
)
581582
)
582583

@@ -600,15 +601,19 @@ async def test_wait_timeout(*, current_month: datetime.date) -> None:
600601
@pytest.mark.parametrize(
601602
argnames=("year", "month"),
602603
argvalues=[
603-
pytest.param(1999, 1, id="month-in-the-past"),
604-
pytest.param(1999, 13, id="month-out-of-range"),
604+
pytest.param(1999, calendar.Month.JANUARY, id="year-in-the-past"),
605+
pytest.param(
606+
1999,
607+
calendar.Month.DECEMBER,
608+
id="year-in-the-past-december",
609+
),
605610
],
606611
)
607612
async def test_month_not_accepted(
608613
*,
609614
async_vws_client: AsyncVWS,
610615
year: int,
611-
month: int,
616+
month: calendar.Month,
612617
) -> None:
613618
"""Months other than the current and previous month are
614619
rejected.
@@ -643,7 +648,7 @@ async def test_database_id_does_not_match_keys(
643648
) as exc:
644649
await client.request_database_reco_counts_report(
645650
year=current_month.year,
646-
month=current_month.month,
651+
month=calendar.Month(value=current_month.month),
647652
)
648653

649654
assert (
@@ -681,7 +686,7 @@ async def test_no_database_id(*, current_month: datetime.date) -> None:
681686
with pytest.raises(expected_exception=DatabaseIdNotSetError):
682687
await client.request_database_reco_counts_report(
683688
year=current_month.year,
684-
month=current_month.month,
689+
month=calendar.Month(value=current_month.month),
685690
)
686691

687692

tests/test_vws.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for helper functions for managing a Vuforia database."""
22

33
import base64
4+
import calendar
45
import datetime
56
import io # noqa: TC003
67
import secrets
@@ -818,7 +819,7 @@ def test_reco_counts_report(
818819
"""A report can be requested, waited for and downloaded."""
819820
report_request = vws_client.request_database_reco_counts_report(
820821
year=report_month.year,
821-
month=report_month.month,
822+
month=calendar.Month(value=report_month.month),
822823
)
823824
assert report_request.transaction_id
824825
assert report_request.presigned_url
@@ -846,7 +847,7 @@ def test_not_ready(*, current_month: datetime.date) -> None:
846847
)
847848
report_request = vws_client.request_database_reco_counts_report(
848849
year=current_month.year,
849-
month=current_month.month,
850+
month=calendar.Month(value=current_month.month),
850851
)
851852

852853
with pytest.raises(
@@ -873,7 +874,7 @@ def test_wait_timeout(*, current_month: datetime.date) -> None:
873874
)
874875
report_request = vws_client.request_database_reco_counts_report(
875876
year=current_month.year,
876-
month=current_month.month,
877+
month=calendar.Month(value=current_month.month),
877878
)
878879

879880
maximum_wait_seconds = 5
@@ -895,15 +896,19 @@ def test_wait_timeout(*, current_month: datetime.date) -> None:
895896
@pytest.mark.parametrize(
896897
argnames=("year", "month"),
897898
argvalues=[
898-
pytest.param(1999, 1, id="month-in-the-past"),
899-
pytest.param(1999, 13, id="month-out-of-range"),
899+
pytest.param(1999, calendar.Month.JANUARY, id="year-in-the-past"),
900+
pytest.param(
901+
1999,
902+
calendar.Month.DECEMBER,
903+
id="year-in-the-past-december",
904+
),
900905
],
901906
)
902907
def test_month_not_accepted(
903908
*,
904909
vws_client: VWS,
905910
year: int,
906-
month: int,
911+
month: calendar.Month,
907912
) -> None:
908913
"""Months other than the current and previous month are
909914
rejected.
@@ -938,7 +943,7 @@ def test_database_id_does_not_match_keys(
938943
) as exc:
939944
vws_client.request_database_reco_counts_report(
940945
year=current_month.year,
941-
month=current_month.month,
946+
month=calendar.Month(value=current_month.month),
942947
)
943948

944949
assert exc.value.response.status_code == HTTPStatus.UNAUTHORIZED
@@ -974,7 +979,7 @@ def test_no_database_id(*, current_month: datetime.date) -> None:
974979
with pytest.raises(expected_exception=DatabaseIdNotSetError):
975980
vws_client.request_database_reco_counts_report(
976981
year=current_month.year,
977-
month=current_month.month,
982+
month=calendar.Month(value=current_month.month),
978983
)
979984

980985

0 commit comments

Comments
 (0)