mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Upgrade test runner to derive from DiscoveryRunner.
This commit is contained in:
parent
f075bcf297
commit
c03bac5efd
10 changed files with 67 additions and 97 deletions
|
|
@ -6,5 +6,5 @@ script:
|
|||
- evennia --init dummy
|
||||
- cd dummy
|
||||
- evennia migrate
|
||||
- evennia test
|
||||
- evennia test evennia
|
||||
|
||||
|
|
|
|||
|
|
@ -13,15 +13,17 @@ main test suite started with
|
|||
"""
|
||||
|
||||
import re
|
||||
|
||||
from django.conf import settings
|
||||
from mock import Mock
|
||||
from evennia.commands.default.cmdset_character import CharacterCmdSet
|
||||
|
||||
from evennia.tests.resources import EvenniaTest
|
||||
from evennia.commands.default.cmdset_character import CharacterCmdSet
|
||||
from evennia.utils.test_resources import EvenniaTest
|
||||
from evennia.commands.default import help, general, system, admin, player, building, batchprocess, comms
|
||||
from evennia.utils import ansi
|
||||
from evennia.server.sessionhandler import SESSIONS
|
||||
|
||||
|
||||
# set up signal here since we are not starting the server
|
||||
|
||||
_RE = re.compile(r"^\+|-+\+|\+-+|--*|\|", re.MULTILINE)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ the stability and integrity of the codebase during updates.
|
|||
This module tests the lock functionality of Evennia.
|
||||
|
||||
"""
|
||||
from evennia.tests.resources import EvenniaTest
|
||||
from evennia.utils.test_resources import EvenniaTest
|
||||
|
||||
try:
|
||||
# this is a special optimized Django version, only available in current Django devel
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@ from django.utils.unittest import TestCase
|
|||
from evennia.scripts.models import ScriptDB, ObjectDoesNotExist
|
||||
from evennia.utils.create import create_script
|
||||
from evennia.scripts.scripts import DoNothing
|
||||
import unittest
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class TestScriptDB(TestCase):
|
||||
|
|
@ -29,12 +29,10 @@ try:
|
|||
except ImportError:
|
||||
import unittest
|
||||
|
||||
from django.conf import settings
|
||||
from django.test.simple import DjangoTestSuiteRunner
|
||||
from evennia.utils.utils import mod_import
|
||||
from django.test.runner import DiscoverRunner
|
||||
|
||||
|
||||
class EvenniaTestSuiteRunner(DjangoTestSuiteRunner):
|
||||
class EvenniaTestSuiteRunner(DiscoverRunner):
|
||||
"""
|
||||
This test runner only runs tests on the apps specified in evennia/
|
||||
avoid running the large number of tests defined by Django
|
||||
|
|
@ -46,32 +44,4 @@ class EvenniaTestSuiteRunner(DjangoTestSuiteRunner):
|
|||
"""
|
||||
import evennia
|
||||
evennia.init()
|
||||
if not test_labels:
|
||||
test_labels = [applabel.rsplit('.', 1)[1] for applabel in settings.INSTALLED_APPS
|
||||
if applabel.startswith('evennia.')]
|
||||
return super(EvenniaTestSuiteRunner, self).build_suite(test_labels, extra_tests=extra_tests, **kwargs)
|
||||
|
||||
|
||||
def suite():
|
||||
"""
|
||||
This function is called automatically by the django test runner.
|
||||
This also collates tests from packages that are not formally django applications.
|
||||
"""
|
||||
from evennia.locks import tests as locktests
|
||||
from evennia.utils import tests as utiltests
|
||||
from evennia.commands.default import tests as commandtests
|
||||
|
||||
tsuite = unittest.TestSuite()
|
||||
tsuite.addTest(unittest.defaultTestLoader.loadTestsFromModule(sys.modules[__name__]))
|
||||
|
||||
# test modules from non-django apps
|
||||
tsuite.addTest(unittest.defaultTestLoader.loadTestsFromModule(commandtests))
|
||||
tsuite.addTest(unittest.defaultTestLoader.loadTestsFromModule(locktests))
|
||||
tsuite.addTest(unittest.defaultTestLoader.loadTestsFromModule(utiltests))
|
||||
|
||||
# load tests from the evennia/tests central location
|
||||
for path in glob.glob(os.path.join(settings.EVENNIA_DIR, "tests", "test_*.py")):
|
||||
testmod = mod_import(path)
|
||||
tsuite.addTest(unittest.defaultTestLoader.loadTestsFromModule(testmod))
|
||||
|
||||
return tsuite
|
||||
|
|
|
|||
|
|
@ -610,7 +610,7 @@ INSTALLED_APPS = (
|
|||
# The user profile extends the User object with more functionality;
|
||||
# This should usually not be changed.
|
||||
AUTH_USER_MODEL = "players.PlayerDB"
|
||||
#AUTH_PROFILE_MODULE = "players.PlayerDB"
|
||||
|
||||
# Use a custom test runner that just tests Evennia-specific apps.
|
||||
TEST_RUNNER = 'evennia.server.tests.EvenniaTestSuiteRunner'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,58 +0,0 @@
|
|||
# test with game/manage.py test
|
||||
import unittest
|
||||
|
||||
from evennia.utils import utils
|
||||
|
||||
class TestIsIter(unittest.TestCase):
|
||||
def test_is_iter(self):
|
||||
self.assertEqual(True, utils.is_iter([1,2,3,4]))
|
||||
self.assertEqual(False, utils.is_iter("This is not an iterable"))
|
||||
|
||||
class TestCrop(unittest.TestCase):
|
||||
def test_crop(self):
|
||||
# No text, return no text
|
||||
self.assertEqual("", utils.crop("", width=10, suffix="[...]"))
|
||||
# Input length equal to max width, no crop
|
||||
self.assertEqual("0123456789", utils.crop("0123456789", width=10, suffix="[...]"))
|
||||
# Input length greater than max width, crop (suffix included in width)
|
||||
self.assertEqual("0123[...]", utils.crop("0123456789", width=9, suffix="[...]"))
|
||||
# Input length less than desired width, no crop
|
||||
self.assertEqual("0123", utils.crop("0123", width=9, suffix="[...]"))
|
||||
# Width too small or equal to width of suffix
|
||||
self.assertEqual("012", utils.crop("0123", width=3, suffix="[...]"))
|
||||
self.assertEqual("01234", utils.crop("0123456", width=5, suffix="[...]"))
|
||||
|
||||
class TestDedent(unittest.TestCase):
|
||||
def test_dedent(self):
|
||||
#print "Did TestDedent run?"
|
||||
# Empty string, return empty string
|
||||
self.assertEqual("", utils.dedent(""))
|
||||
# No leading whitespace
|
||||
self.assertEqual("TestDedent", utils.dedent("TestDedent"))
|
||||
# Leading whitespace, single line
|
||||
self.assertEqual("TestDedent", utils.dedent(" TestDedent"))
|
||||
# Leading whitespace, multi line
|
||||
input_string = " hello\n world"
|
||||
expected_string = "hello\nworld"
|
||||
self.assertEqual(expected_string, utils.dedent(input_string))
|
||||
|
||||
class TestListToString(unittest.TestCase):
|
||||
"""
|
||||
Default function header from utils.py:
|
||||
list_to_string(inlist, endsep="and", addquote=False)
|
||||
|
||||
Examples:
|
||||
no endsep:
|
||||
[1,2,3] -> '1, 2, 3'
|
||||
with endsep=='and':
|
||||
[1,2,3] -> '1, 2 and 3'
|
||||
with addquote and endsep
|
||||
[1,2,3] -> '"1", "2" and "3"'
|
||||
"""
|
||||
#print "Did TestListToString run?"
|
||||
def test_list_to_string(self):
|
||||
self.assertEqual('1, 2, 3', utils.list_to_string([1,2,3], endsep=""))
|
||||
self.assertEqual('"1", "2", "3"', utils.list_to_string([1,2,3], endsep="", addquote=True))
|
||||
self.assertEqual('1, 2 and 3', utils.list_to_string([1,2,3]))
|
||||
self.assertEqual('"1", "2" and "3"', utils.list_to_string([1,2,3], endsep="and", addquote=True))
|
||||
|
||||
|
|
@ -6,6 +6,7 @@ except ImportError:
|
|||
from django.test import TestCase
|
||||
|
||||
from ansi import ANSIString
|
||||
import utils
|
||||
|
||||
|
||||
class ANSIStringTestCase(TestCase):
|
||||
|
|
@ -119,3 +120,60 @@ class ANSIStringTestCase(TestCase):
|
|||
target = ANSIString('{gtest{n')
|
||||
result = u'\x1b[1m\x1b[32mTest\x1b[0m'
|
||||
self.checker(target.capitalize(), result, u'Test')
|
||||
|
||||
|
||||
class TestIsIter(TestCase):
|
||||
def test_is_iter(self):
|
||||
self.assertEqual(True, utils.is_iter([1,2,3,4]))
|
||||
self.assertEqual(False, utils.is_iter("This is not an iterable"))
|
||||
|
||||
|
||||
class TestCrop(TestCase):
|
||||
def test_crop(self):
|
||||
# No text, return no text
|
||||
self.assertEqual("", utils.crop("", width=10, suffix="[...]"))
|
||||
# Input length equal to max width, no crop
|
||||
self.assertEqual("0123456789", utils.crop("0123456789", width=10, suffix="[...]"))
|
||||
# Input length greater than max width, crop (suffix included in width)
|
||||
self.assertEqual("0123[...]", utils.crop("0123456789", width=9, suffix="[...]"))
|
||||
# Input length less than desired width, no crop
|
||||
self.assertEqual("0123", utils.crop("0123", width=9, suffix="[...]"))
|
||||
# Width too small or equal to width of suffix
|
||||
self.assertEqual("012", utils.crop("0123", width=3, suffix="[...]"))
|
||||
self.assertEqual("01234", utils.crop("0123456", width=5, suffix="[...]"))
|
||||
|
||||
|
||||
class TestDedent(TestCase):
|
||||
def test_dedent(self):
|
||||
#print "Did TestDedent run?"
|
||||
# Empty string, return empty string
|
||||
self.assertEqual("", utils.dedent(""))
|
||||
# No leading whitespace
|
||||
self.assertEqual("TestDedent", utils.dedent("TestDedent"))
|
||||
# Leading whitespace, single line
|
||||
self.assertEqual("TestDedent", utils.dedent(" TestDedent"))
|
||||
# Leading whitespace, multi line
|
||||
input_string = " hello\n world"
|
||||
expected_string = "hello\nworld"
|
||||
self.assertEqual(expected_string, utils.dedent(input_string))
|
||||
|
||||
|
||||
class TestListToString(TestCase):
|
||||
"""
|
||||
Default function header from utils.py:
|
||||
list_to_string(inlist, endsep="and", addquote=False)
|
||||
|
||||
Examples:
|
||||
no endsep:
|
||||
[1,2,3] -> '1, 2, 3'
|
||||
with endsep=='and':
|
||||
[1,2,3] -> '1, 2 and 3'
|
||||
with addquote and endsep
|
||||
[1,2,3] -> '"1", "2" and "3"'
|
||||
"""
|
||||
def test_list_to_string(self):
|
||||
self.assertEqual('1, 2, 3', utils.list_to_string([1,2,3], endsep=""))
|
||||
self.assertEqual('"1", "2", "3"', utils.list_to_string([1,2,3], endsep="", addquote=True))
|
||||
self.assertEqual('1, 2 and 3', utils.list_to_string([1,2,3]))
|
||||
self.assertEqual('"1", "2" and "3"', utils.list_to_string([1,2,3], endsep="and", addquote=True))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue