Mercurial > nosedjango
changeset 5:22ae9aa457af
excercise more bits of the django 1.0b1 test framework
author | Victor Ng <victor@monkeybean.ca> |
---|---|
date | Thu, 28 Aug 2008 11:29:21 -0400 |
parents | 20bca08c0828 |
children | 8d0793b2358b |
files | .hgignore examples/project/settings.py examples/project/zoo/__init__.py examples/project/zoo/fixtures/f1.json examples/project/zoo/fixtures/f2.json examples/project/zoo/test_doctest_modules.py examples/project/zoo/test_fixtures.py examples/project/zoo/test_foo.py examples/project/zoo/test_race.py nosedjango/__init__.py nosedjango/nosedjango.py setup.py |
diffstat | 12 files changed, 68 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Thu Aug 28 10:18:23 2008 -0400 +++ b/.hgignore Thu Aug 28 11:29:21 2008 -0400 @@ -2,6 +2,8 @@ *.orig *.pyc +*.swp +*.db *.egg-info build dist
--- a/examples/project/settings.py Thu Aug 28 10:18:23 2008 -0400 +++ b/examples/project/settings.py Thu Aug 28 11:29:21 2008 -0400 @@ -10,7 +10,7 @@ MANAGERS = ADMINS DATABASE_ENGINE = 'sqlite3' # 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'. -DATABASE_NAME = ':memory:' # Or path to database file if using sqlite3. +DATABASE_NAME = 'zoo.db' # Or path to database file if using sqlite3. #DATABASE_USER = '' # Not used with sqlite3. #DATABASE_PASSWORD = '' # Not used with sqlite3. #DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/project/zoo/__init__.py Thu Aug 28 11:29:21 2008 -0400 @@ -0,0 +1,1 @@ +# place holder
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/project/zoo/fixtures/f1.json Thu Aug 28 11:29:21 2008 -0400 @@ -0,0 +1,1 @@ +[{"pk": 1, "model": "zoo.zoo", "fields": {"name": "f1"}}]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/project/zoo/fixtures/f2.json Thu Aug 28 11:29:21 2008 -0400 @@ -0,0 +1,1 @@ +[{"pk": 1, "model": "zoo.zoo", "fields": {"name": "f2"}}]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/project/zoo/test_doctest_modules.py Thu Aug 28 11:29:21 2008 -0400 @@ -0,0 +1,13 @@ + +def test_regular_test_method(): + ''' This is just a stub for a regular test method''' + pass + +def blah(): + ''' + This is a doctest that might get skipped + + >>> 5 + 5 + 10 + ''' +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/project/zoo/test_fixtures.py Thu Aug 28 11:29:21 2008 -0400 @@ -0,0 +1,15 @@ +from project.zoo.models import * + +class TestFixture1(object): + fixtures = ['f1.json'] + + def test_count(self): + assert Zoo.objects.count() == 1 + assert Zoo.objects.get(id=1).name == 'f1' + + +class TestFixture2(object): + fixtures = ['f2.json'] + def test_count(self): + assert Zoo.objects.count() == 1 + assert Zoo.objects.get(id=1).name == 'f2'
--- a/examples/project/zoo/test_foo.py Thu Aug 28 10:18:23 2008 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ - -def test_regular_test_method(): - ''' This is just a stub for a regular test method''' - pass - -def blah(): - ''' - This is a doctest that might get skipped - - >>> 5 + 5 - 10 - '''
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/project/zoo/test_race.py Thu Aug 28 11:29:21 2008 -0400 @@ -0,0 +1,23 @@ +# We have two test classes because we want to induce a race condition +# and ensure that the database is always reset between test methods + +from zoo.models import * + +class TestDBRace1(object): + def setup(self): + assert Zoo.objects.count() == 0 + + def test1(self): + obj = Zoo.objects.create(name='sample1') + assert Zoo.objects.count() == 1 + assert Zoo.objects.all()[0].name == 'sample1' + + +class TestDBRace2(object): + def setup(self): + assert Zoo.objects.count() == 0 + + def test1(self): + obj = Zoo.objects.create(name='sample2') + assert Zoo.objects.count() == 1 + assert Zoo.objects.all()[0].name == 'sample2'
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nosedjango/__init__.py Thu Aug 28 11:29:21 2008 -0400 @@ -0,0 +1,1 @@ +# Just a place holder for Windows.
--- a/nosedjango/nosedjango.py Thu Aug 28 10:18:23 2008 -0400 +++ b/nosedjango/nosedjango.py Thu Aug 28 11:29:21 2008 -0400 @@ -4,7 +4,6 @@ are run, and tears the test database (or schema) down after all tests are run. """ -import logging import os, sys import re @@ -16,18 +15,25 @@ # the settings file from nose.importer import add_path os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' +import re +NT_ROOT = re.compile(r"^[a-zA-Z]:\\$") def get_SETTINGS_PATH(): + ''' + Hunt down the settings.py module by going up the FS path + ''' cwd = os.getcwd() while cwd: if 'settings.py' in os.listdir(cwd): break cwd = os.path.split(cwd)[0] - if cwd == '/': + if os.name == 'nt' and NT_ROOT.match(cwd): + return None + elif cwd == '/': return None return cwd + SETTINGS_PATH = get_SETTINGS_PATH() -log = logging.getLogger('nose.plugins.nosedjango') class NoseDjango(Plugin): """
--- a/setup.py Thu Aug 28 10:18:23 2008 -0400 +++ b/setup.py Thu Aug 28 11:29:21 2008 -0400 @@ -12,7 +12,7 @@ install_requires='nose>=0.10', url = "http://www.assembla.com/spaces/nosedjango", license = 'GNU LGPL', - packages = find_packages(exclude=['tests']), + packages = find_packages(), zip_safe = False, include_package_data = True, entry_points = {