conftest.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. # pylint: disable=import-private-name; tests
  22. from location_guessing_game_telegram_bot import _Photo
  23. @pytest.fixture(scope="session")
  24. def wikimap_export_path() -> pathlib.Path:
  25. return pathlib.Path(__file__).parent.joinpath(
  26. "resources",
  27. "wikimap.toolforge.org",
  28. "api.php@cat=Images_with_annotations&lang=de&year=2020-2020&region=48%7C12%7C47%7C13",
  29. )
  30. # pylint: disable=redefined-outer-name; fixture
  31. @pytest.fixture(scope="session")
  32. def wikimap_export(wikimap_export_path) -> pathlib.Path:
  33. try:
  34. return json.loads(wikimap_export_path.read_text())
  35. except json.decoder.JSONDecodeError as exc:
  36. if "git-lfs.github.com" in wikimap_export_path.read_text():
  37. raise ValueError("git-lfs pointers unresolved") from exc
  38. raise
  39. @pytest.fixture(scope="session")
  40. def wikimap_photos(wikimap_export) -> typing.List[_Photo]:
  41. return [_Photo.from_wikimap_export(attrs) for attrs in wikimap_export]