conftest.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # location-guessing-game-telegram-bot - Telegram Bot Sending Random Wikimedia Commons Photos
  2. #
  3. # Copyright (C) 2021 Fabian Peter Hammerle <fabian@hammerle.me>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. import json
  18. import pathlib
  19. import typing
  20. import pytest
  21. from location_guessing_game_telegram_bot import _Photo
  22. @pytest.fixture(scope="session")
  23. def wikimap_export_path() -> pathlib.Path:
  24. return pathlib.Path(__file__).parent.joinpath(
  25. "resources",
  26. "wikimap.toolforge.org",
  27. "api.php@cat=Images_with_annotations&lang=de&year=2020-2020&region=48%7C12%7C47%7C13",
  28. )
  29. # pylint: disable=redefined-outer-name; fixture
  30. @pytest.fixture(scope="session")
  31. def wikimap_export(wikimap_export_path) -> pathlib.Path:
  32. try:
  33. return json.loads(wikimap_export_path.read_text())
  34. except json.decoder.JSONDecodeError as exc:
  35. if "git-lfs.github.com" in wikimap_export_path.read_text():
  36. raise ValueError("git-lfs pointers unresolved") from exc
  37. raise
  38. @pytest.fixture(scope="session")
  39. def wikimap_photos(wikimap_export) -> typing.List[_Photo]:
  40. return [_Photo.from_wikimap_export(attrs) for attrs in wikimap_export]