Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
052adec
commit c7022b1
Showing
14 changed files
with
212 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Python package | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python: ["3.8", "3.9", "3.10"] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python }} | ||
- name: Install tox and any other packages | ||
run: pip install tox | ||
- name: Run tox | ||
# Run tox using the version of Python in `PATH` | ||
run: tox -e py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from django.conf import settings | ||
import sys | ||
import pytest | ||
|
||
|
||
def pytest_addoption(parser): | ||
# https://docs.pytest.org/en/7.1.x/example/markers.html#custom-marker-and-command-line-option-to-control-test-runs | ||
parser.addoption("--test-spatial", action="store_true", default=False) | ||
|
||
|
||
def should_run_spatial(config): | ||
return config.getoption("--test-spatial") | ||
|
||
|
||
def pytest_runtest_setup(item): | ||
requires_spatial = any(mark.name == "spatial" for mark in item.iter_markers()) | ||
if requires_spatial: | ||
if not should_run_spatial(item.config): | ||
pytest.skip("cannot run without the --test-spatial parameter") | ||
|
||
|
||
def pytest_configure(config): | ||
COMMON_CONFIG = dict( | ||
STATIC_URL="", | ||
INSTALLED_APPS = [ | ||
"location_field", | ||
"tests", | ||
], | ||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'APP_DIRS': True, | ||
}, | ||
], | ||
) | ||
|
||
if sys.platform == 'darwin': | ||
COMMON_CONFIG['SPATIALITE_LIBRARY_PATH'] = '/usr/local/lib/mod_spatialite.dylib' | ||
|
||
if should_run_spatial(config): | ||
settings.configure(**dict(COMMON_CONFIG, | ||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.contrib.gis.db.backends.spatialite', | ||
'NAME': 'db.sqlite3', | ||
} | ||
} | ||
)) | ||
else: | ||
settings.configure(**dict(COMMON_CONFIG, | ||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': 'db.sqlite3', | ||
} | ||
} | ||
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[pytest] | ||
pythonpath = . tests | ||
python_files = test.py spatial_test.py | ||
django_find_project = false | ||
addopts = --nomigrations --strict-markers | ||
markers = spatial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[metadata] | ||
license-file = LICENSE | ||
license_files = LICENSE | ||
|
||
[wheel] | ||
universal = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
from django.test import TestCase | ||
from django.contrib.gis.geos import Point | ||
import pytest | ||
|
||
from tests.spatial_models import SpatialPlace | ||
@pytest.mark.spatial | ||
@pytest.mark.django_db | ||
def test_spatial(db): | ||
from tests.models import SpatialPlace | ||
|
||
vals = { | ||
'city': 'Bauru', | ||
'location': 'POINT(-22.2878573 -49.0905487)', | ||
} | ||
|
||
class LocationFieldSpatialTest(TestCase): | ||
def test_spatial(self): | ||
vals = { | ||
'city': 'Bauru', | ||
'location': 'POINT(-22.2878573 -49.0905487)', | ||
} | ||
obj = SpatialPlace.objects.create(**vals) | ||
|
||
obj = SpatialPlace.objects.create(**vals) | ||
|
||
self.assertEqual(obj.city, 'Bauru') | ||
self.assertEqual(obj.location, Point(-22.2878573, -49.0905487)) | ||
assert obj.city == 'Bauru' | ||
assert obj.location == Point(-22.2878573, -49.0905487, srid=4326) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,40 @@ | ||
import sys | ||
import os | ||
|
||
|
||
TEST_SPATIAL = 'TEST_SPATIAL' in os.environ | ||
|
||
|
||
SECRET_KEY = 'fake-key' | ||
|
||
INSTALLED_APPS = [ | ||
"location_field", | ||
"tests", | ||
] | ||
|
||
STATIC_URL = '/static/' | ||
|
||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'APP_DIRS': True, | ||
}, | ||
] | ||
|
||
|
||
if TEST_SPATIAL: | ||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.contrib.gis.db.backends.spatialite', | ||
'NAME': 'db.sqlite3', | ||
} | ||
} | ||
|
||
if sys.platform == 'darwin': | ||
SPATIALITE_LIBRARY_PATH = '/usr/local/lib/mod_spatialite.dylib' | ||
|
||
else: | ||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': 'db.sqlite3', | ||
} | ||
} | ||
# import sys | ||
# import os | ||
# | ||
# | ||
# TEST_SPATIAL = 'TEST_SPATIAL' in os.environ | ||
# | ||
# | ||
# SECRET_KEY = 'fake-key' | ||
# | ||
# INSTALLED_APPS = [ | ||
# "location_field", | ||
# "tests", | ||
# ] | ||
# | ||
# STATIC_URL = '/static/' | ||
# | ||
# TEMPLATES = [ | ||
# { | ||
# 'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
# 'APP_DIRS': True, | ||
# }, | ||
# ] | ||
# | ||
# if sys.platform == 'darwin': | ||
# SPATIALITE_LIBRARY_PATH = '/usr/local/lib/mod_spatialite.dylib' | ||
# | ||
# if TEST_SPATIAL: | ||
# DATABASES = { | ||
# 'default': { | ||
# 'ENGINE': 'django.contrib.gis.db.backends.spatialite', | ||
# 'NAME': 'db.sqlite3', | ||
# } | ||
# } | ||
# else: | ||
# DATABASES = { | ||
# 'default': { | ||
# 'ENGINE': 'django.db.backends.sqlite3', | ||
# 'NAME': 'db.sqlite3', | ||
# } | ||
# } |
Oops, something went wrong.