Skip to content

Commit ee0be69

Browse files
authored
tests: Adding Django test project (#447)
* tests: Adding Django test project
1 parent ee3885a commit ee0be69

17 files changed

Lines changed: 285 additions & 45 deletions

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repos:
2121
hooks:
2222
- id: mypy
2323
name: Mypy
24-
entry: poetry run mypy statemachine/ tests/
24+
entry: poetry run mypy --namespace-packages --explicit-package-bases statemachine/ tests/
2525
types: [python]
2626
language: system
2727
pass_filenames: false

conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
13
import pytest
24

35

@@ -21,3 +23,11 @@ def __init__(self):
2123
doctest_namespace["State"] = State
2224
doctest_namespace["StateMachine"] = StateMachine
2325
doctest_namespace["asyncio"] = ContribAsyncio()
26+
27+
28+
def pytest_ignore_collect(collection_path, path, config):
29+
if sys.version_info >= (3, 10): # noqa: UP036
30+
return None
31+
32+
if "django_project" in str(path):
33+
return True

poetry.lock

Lines changed: 82 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,21 @@ diagrams = ["pydot"]
3939
python = ">=3.7"
4040

4141
[tool.poetry.group.dev.dependencies]
42-
pytest = "*"
43-
pytest-cov = "*"
44-
pytest-sugar = "^1.0.0"
4542
pydot = "^2.0.0"
4643
ruff = "^0.4.8"
4744
pre-commit = "*"
4845
mypy = "*"
46+
47+
[tool.poetry.group.tests.dependencies]
48+
pytest = "*"
49+
pytest-cov = "*"
50+
pytest-sugar = "^1.0.0"
4951
pytest-mock = "^3.10.0"
5052
pytest-profiling = "^1.7.0"
5153
pytest-benchmark = "^4.0.0"
5254
pytest-asyncio = "*"
53-
sphinx-rtd-theme = "^2.0.0"
55+
django = { version = "^5.0.3", python = ">3.10" }
56+
pytest-django = { version = "^4.8.0", python = ">3.8" }
5457

5558
[tool.poetry.group.docs.dependencies]
5659
Sphinx = "*"
@@ -71,12 +74,14 @@ asyncio_mode = "auto"
7174
markers = [
7275
"""slow: marks tests as slow (deselect with '-m "not slow"')""",
7376
]
77+
python_files = ["tests.py", "test_*.py", "*_tests.py"]
7478

7579
[tool.mypy]
7680
python_version = "3.12"
7781
warn_return_any = true
7882
warn_unused_configs = true
7983
disable_error_code = "annotation-unchecked"
84+
mypy_path = "$MYPY_CONFIG_FILE_DIR/tests/django_project"
8085

8186
[[tool.mypy.overrides]]
8287
module = [

statemachine/registry.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import warnings
22

3+
from .utils import qualname
4+
35
try:
4-
_has_django = True
56
from django.utils.module_loading import autodiscover_modules
6-
except ImportError:
7+
except ImportError: # pragma: no cover
78
# Not a django project
8-
autodiscover_modules = None
9-
_has_django = False
9+
def autodiscover_modules(module_name: str):
10+
pass
1011

11-
from .utils import qualname
1212

1313
_REGISTRY = {}
1414
_initialized = False
@@ -39,8 +39,5 @@ def init_registry():
3939

4040

4141
def load_modules(modules=None):
42-
if not _has_django:
43-
return
44-
4542
for module in modules:
4643
autodiscover_modules(module)

tests/conftest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import sys
22
from datetime import datetime
3+
from typing import List
34

45
import pytest
56

7+
collect_ignore_glob: List[str] = []
8+
69
# We support Python 3.8+ positional only syntax
710
if sys.version_info[:2] < (3, 8): # noqa: UP036
8-
collect_ignore_glob = ["*_positional_only.py"]
11+
collect_ignore_glob.append("*_positional_only.py")
912

1013

1114
@pytest.fixture()

tests/django_project/app.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from django.http import HttpResponse
2+
from django.urls import re_path
3+
4+
5+
def home(request):
6+
return HttpResponse("WE LOVE DJANGO")
7+
8+
9+
urlpatterns = [
10+
re_path(r"^$", home, name="homepage"),
11+
]

tests/django_project/core/__init__,.py

Whitespace-only changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from pathlib import Path
2+
3+
BASE_DIR = Path(__file__).resolve().parent.parent
4+
5+
DEBUG = True
6+
7+
ROOT_URLCONF = "app"
8+
9+
INSTALLED_APPS = [
10+
"django.contrib.auth",
11+
"django.contrib.contenttypes",
12+
"django.contrib.sessions",
13+
"django.contrib.messages",
14+
"django.contrib.staticfiles",
15+
"workflow",
16+
]
17+
18+
DATABASES = {
19+
"default": {
20+
"ENGINE": "django.db.backends.sqlite3",
21+
"NAME": ":memory:",
22+
}
23+
}
24+
25+
WSGI_APPLICATION = "core.wsgi.application"

tests/django_project/core/wsgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for project project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")
15+
16+
application = get_wsgi_application()

0 commit comments

Comments
 (0)