Skip to content

Commit

Permalink
Fix #158 -- Modernize CI
Browse files Browse the repository at this point in the history
  • Loading branch information
caioariede committed Mar 21, 2023
1 parent 052adec commit c7022b1
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 121 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/ci.yaml
@@ -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
1 change: 0 additions & 1 deletion MANIFEST.in
Expand Up @@ -2,7 +2,6 @@ include LICENSE
include README.md

recursive-include location_field/static *
recursive-include location_field/contrib *.py
recursive-include location_field/forms *.py
recursive-include location_field/models *.py
recursive-include location_field/templates *.html
Expand Down
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -5,7 +5,7 @@ django-location-field

Let users pick locations using a map widget and store its latitude and longitude.

**Stable version:** [django-location-field==2.1.0](https://pypi.python.org/pypi/django-location-field/2.1.1)
**Stable version:** [django-location-field==2.1.1](https://pypi.python.org/pypi/django-location-field/2.1.1)
**Documentation:** [https://django-location-field.readthedocs.io/en/latest/](https://django-location-field.readthedocs.io/en/latest/)
**License:** MIT

Expand All @@ -27,8 +27,8 @@ Features
Compatibility
--

* Django >= 1.11
* Python 2.7, 3.6, 3.7
* Django: 1.11, 2.2, 3.2
* Python 2.7, 3.9, 3.10, 3.11

Spatial Databases
--
Expand Down
57 changes: 57 additions & 0 deletions conftest.py
@@ -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',
}
}
))
6 changes: 6 additions & 0 deletions pytest.ini
@@ -0,0 +1,6 @@
[pytest]
pythonpath = . tests
python_files = test.py spatial_test.py
django_find_project = false
addopts = --nomigrations --strict-markers
markers = spatial
4 changes: 2 additions & 2 deletions runtests.py
Expand Up @@ -8,13 +8,13 @@
sys.path.insert(0, test_dir)


import django
django.setup()


def runtests():
import django
from django.test.utils import get_runner
from django.conf import settings
django.setup()

TestRunner = get_runner(settings)
test_runner = TestRunner(verbosity=1, interactive=True)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
@@ -1,5 +1,5 @@
[metadata]
license-file = LICENSE
license_files = LICENSE

[wheel]
universal = 1
13 changes: 7 additions & 6 deletions setup.py
Expand Up @@ -28,16 +28,17 @@
"Operating System :: OS Independent",
"Framework :: Django",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
include_package_data=True,
install_requires=[
'Django>=1.7',
'six',
],
tests_require=[
'pyquery',
'six',
'pyquery<1.4',
],
test_suite="runtests.runtests",
)
10 changes: 10 additions & 0 deletions tests/models.py
@@ -1,4 +1,5 @@
from django.db import models
from django.conf import settings

from location_field.models.plain import PlainLocationField

Expand All @@ -12,3 +13,12 @@ class Place(models.Model):
)
city = models.CharField(max_length=255)
location = PlainLocationField(based_fields=['city'])


DATABASE_ENGINE = settings.DATABASES["default"]["ENGINE"]
if DATABASE_ENGINE == 'django.contrib.gis.db.backends.spatialite':
from location_field.models.spatial import LocationField
class SpatialPlace(models.Model):
parent_place = models.ForeignKey('self', blank=True, null=True, on_delete=models.SET_NULL)
city = models.CharField(max_length=255)
location = LocationField(based_fields=['city'], zoom=7)
9 changes: 0 additions & 9 deletions tests/spatial_models.py

This file was deleted.

24 changes: 12 additions & 12 deletions tests/spatial_test.py
@@ -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)
65 changes: 30 additions & 35 deletions tests/test.py
@@ -1,5 +1,5 @@
from django.test import TestCase
from django.conf import settings
import pytest

from location_field.apps import DefaultConfig

Expand All @@ -12,48 +12,43 @@
import location_field


class LocationFieldTest(TestCase):
def test_plain(self):
vals = {
'city': 'Bauru',
'location': '-22.2878573,-49.0905487',
}
@pytest.mark.django_db
def test_plain():
vals = {
'city': 'Bauru',
'location': '-22.2878573,-49.0905487',
}

obj = Place.objects.create(**vals)
obj = Place.objects.create(**vals)

self.assertEqual(obj.city, 'Bauru')
self.assertEqual(obj.location, '-22.2878573,-49.0905487')
assert obj.city == 'Bauru'
assert obj.location == '-22.2878573,-49.0905487'

def test_settings(self):
with self.settings(LOCATION_FIELD={'map.provider': 'foobar'}):
app_config = DefaultConfig('location_field', location_field)
app_config.patch_settings()
def test_settings(settings):
settings.LOCATION_FIELD={'map.provider': 'foobar'}
app_config = DefaultConfig('location_field', location_field)
app_config.patch_settings()

self.assertEqual(settings.LOCATION_FIELD.get('map.provider'),
'foobar')
assert settings.LOCATION_FIELD.get('map.provider') == 'foobar'

def test_field_options(self):
form = LocationForm(initial={})
d = pq(str(form))
@pytest.mark.django_db
def test_field_options(settings):
form = LocationForm(initial={})
d = pq(str(form))

opts = json.loads(d('[data-location-field-options]').attr(
'data-location-field-options'))
opts = json.loads(d('[data-location-field-options]').attr(
'data-location-field-options'))

location_field_opts = settings.LOCATION_FIELD
location_field_opts = settings.LOCATION_FIELD

for key, value in location_field_opts.items():
self.assertEqual(value, opts[key])
for key, value in location_field_opts.items():
assert value == opts[key]

def test_custom_resources(self):
form = LocationForm(initial={})
def test_custom_resources(settings):
form = LocationForm(initial={})

self.assertIn('form.js', str(form.media))
assert 'form.js' in str(form.media)

with self.settings(LOCATION_FIELD={
'resources.media': {'js': ['foo.js', 'bar.js']}}):
self.assertIn('foo.js', str(form.media))
self.assertIn('bar.js', str(form.media))


if settings.TEST_SPATIAL:
from . import spatial_test
settings.LOCATION_FIELD = {'resources.media': {'js': ['foo.js', 'bar.js']}}
assert 'foo.js' in str(form.media)
assert 'bar.js' in str(form.media)
82 changes: 40 additions & 42 deletions tests/test_settings.py
@@ -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',
# }
# }

0 comments on commit c7022b1

Please sign in to comment.