Skip to content

Commit

Permalink
Set up tests for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mbourqui committed Jul 10, 2017
1 parent 1aaa215 commit 242cfce
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 7 deletions.
Empty file added unitfield/tests/__init__.py
Empty file.
17 changes: 17 additions & 0 deletions unitfield/tests/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys

import django
from django.test.runner import DiscoverRunner

os.environ['DJANGO_SETTINGS_MODULE'] = 'unitfield.tests.settings'

if __name__ == "__main__":
# https://docs.djangoproject.com/en/1.8/topics/settings/#calling-django-setup-is-required-for-standalone-django-usage

django.setup()

sys.exit(DiscoverRunner(verbosity=1).run_tests(['unitfield']))
63 changes: 63 additions & 0 deletions unitfield/tests/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import os
from distutils.version import StrictVersion

import django
from django.conf import global_settings

BASE_DIR = os.path.dirname(__file__)

DEBUG = False

SECRET_KEY = 'm+qa*7_8t-=17zt_)9gi)4g%6w*v$xxkh6rwrys*bn9su+5%du'

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.staticfiles',
)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)

if StrictVersion(django.get_version()) < StrictVersion('1.10.0'):
MIDDLEWARE_CLASSES = MIDDLEWARE

LANGUAGE_CODE = 'en'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

SITE_ID = 1

USE_I18N = True

if hasattr(global_settings, 'TEMPLATE_CONTEXT_PROCESSORS'):
TEMPLATE_CONTEXT_PROCESSORS = tuple(global_settings.TEMPLATE_CONTEXT_PROCESSORS) + (
'django.core.context_processors.request',)
else:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
],
},
},
]
16 changes: 9 additions & 7 deletions unitfield/tests.py → unitfield/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.test import TestCase
from unitfield.units import Unit, UnitValue, get_choices


class UnitTest(TestCase):
def test_attribute_factor(self):
"""
Expand Down Expand Up @@ -30,6 +31,7 @@ def test_attribute_label(self):
e.label = u'metre'
self.assertEqual(e.label, u'metre')


class UnitValueTest(TestCase):
def test_attribute_input(self):
"""
Expand All @@ -55,10 +57,10 @@ def test_property_value(self):
multiplied by the unit factor (unit)
"""
testCases = [
{ 'params': [7.1, 0.1], 'result': 0.71 },
{ 'params': [0.1, 0.1], 'result': 0.01 },
{ 'params': [5, 0.01], 'result': 0.05 },
{ 'params': [2.4, 1000], 'result': 2400 },
{'params': [7.1, 0.1], 'result': 0.71},
{'params': [0.1, 0.1], 'result': 0.01},
{'params': [5, 0.01], 'result': 0.05},
{'params': [2.4, 1000], 'result': 2400},
]
for testCase in testCases:
uv = UnitValue(
Expand All @@ -72,9 +74,9 @@ def test_get_choices(self):
in the correct way
"""
a = [
Unit(0.001, 'mm', 'milimetre' ),
Unit(0.01, 'cm', 'centimetre'),
Unit(0.1, 'dm', 'decimetre' ),
Unit(0.001, 'mm', 'milimetre'),
Unit(0.01, 'cm', 'centimetre'),
Unit(0.1, 'dm', 'decimetre'),
]

b = [(0.001, 'mm'), (0.01, 'cm'), (0.1, 'dm')]
Expand Down

0 comments on commit 242cfce

Please sign in to comment.