advent-of-code-data 2.1.0__tar.gz → 2.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/PKG-INFO +7 -6
  2. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/advent_of_code_data.egg-info/PKG-INFO +7 -6
  3. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/advent_of_code_data.egg-info/requires.txt +4 -1
  4. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/aocd/__init__.py +2 -1
  5. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/aocd/cli.py +1 -1
  6. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/aocd/examples.py +5 -2
  7. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/aocd/get.py +5 -4
  8. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/aocd/models.py +34 -29
  9. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/aocd/runner.py +4 -2
  10. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/aocd/types.py +10 -2
  11. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/aocd/utils.py +3 -15
  12. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/pyproject.toml +5 -7
  13. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/tests/test_get_data.py +0 -54
  14. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/tests/test_models.py +56 -4
  15. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/tests/test_submit.py +44 -0
  16. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/LICENSE +0 -0
  17. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/README.md +0 -0
  18. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/advent_of_code_data.egg-info/SOURCES.txt +0 -0
  19. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/advent_of_code_data.egg-info/dependency_links.txt +0 -0
  20. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/advent_of_code_data.egg-info/entry_points.txt +0 -0
  21. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/advent_of_code_data.egg-info/top_level.txt +0 -0
  22. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/aocd/_ipykernel.py +0 -0
  23. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/aocd/cookies.py +0 -0
  24. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/aocd/exceptions.py +0 -0
  25. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/aocd/post.py +0 -0
  26. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/aocd/py.typed +0 -0
  27. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/setup.cfg +0 -0
  28. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/tests/test_aocd.py +0 -0
  29. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/tests/test_auth.py +0 -0
  30. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/tests/test_cli.py +0 -0
  31. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/tests/test_cookies.py +0 -0
  32. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/tests/test_date_finding.py +0 -0
  33. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/tests/test_date_introspection.py +0 -0
  34. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/tests/test_example_parser.py +0 -0
  35. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/tests/test_runner.py +0 -0
  36. {advent_of_code_data-2.1.0 → advent_of_code_data-2.2.0}/tests/test_utils.py +0 -0
@@ -1,26 +1,27 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: advent-of-code-data
3
- Version: 2.1.0
3
+ Version: 2.2.0
4
4
  Summary: Get your puzzle data with a single import
5
5
  Author-email: Wim Jeantine-Glenn <hey@wimglenn.com>
6
- License: MIT
6
+ License-Expression: MIT
7
7
  Project-URL: Homepage, https://github.com/wimglenn/advent-of-code-data
8
8
  Classifier: Intended Audience :: Developers
9
9
  Classifier: Programming Language :: Python :: 3
10
- Classifier: License :: OSI Approved :: MIT License
11
10
  Classifier: Topic :: Software Development :: Libraries
12
11
  Classifier: Topic :: Games/Entertainment :: Puzzle Games
13
- Requires-Python: >=3.9
12
+ Requires-Python: >=3.10
14
13
  Description-Content-Type: text/markdown
15
14
  License-File: LICENSE
16
15
  Requires-Dist: beautifulsoup4
17
16
  Requires-Dist: pebble
18
17
  Requires-Dist: urllib3
19
18
  Requires-Dist: tzdata; platform_system == "Windows"
20
- Requires-Dist: aocd-example-parser>=2023.12.24
19
+ Requires-Dist: aocd-example-parser>=2025.12.12
20
+ Requires-Dist: typing_extensions; python_version < "3.11"
21
21
  Provides-Extra: nb
22
22
  Requires-Dist: IPython; extra == "nb"
23
23
  Requires-Dist: jupyter-server; extra == "nb"
24
+ Dynamic: license-file
24
25
 
