Skip to content

Commit

Permalink
allow setup.py to run tests
Browse files Browse the repository at this point in the history
  • Loading branch information
saxix committed Nov 26, 2015
1 parent 05a11f4 commit 748d2d6
Show file tree
Hide file tree
Showing 18 changed files with 212 additions and 50 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ develop:


demo:
PYTHONPATH=${PWD}:${PWD}/tests django-admin.py syncdb --settings=demo.settings --noinput
PYTHONPATH=${PWD}:${PWD}/tests django-admin.py loaddata adminactions.json demoproject.json --settings=demo.settings
PYTHONPATH=${PWD}:${PWD}/tests django-admin.py runserver --settings=demo.settings
PYTHONPATH=${PWD}:${PWD}/tests:${PWD}/src django-admin.py migrate --settings=demo.settings --noinput
PYTHONPATH=${PWD}:${PWD}/tests:${PWD}/src django-admin.py loaddata adminactions.json demoproject.json --settings=demo.settings
PYTHONPATH=${PWD}:${PWD}/tests:${PWD}/src django-admin.py runserver --settings=demo.settings


clean:
Expand Down
16 changes: 16 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python
import os, sys
here = os.path.abspath(os.path.join(os.path.dirname(__file__)))
rel = lambda *args: os.path.join(here, *args)

sys.path.insert(0, rel(os.pardir))


if __name__ == "__main__":
sys.path.insert(0, 'src')
sys.path.insert(0, 'tests')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demo.settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ignore = E501,E401,W391,E128,E261
[pytest]
python_paths=./src ./tests
DJANGO_SETTINGS_MODULE=demo.settings
norecursedirs = data .tox concurrency docs
norecursedirs = demo
addopts =
-p no:sugar
-p no:pep8
Expand All @@ -40,7 +40,7 @@ addopts =
--echo-version django

doctest_optionflags=
python_files=tests/test_*.py
python_files=tests/test_*.py tests/**/test_*.py
pep8ignore = * ALL
markers =
functional: mark a test as functional
69 changes: 63 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
#!/usr/bin/env python
from __future__ import absolute_import

import os
from setuptools import setup, find_packages
import sys
from distutils import log
from distutils.command.clean import clean as CleanCommand
from distutils.dir_util import remove_tree

from setuptools import find_packages, setup
from setuptools.command.test import test as TestCommand

# from adminactions import get_version, NAME

ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__)))
SOURCE=os.path.join(ROOT, 'src')
SOURCE = os.path.join(ROOT, 'src')
sys.path.append(SOURCE)
from adminactions import NAME, VERSION, get_version
app = __import__('adminactions')

rel = lambda fname: os.path.join(os.path.dirname(__file__),
'src',
Expand All @@ -19,6 +28,53 @@
reqs = 'install.py3.pip'


class Clean(CleanCommand):
user_options = CleanCommand.user_options + [
('build-coverage=', 'c',
"build directory for coverage output (default: 'build.build-coverage')"),
]

def initialize_options(self):
self.build_coverage = None
self.build_help = None
CleanCommand.initialize_options(self)

def run(self):
if self.all:
for directory in (os.path.join(self.build_base, 'coverage'),
os.path.join(self.build_base, 'help')):
if os.path.exists(directory):
remove_tree(directory, dry_run=self.dry_run)
else:
log.warn("'%s' does not exist -- can't clean it",
directory)
if self.build_coverage:
remove_tree(self.build_coverage, dry_run=self.dry_run)
if self.build_help:
remove_tree(self.build_help, dry_run=self.dry_run)
CleanCommand.run(self)


class PyTest(TestCommand):
user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]

def initialize_options(self):
TestCommand.initialize_options(self)
self.pytest_args = ['tests']

def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True

def run_tests(self):
# import here, cause outside the eggs aren't loaded
import pytest

errno = pytest.main(self.pytest_args)
sys.exit(errno)


