Skip to content

Commit

Permalink
Add coverage re #11114
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls authored and chiatt committed Aug 6, 2024
1 parent 5cb1f72 commit 06ba1a7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
6 changes: 3 additions & 3 deletions arches/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

try:
import tomllib # Python 3.11+
except ImportError:
except ImportError: # pragma: no cover
# Python 3.10 depends on tomli instead
import tomli as tomllib

Expand Down Expand Up @@ -93,13 +93,13 @@ def check_arches_compatibility(app_configs, **kwargs):
except PackageNotFoundError:
# Not installed by pip: read pyproject.toml directly
toml_path = Path(config.path).parent / "pyproject.toml"
if not toml_path.exists():
if not toml_path.exists(): # pragma: no cover
raise ValueError
with open(toml_path, "rb") as f:
data = tomllib.load(f)
try:
project_requirements = data["project"]["dependencies"]
except KeyError:
except KeyError: # pragma: no cover
raise ValueError from None
try:
for requirement in project_requirements:
Expand Down
46 changes: 46 additions & 0 deletions tests/utils/test_checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from importlib.metadata import PackageNotFoundError
from unittest import mock

from django.apps import apps
from django.core.management import call_command
from django.core.management.base import SystemCheckError
from django.test import SimpleTestCase


# these tests can be run from the command line via
# python manage.py test tests.utils.test_checks.SystemCheckTests --settings="tests.test_settings"


def raise_package_not_found_error(name):
raise PackageNotFoundError


class SystemCheckTests(SimpleTestCase):
def test_compatibility(self):
"""Patch core arches to be an "arches application" so we can check
its range of compatible arches version, which it won't have.
"""

core_arches_appconfig = apps.get_app_config("arches")
core_arches_appconfig.is_arches_application = True
self.addCleanup(setattr, core_arches_appconfig, "is_arches_application", False)

# Test something pip-installed.
with self.assertRaisesMessage(
SystemCheckError, "Invalid or missing arches requirement"
):
call_command("check")

# Mock having to go to the pyproject.toml
with mock.patch("arches.apps.requires", raise_package_not_found_error):
with self.assertRaisesMessage(
SystemCheckError, "Invalid or missing arches requirement"
):
call_command("check")

# Mock an incompatible version requirement.
with mock.patch("arches.apps.requires", lambda app_name: ["arches==0.0.1"]):
with self.assertRaisesMessage(
SystemCheckError, "Incompatible arches requirement"
):
call_command("check")

0 comments on commit 06ba1a7

Please sign in to comment.