25
26
  [![pypi](https://img.shields.io/pypi/v/advent-of-code-data.svg)](https://pypi.org/project/advent-of-code-data/)
26
27
  [![actions](https://github.com/wimglenn/advent-of-code-data/actions/workflows/tests.yml/badge.svg)](https://github.com/wimglenn/advent-of-code-data/actions/workflows/tests.yml)
@@ -1,26 +1,27 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: advent-of-code-data
3
- Version: 2.1.0
3
+ Version: 2.2.0
4
4
  Summary: Get your puzzle data with a single import
5
5
  Author-email: Wim Jeantine-Glenn <hey@wimglenn.com>
6
- License: MIT
6
+ License-Expression: MIT
7
7
  Project-URL: Homepage, https://github.com/wimglenn/advent-of-code-data
8
8
  Classifier: Intended Audience :: Developers
9
9
  Classifier: Programming Language :: Python :: 3
10
- Classifier: License :: OSI Approved :: MIT License
11
10
  Classifier: Topic :: Software Development :: Libraries
12
11
  Classifier: Topic :: Games/Entertainment :: Puzzle Games
13
- Requires-Python: >=3.9
12
+ Requires-Python: >=3.10
14
13
  Description-Content-Type: text/markdown
15
14
  License-File: LICENSE
16
15
  Requires-Dist: beautifulsoup4
17
16
  Requires-Dist: pebble
18
17
  Requires-Dist: urllib3
19
18
  Requires-Dist: tzdata; platform_system == "Windows"
20
- Requires-Dist: aocd-example-parser>=2023.12.24
19
+ Requires-Dist: aocd-example-parser>=2025.12.12
20
+ Requires-Dist: typing_extensions; python_version < "3.11"
21
21
  Provides-Extra: nb
22
22
  Requires-Dist: IPython; extra == "nb"
23
23
  Requires-Dist: jupyter-server; extra == "nb"
24
+ Dynamic: license-file
24
25
 
25
26
  [![pypi](https://img.shields.io/pypi/v/advent-of-code-data.svg)](https://pypi.org/project/advent-of-code-data/)
26
27
  [![actions](https://github.com/wimglenn/advent-of-code-data/actions/workflows/tests.yml/badge.svg)](https://github.com/wimglenn/advent-of-code-data/actions/workflows/tests.yml)
@@ -1,11 +1,14 @@
1
1
  beautifulsoup4
2
2
  pebble
3
3
  urllib3
4
- aocd-example-parser>=2023.12.24
4
+ aocd-example-parser>=2025.12.12
5
5
 
6
6
  [:platform_system == "Windows"]
7
7
  tzdata
8
8
 
9
+ [:python_version < "3.11"]
10
+ typing_extensions
11
+
9
12
  [nb]
10
13
  IPython
11
14
  jupyter-server
@@ -2,6 +2,7 @@ import json
2
2
  import os
3
3
  import sys
4
4
  import typing as t
5
+ from collections.abc import Callable
5
6
  from functools import partial
6
7
 
7
8
  from . import _ipykernel
@@ -44,7 +45,7 @@ if t.TYPE_CHECKING:
44
45
  data: str
45
46
  extra: dict[str, t.Any]
46
47
  puzzle: models.Puzzle
47
- submit = _impartial_submit
48
+ submit: Callable = _impartial_submit
48
49
 
49
50
 
50
51
  def __getattr__(name: str) -> t.Any:
@@ -30,7 +30,7 @@ def main() -> None:
30
30
  "day",
31
31
  nargs="?",
32
32
  type=int,
33
- default=min(aoc_now.day, 25) if aoc_now.month == 12 else 1,
33
+ default=min(aoc_now.day, 25 if aoc_now.year < 2025 else 12) if aoc_now.month == 12 else 1,
34
34
  help="1-25 (default: %(default)s)",
35
35
  )
36
36
  parser.add_argument(
@@ -228,6 +228,8 @@ def main() -> None:
228
228
  table.add_column("Extra")
229
229
  missing = Example("")
230
230
  for day in range(1, 26):
231
+ if year >= 2025 and day > 12:
232
+ break
231
233
  puzzle = models.Puzzle(year, day)
232
234
  if datetime.now(tz=AOC_TZ) < puzzle.unlock_time(local=False):
233
235
  break
@@ -282,9 +284,10 @@ def main() -> None:
282
284
  row[4] += f"\n(correct: {correct.answer_a})"
283
285
  wrong += inc
284
286
 
285
- if day < 25 and part_b_locked and i5:
287
+ _not_final_day = (day < 12) if year >= 2025 else (day < 25)
288
+ if _not_final_day and part_b_locked and i5:
286
289
  row[5] = "❓"
287
- elif day < 25 or scraped.answer_b:
290
+ elif _not_final_day or scraped.answer_b:
288
291
  row[5] = "❌✅"[i5] + f" {_trunc(scraped.answer_b)}"
289
292
  count += inc
290
293
  if not i5:
@@ -67,9 +67,7 @@ def get_puzzle(
67
67
  raise
68
68
  q = block == "q"
69
69
  blocker(quiet=q, until=(year, day))
70
- return puzzle
71
- else:
72
- return puzzle
70
+ return puzzle
73
71
 
74
72
 
75
73
  def most_recent_year() -> int:
@@ -96,7 +94,10 @@ def current_day() -> int:
96
94
  if aoc_now.month != 12:
97
95
  log.warning("current_day is only available in December (EST)")
98
96
  return 1
99
- day = min(aoc_now.day, 25)
97
+ if aoc_now.year < 2025:
98
+ day = min(aoc_now.day, 25)
99
+ else:
100
+ day = min(aoc_now.day, 12)
100
101
  return day
101
102
 
102
103
 
@@ -64,6 +64,7 @@ class User:
64
64
  def from_id(cls, id: str) -> User:
65
65
  users = _load_users()
66
66
  if id not in users:
67
+ log.warning("The known user ids are:\n%s", "\n".join(f"- {u}" for u in users))
67
68
  raise UnknownUserError(f"User with id '{id}' is not known")
68
69
  user = cls(users[id])
69
70
  user._owner = id
@@ -149,18 +150,16 @@ class User:
149
150
  vals = line.split()
150
151
  day = int(vals[0])
151
152
  k = f"{year}/{day:02d}"
152
- results[k] = {}
153
- results[k]["a"] = {
154
- "time": _parse_duration(vals[1]),
155
- "rank": int(vals[2]),
156
- "score": int(vals[3]),
157
- }
158
- if vals[4] != "-":
159
- results[k]["b"] = {
160
- "time": _parse_duration(vals[4]),
161
- "rank": int(vals[5]),
162
- "score": int(vals[6]),
163
- }
153
+ results[k] = {"a": {"time": _parse_duration(vals[1])}}
154
+ if year < 2025:
155
+ results[k]["a"]["rank"] = int(vals[2])
156
+ results[k]["a"]["score"] = int(vals[3])
157
+ del vals[2:4]
158
+ if vals[2] != "-":
159
+ results[k]["b"] = {"time": _parse_duration(vals[2])}
160
+ if year < 2025:
161
+ results[k]["b"]["rank"] = int(vals[3])
162
+ results[k]["b"]["score"] = int(vals[4])
164
163
  return results
165
164
 
166
165
 
@@ -220,7 +219,7 @@ class Puzzle:
220
219
  # this is a property to make it clear that it's read-only
221
220
  return self._user
222
221
 
223
- @property
222
+ @cached_property
224
223
  def input_data(self) -> str:
225
224
  """
226
225
  This puzzle's input data, specific to puzzle.user. It will usually be retrieved
@@ -532,17 +531,18 @@ class Puzzle:
532
531
  part_b_url = self.url + "#part2"
533
532
  log.info("reopening to %s", part_b_url)
534
533
  webbrowser.open(part_b_url)
535
- if not (self.day == 25 and part == "b"):
534
+ if not (self._is_final_day and part == "b"):
536
535
  self._save_correct_answer(value=value, part=part)
537
- if self.day == 25 and part == "a":
538
- log.debug("checking if got 49 stars already for year %s...", self.year)
536
+ if self._is_final_day and part == "a":
537
+ max_stars = 50 if self.year < 2025 else 24
538
+ log.debug("checking if got %d stars already for year %s...", max_stars - 1, self.year)
539
539
  my_stats = self.user.get_stats(self.year)
540
540
  n_stars = sum(len(val) for val in my_stats.values())
541
- if n_stars == 49:
542
- log.info("Got 49 stars already, getting 50th...")
541
+ if n_stars == max_stars - 1:
542
+ log.info("Got %d stars already, getting %dth...", max_stars - 1, max_stars)
543
543
  self._submit(value="done", part="b", reopen=reopen, quiet=quiet)
544
544
  else:
545
- rem = 49 - n_stars
545
+ rem = max_stars - 1 - n_stars
546
546
  log.info("Got %d stars, need %d more for part b", n_stars, rem)
547
547
  elif "Did you already complete it" in message:
548
548
  color = "yellow"
@@ -567,6 +567,8 @@ class Puzzle:
567
567
  log.info("Waiting %d seconds to autoretry", wait_time)
568
568
  time.sleep(wait_time)
569
569
  return self._submit(value=value, part=part, reopen=reopen, quiet=quiet)
570
+ elif self._is_final_day and part == "b" and "You've finished every puzzle " in message:
571
+ log.info("Final day congrats message: %s", message)
570
572
  else:
571
573
  log.warning("Unrecognised submit message %r", message)
572
574
  if not quiet:
@@ -633,7 +635,7 @@ class Puzzle:
633
635
  Note: Answers are only revealed after a correct submission. If you've
634
636
  not already solved the puzzle, PuzzleUnsolvedError will be raised.
635
637
  """
636
- if part == "b" and self.day == 25:
638
+ if self._is_final_day and part == "b":
637
639
  return ""
638
640
  answer_path = getattr(self, f"answer_{part}_path")
639
641
  if answer_path.is_file():
@@ -718,7 +720,7 @@ class Puzzle:
718
720
  _ensure_intermediate_dirs(self.prose2_path)
719
721
  self.prose2_path.write_text(text, encoding="utf-8")
720
722
  hits = [p for p in soup.find_all("p") if p.text.startswith(hit)]
721
- if self.day == 25:
723
+ if self._is_final_day:
722
724
  [pa] = hits
723
725
  self._save_correct_answer(pa.code.text, "a")
724
726
  else:
@@ -772,12 +774,12 @@ class Puzzle:
772
774
  def easter_eggs(self) -> list[str]:
773
775
  """
774
776
  Return a list of Easter eggs in the puzzle's description page. When you've
775
- completed all 25 days, adventofcode.com will reveal the Easter eggs directly in
777
+ completed all days, adventofcode.com will reveal the Easter eggs directly in
776
778
  the html, but this property works even if all days haven't been completed yet.
777
779
  Most puzzles have exactly one Easter egg, but 2018-12-17 had two, so this
778
780
  property always returns a list for consistency.
779
781
  """
780
- txt = self._get_prose()
782
+ txt = self._get_prose(force_precheck=True)
781
783
  soup = _get_soup(txt)
782
784
  eggs = soup.find_all(["span", "em", "code"], class_=None, attrs={"title": bool})
783
785
  return eggs
@@ -794,6 +796,12 @@ class Puzzle:
794
796
  result = result.astimezone(tz=localzone)
795
797
  return result
796
798
 
799
+ @property
800
+ def _is_final_day(self) -> bool:
801
+ if self.year >= 2025:
802
+ return self.day == 12
803
+ return self.day == 25
804
+
797
805
  @staticmethod
798
806
  def all(user: User | None = None) -> t.Iterator[Puzzle]:
799
807
  """
@@ -801,6 +809,8 @@ class Puzzle:
801
809
  """
802
810
  for year in count(2015):
803
811
  for day in range(1, 26):
812
+ if year >= 2025 and day > 12:
813
+ break
804
814
  puzzle = Puzzle(year, day, user)
805
815
  if datetime.now(tz=AOC_TZ) < puzzle.unlock_time(local=False):
806
816
  return
@@ -829,12 +839,7 @@ def _load_users():
829
839
  @cache
830
840
  def _load_example_parser(group="adventofcode.examples", name="reference"):
831
841
  # lazy-loads a plugin used to parse sample data, and cache it
832
- try:
833
- # Python 3.10+ - group/name selectable entry points
834
- eps = entry_points().select(group=group, name=name)
835
- except AttributeError:
836
- # Python 3.9 - dict interface
837
- eps = [ep for ep in entry_points()[group] if ep.name == name]
842
+ eps = entry_points().select(group=group, name=name)
838
843
  if not eps:
839
844
  msg = f"could not find the example parser plugin {group=}/{name=}"
840
845
  raise ExampleParserError(msg)
@@ -337,6 +337,8 @@ def run_for(
337
337
  for year, day, plugin in matrix:
338
338
  if year == aoc_now.year and day > aoc_now.day:
339
339
  continue
340
+ if year >= 2025 and day > 12:
341
+ continue
340
342
  entry_point = eps[plugin]
341
343
  puzzle = Puzzle(year, day)
342
344
  if example:
@@ -381,8 +383,8 @@ def run_for(
381
383
  line += f" {icon} {error}"
382
384
  else:
383
385
  for answer, part in zip((a, b), "ab"):
384
- if day == 25 and part == "b":
385
- # there's no part b on Christmas day, skip
386
+ if part == "b" and (day == 25 or (year >= 2025 and day == 12)):
387
+ # there's no part b on the final day, skip
386
388
  continue
387
389
  expected = None
388
390
  try:
@@ -1,10 +1,16 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import sys
3
4
  from datetime import timedelta
4
5
  from typing import Any
5
6
  from typing import Literal
6
7
  from typing import TypedDict
7
8
 
9
+ if sys.version_info < (3, 11):
10
+ from typing_extensions import NotRequired
11
+ else:
12
+ from typing import NotRequired
13
+
8
14
 
9
15
  AnswerValue = Any
10
16
  """The answer to a puzzle, either a string or a number. Numbers are coerced to a string"""
@@ -16,11 +22,13 @@ class PuzzleStats(TypedDict):
16
22
  """Your personal stats for a given puzzle
17
23
 
18
24
  See https://adventofcode.com/<year>/leaderboard/self when logged in.
25
+
26
+ Since 2025, "rank" and "score" are no longer provided.
19
27
  """
20
28
 
21
29
  time: timedelta
22
- rank: int
23
- score: int
30
+ rank: NotRequired[int]
31
+ score: NotRequired[int]
24
32
 
25
33
 
26
34
  class Submission(TypedDict):
@@ -15,6 +15,7 @@ from decimal import Decimal
15
15
  from fractions import Fraction
16
16
  from functools import cache
17
17
  from importlib.metadata import entry_points
18
+ from importlib.metadata import EntryPoints
18
19
  from importlib.metadata import version
19
20
  from itertools import cycle
20
21
  from pathlib import Path
@@ -27,14 +28,6 @@ import urllib3
27
28
  from .exceptions import CoercionError
28
29
  from .exceptions import DeadTokenError
29
30
 
30
- if sys.version_info >= (3, 10):
31
- # Python 3.10+
32
- from importlib.metadata import EntryPoints as _EntryPointsType
33
- else:
34
- # Python 3.9
35
- from importlib.metadata import EntryPoint
36
-
37
- _EntryPointsType = list[EntryPoint]
38
31
 
39
32
  log: logging.Logger = logging.getLogger(__name__)
40
33
  AOC_TZ = ZoneInfo("America/New_York")
@@ -255,16 +248,11 @@ def colored(txt: str, color: _ANSIColor | None) -> str:
255
248
  return f"\x1b[{code + 30}m{txt}{reset}"
256
249
 
257
250
 
258
- def get_plugins(group: str = "adventofcode.user") -> _EntryPointsType:
251
+ def get_plugins(group: str = "adventofcode.user") -> EntryPoints:
259
252
  """
260
253
  Currently installed plugins for user solves.
261
254
  """
262
- try:
263
- # Python 3.10+
264
- return entry_points(group=group)
265
- except TypeError:
266
- # Python 3.9
267
- return entry_points().get(group, [])
255
+ return entry_points(group=group)
268
256
 
269
257
 
270
258
  @cache
@@ -4,14 +4,14 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "advent-of-code-data"
7
- version = "2.1.0"
7
+ version = "2.2.0"
8
8
  description = "Get your puzzle data with a single import"
9
9
  readme = "README.md"
10
- requires-python = ">=3.9"
10
+ license = "MIT"
11
+ requires-python = ">=3.10"
11
12
  classifiers = [
12
13
  "Intended Audience :: Developers",
13
14
  "Programming Language :: Python :: 3",
14
- "License :: OSI Approved :: MIT License",
15
15
  "Topic :: Software Development :: Libraries",
16
16
  "Topic :: Games/Entertainment :: Puzzle Games",
17
17
  ]
@@ -20,16 +20,14 @@ dependencies = [
20
20
  "pebble",
21
21
  "urllib3",
22
22
  'tzdata ; platform_system == "Windows"',
23
- "aocd-example-parser >= 2023.12.24",
23
+ "aocd-example-parser >= 2025.12.12",
24
+ 'typing_extensions ; python_version < "3.11"',
24
25
  ]
25
26
 
26
27
  [[project.authors]]
27
28
  name = "Wim Jeantine-Glenn"
28
29
  email = "hey@wimglenn.com"
29
30
 
30
- [project.license]
31
- text = "MIT"
32
-
33
31
  [project.urls]
34
32
  Homepage = "https://github.com/wimglenn/advent-of-code-data"
35
33
 
@@ -1,7 +1,4 @@
1
- import io
2
1
  import logging
3
- import os
4
- import threading
5
2
  from importlib.metadata import version
6
3
 
7
4
  import pytest
@@ -124,54 +121,3 @@ def test_corrupted_cache(aocd_data_dir):
124
121
  cached.mkdir(parents=True)
125
122
  with pytest.raises(OSError):
126
123
  aocd.get_data(year=2018, day=1)
127
-
128
-
129
- def test_race_on_download_data(mocker, aocd_data_dir, pook):
130
- pook.get(
131
- url="https://adventofcode.com/2018/day/1/input",
132
- response_body="fake data for year 2018 day 1",
133
- times=2,
134
- )
135
- open_evt = threading.Event()
136
- write_evt = threading.Event()
137
-
138
- real_os_open = os.open
139
- fds = {}
140
-
141
- def logging_os_open(path, *args, **kwargs):
142
- ret = real_os_open(path, *args, **kwargs)
143
- fds[ret] = path
144
- return ret
145
-
146
- mocker.patch("os.open", side_effect=logging_os_open)
147
-
148
- # This doesn't use unittest.mock_open because we actually do want the faked object to be functional.
149
- # We don't want fake results or to assert things are called in a certain order; we just want the
150
- # write operation to be slow.
151
- def generate_open(real_open):
152
- def open_impl(file, *args, **kwargs):
153
- res = real_open(file, *args, **kwargs)
154
- filename = fds[file] if isinstance(file, int) else file
155
- if "aocd-data" not in str(filename):
156
- return res
157
- open_evt.set()
158
- real_write = res.write
159
-
160
- def write(*args, **kwargs):
161
- write_evt.wait()
162
- real_write(*args, **kwargs)
163
-
164
- res.write = write
165
- return res
166
-
167
- return open_impl
168
-
169
- mocker.patch("io.open", side_effect=generate_open(io.open))
170
-
171
- t = threading.Thread(target=aocd.get_data, kwargs={"year": 2018, "day": 1})
172
- t.start()
173
- open_evt.wait()
174
- mocker.stopall()
175
- data = aocd.get_data(year=2018, day=1)
176
- write_evt.set()
177
- assert data == "fake data for year 2018 day 1"
@@ -235,6 +235,34 @@ def test_get_stats(pook):
235
235
  }
236
236
 
237
237
 
238
+ fake_stats_response_2025 = """
239
+ <article><p>These are your personal leaderboard times:</p>
240
+ <pre>Day <span class="leaderboard-daydesc-first">-Part 1-</span>
241
+ <span class="leaderboard-daydesc-both">-Part 2-</span>
242
+ 2 00:05:42 -
243
+ 1 00:06:31 00:31:28
244
+ </pre>
245
+ </article>
246
+ """
247
+
248
+
249
+ def test_get_stats_2025(pook):
250
+ puzzle1 = Puzzle(year=2025, day=1)
251
+ puzzle2 = Puzzle(year=2025, day=2)
252
+ pook.get(
253
+ url="https://adventofcode.com/2025/leaderboard/self",
254
+ response_body=fake_stats_response_2025,
255
+ times=2,
256
+ )
257
+ assert puzzle1.my_stats == {
258
+ "a": {"time": timedelta(minutes=6, seconds=31)},
259
+ "b": {"time": timedelta(minutes=31, seconds=28)},
260
+ }
261
+ assert puzzle2.my_stats == {
262
+ "a": {"time": timedelta(minutes=5, seconds=42)},
263
+ }
264
+
265
+
238
266
  def test_get_stats_when_token_expired(pook):
239
267
  # sadly, it just returns the global leaderboard, rather than a http 4xx
240
268
  user = User("token12345678")
@@ -311,6 +339,30 @@ def test_easter_eggs(pook):
311
339
  assert egg.attrs["title"] == "Later, on its turn, it sends you a sorcery."
312
340
 
313
341
 
342
+ def test_easter_eggs_cache(pook):
343
+ pook.get(
344
+ url="https://adventofcode.com/2025/day/1",
345
+ response_body=(
346
+ "Advent of Code"
347
+ '<article class="day-desc">'
348
+ "<h2>--- Day 1: Secret Entrance ---</h2>"
349
+ "The first half of this puzzle is complete!"
350
+ "<p>Your puzzle answer was <code>answerA</code></p>"
351
+ '<p><em>password method <span title="You should have seen the chaos">'
352
+ "0x434C49434B</span></em></p>"
353
+ )
354
+ )
355
+ puzzle = Puzzle(2025, 1)
356
+ puzzle.prose0_path.parent.mkdir(parents=True, exist_ok=True)
357
+ puzzle.prose0_path.write_text("no egg")
358
+ assert not puzzle.prose1_path.exists()
359
+ [egg] = puzzle.easter_eggs
360
+ assert puzzle.prose1_path.exists()
361
+ assert not puzzle.prose2_path.exists()
362
+ assert egg.text == "0x434C49434B"
363
+ assert egg.attrs["title"] == "You should have seen the chaos"
364
+
365
+
314
366
  def test_get_stats_400(pook):
315
367
  url = "https://adventofcode.com/2015/leaderboard/self"
316
368
  pook.get(url, reply=400)
@@ -471,14 +523,14 @@ def test_unlock_time(pook):
471
523
 
472
524
 
473
525
  def test_all_puzzles(freezer):
474
- freezer.move_to("2017-10-10")
526
+ freezer.move_to("2025-12-16")
475
527
  all_puzzles = list(Puzzle.all())
476
- assert len(all_puzzles) == 50
528
+ assert len(all_puzzles) == 262
477
529
  first, *rest, last = all_puzzles
478
530
  assert first.year == 2015
479
531
  assert first.day == 1
480
- assert last.year == 2016
481
- assert last.day == 25
532
+ assert last.year == 2025
533
+ assert last.day == 12
482
534
 
483
535
 
484
536
  def test_submit_prevents_bad_guesses_too_high(freezer, capsys, pook):
@@ -282,3 +282,47 @@ def test_submit_float_warns(pook, capsys, caplog):
282
282
  assert post.calls == 1
283
283
  record = ("aocd.utils", logging.WARNING, "coerced float value 1234.0 to '1234'")
284
284
  assert record in caplog.record_tuples
285
+
286
+
287
+ full_stats_resp = """
288
+ <article><p>These are your personal leaderboard times:</p>
289
+ <pre>Day <span class="leaderboard-daydesc-first">-Part 1-</span>
290
+ <span class="leaderboard-daydesc-both">-Part 2-</span>
291
+ 12 00:25:52 -
292
+ 11 00:05:52 02:14:30
293
+ 10 00:45:22 17:13:51
294
+ 9 00:05:54 03:23:40
295
+ 8 00:44:46 00:48:51
296
+ 7 00:30:35 00:55:12
297
+ 6 03:43:07 03:58:49
298
+ 5 00:03:18 00:08:43
299
+ 4 00:03:12 00:04:49
300
+ 3 00:02:59 00:20:44
301
+ 2 00:05:42 00:10:48
302
+ 1 00:06:31 00:31:28
303
+ </pre>
304
+ </article>
305
+ """
306
+
307
+
308
+ def test_submit_on_final_day(pook):
309
+ post1 = pook.post(
310
+ url="https://adventofcode.com/2025/day/12/answer",
311
+ content="application/x-www-form-urlencoded",
312
+ body="level=1&answer=1234",
313
+ response_body="<article>That's the right answer. Yeah!!</article>",
314
+ )
315
+ stats = pook.get(
316
+ url="https://adventofcode.com/2025/leaderboard/self",
317
+ response_body=full_stats_resp,
318
+ )
319
+ post2 = pook.post(
320
+ url="https://adventofcode.com/2025/day/12/answer",
321
+ content="application/x-www-form-urlencoded",
322
+ body="level=2&answer=done",
323
+ response_body="<article>You've finished every puzzle </article>",
324
+ )
325
+ submit(1234, part="a", day=12, year=2025, session="whatever", reopen=False)
326
+ assert post1.calls == 1
327
+ assert stats.calls == 1
328
+ assert post2.calls == 1