def fread(fname):
return open(rel('install.any.pip')).read() + open(rel(fname)).read()

Expand All @@ -27,8 +83,8 @@ def fread(fname):
dev_require = fread('develop.pip')

setup(
name=NAME,
version=get_version(),
name=app.NAME,
version=app.get_version(),
url='https://github.com/saxix/django-adminactions',
download_url='https://github.com/saxix/django-adminactions',
author='sax',
Expand All @@ -38,6 +94,8 @@ def fread(fname):

package_dir={'': 'src'},
packages=find_packages('src'),
cmdclass={'test': PyTest,
'clean': Clean},

include_package_data=True,
install_requires=fread(reqs),
Expand All @@ -46,7 +104,6 @@ def fread(fname):
'test': tests_require,
'dev': dev_require + tests_require,
},
test_suite='conftest.runtests',
zip_safe=False,
platforms=['any'],
classifiers=[
Expand Down
4 changes: 2 additions & 2 deletions src/adminactions/mass_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ def _clean_fields(self):
def clean__validate(self):
return bool(self.data.get('_validate', 0))

def clean__unique_transaction(self):
return bool(self.data.get('_unique_transaction', 0))
# def clean__unique_transaction(self):
# return bool(self.data.get('_unique_transaction', 0))

def clean__clean(self):
return bool(self.data.get('_clean', 0))
Expand Down
2 changes: 1 addition & 1 deletion src/adminactions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def create_extra_permission(sender, **kwargs):
from django.db.models.signals import post_migrate

post_migrate.connect(create_extra_permission)
except:
except ImportError:
from django.db.models.signals import post_syncdb

post_syncdb.connect(create_extra_permission)
3 changes: 1 addition & 2 deletions src/adminactions/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

from adminactions.views import format_date

urlpatterns = patterns('',
url(r'^s/format/date/$', format_date, name='adminactions.format_date'))
urlpatterns = (url(r'^s/format/date/$', format_date, name='adminactions.format_date'),)
10 changes: 5 additions & 5 deletions tests/.coveragerc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[run]
branch = True
source = adminactions
include =
adminactions/**
#include =
# adminactions/**

omit = adminactions/__init__.py
adminactions/compat.py
omit = src/adminactions/__init__.py
src/adminactions/compat.py
tests/**

[report]
Expand All @@ -27,4 +27,4 @@ exclude_lines =
ignore_errors = True

[html]
directory = ~build/coverage
directory = build/coverage
16 changes: 8 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from demo.models import DemoModel


def pytest_configure(config):
try:
from django.apps import AppConfig # noqa
import django

django.setup()
except ImportError:
pass
# def pytest_configure(config):
# try:
# from django.apps import AppConfig # noqa
# import django
#
# django.setup()
# except ImportError:
# pass


@pytest.fixture(scope='function')
Expand Down
3 changes: 0 additions & 3 deletions tests/demo/fixtures/demoproject.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"float": 10.1,
"generic_ip": "192.168.10.1",
"url": "https://github.com/saxix/django-adminactions",
"ip": "192.168.10.1",
"decimal": "10.1",
"time": "09:18:35",
"blank": "",
Expand All @@ -33,7 +32,6 @@
"float": 10.1,
"generic_ip": "192.168.10.2",
"url": "https://github.com/saxix/django-adminactions",
"ip": "192.168.10.2",
"decimal": "22.2",
"time": "19:00:35",
"blank": "",
Expand All @@ -59,7 +57,6 @@
"float": 10.1,
"generic_ip": "192.168.10.2",
"url": "https://github.com/saxix/django-adminactions",
"ip": "192.168.10.2",
"decimal": "22.2",
"time": "19:00:35",
"blank": "",
Expand Down
52 changes: 52 additions & 0 deletions tests/demo/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9b1 on 2015-11-26 06:08
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='DemoModel',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('char', models.CharField(max_length=255, verbose_name='Ch\xe4\u0159')),
('integer', models.IntegerField()),
('logic', models.BooleanField(default=False)),
('null_logic', models.NullBooleanField(default=None)),
('date', models.DateField()),
('datetime', models.DateTimeField()),
('time', models.TimeField()),
('decimal', models.DecimalField(decimal_places=3, max_digits=10)),
('email', models.EmailField(max_length=254)),
('float', models.FloatField()),
('bigint', models.BigIntegerField()),
('generic_ip', models.GenericIPAddressField()),
('url', models.URLField()),
('text', models.TextField()),
('unique', models.CharField(max_length=255, unique=True)),
('nullable', models.CharField(max_length=255, null=True)),
('blank', models.CharField(blank=True, max_length=255, null=True)),
('not_editable', models.CharField(blank=True, editable=False, max_length=255, null=True)),
('choices', models.IntegerField(choices=[(1, 'Choice 1'), (2, 'Choice 2'), (3, 'Choice 3')])),
],
),
migrations.CreateModel(
name='UserDetail',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('note', models.CharField(blank=True, max_length=10)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
Empty file.
2 changes: 1 addition & 1 deletion tests/demo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DemoModel(models.Model):
# filepath = models.FilePathField(path=__file__)
float = models.FloatField()
bigint = models.BigIntegerField()
ip = models.IPAddressField()
# ip = models.IPAddressField()
generic_ip = models.GenericIPAddressField()
url = models.URLField()
text = models.TextField()
Expand Down
32 changes: 32 additions & 0 deletions tests/demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,30 @@
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)

TEMPLATES = [
{'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
# insert your TEMPLATE_DIRS here
],
'APP_DIRS': True,
'OPTIONS': {
'debug':DEBUG,
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
},
}
]

CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
Expand All @@ -102,3 +126,11 @@

ENABLE_SELENIUM = True

DATE_FORMAT = 'd-m-Y'
TIME_FORMAT = 'H:i'
DATETIME_FORMAT = 'd-m-Y H:i'
YEAR_MONTH_FORMAT = 'F Y'
MONTH_DAY_FORMAT = 'F j'
SHORT_DATE_FORMAT = 'm/d/Y'
SHORT_DATETIME_FORMAT = 'm/d/Y P'
FIRST_DAY_OF_WEEK = 1
14 changes: 6 additions & 8 deletions tests/demo/urls.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from __future__ import absolute_import
from django.contrib import admin
from django.conf.urls import patterns, include
from django.conf.urls import include, url
from adminactions import actions
import adminactions.urls


admin.autodiscover()
actions.add_to_site(admin.site)

urlpatterns = patterns('',
(r'admin/', include(admin.site.urls)),
(r'as/', include(adminactions.urls)),
(r'', include(admin.site.urls)),
)

urlpatterns = (
url(r'admin/', include(admin.site.urls)),
url(r'as/', include(adminactions.urls)),
url(r'', include(admin.site.urls)),
)
4 changes: 2 additions & 2 deletions tests/selenium_tests/test_export_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
pytestmark = pytest.mark.selenium


@pytest.mark.skipif('django.VERSION[:2]==(1,8)')
# @pytest.mark.skipif('django.VERSION[:2]==(1,8)')
def test_export_as_csv(admin_site):
browser, administrator = admin_site
browser.find_element_by_link_text("Demo models").click()
Expand Down Expand Up @@ -43,7 +43,7 @@ def _test(browser, target, format, sample_num):
assert sample.text == expected_value, "Failed Ajax call on %s" % target


@pytest.mark.skipif('django.VERSION[:2]==(1,8)')
# @pytest.mark.skipif('django.VERSION[:2]==(1,8)')
def test_datetime_format_ajax(export_csv_page):
browser, administrator = export_csv_page
_test(browser, "id_datetime_format", 'l, d F Y', 0)
Expand Down

0 comments on commit 748d2d6

Please sign in to comment.