Ran formatting on code
This commit is contained in:
parent
83154de19e
commit
353e4c0aa7
20 changed files with 296 additions and 327 deletions
|
|
@ -6,5 +6,6 @@ dependencies.
|
|||
|
||||
from evennia import nonexistent_module, DefaultScript
|
||||
|
||||
|
||||
class BrokenScript(DefaultScript):
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -8,14 +8,16 @@ from evennia import DefaultScript
|
|||
|
||||
_BASE_TYPECLASS = class_from_module(settings.BASE_SCRIPT_TYPECLASS)
|
||||
|
||||
|
||||
class GoodScript(DefaultScript):
|
||||
pass
|
||||
|
||||
|
||||
class InvalidScript:
|
||||
pass
|
||||
|
||||
class TestGlobalScriptContainer(unittest.TestCase):
|
||||
|
||||
class TestGlobalScriptContainer(unittest.TestCase):
|
||||
def test_init_with_no_scripts(self):
|
||||
gsc = containers.GlobalScriptContainer()
|
||||
|
||||
|
|
@ -29,7 +31,7 @@ class TestGlobalScriptContainer(unittest.TestCase):
|
|||
|
||||
self.assertEqual(len(gsc.typeclass_storage), 0)
|
||||
|
||||
@override_settings(GLOBAL_SCRIPTS={'script_name': {}})
|
||||
@override_settings(GLOBAL_SCRIPTS={"script_name": {}})
|
||||
def test_start_with_typeclassless_script(self):
|
||||
"""No specified typeclass should fallback to base"""
|
||||
gsc = containers.GlobalScriptContainer()
|
||||
|
|
@ -37,10 +39,14 @@ class TestGlobalScriptContainer(unittest.TestCase):
|
|||
gsc.start()
|
||||
|
||||
self.assertEqual(len(gsc.typeclass_storage), 1)
|
||||
self.assertIn('script_name', gsc.typeclass_storage)
|
||||
self.assertEqual(gsc.typeclass_storage['script_name'], _BASE_TYPECLASS)
|
||||
self.assertIn("script_name", gsc.typeclass_storage)
|
||||
self.assertEqual(gsc.typeclass_storage["script_name"], _BASE_TYPECLASS)
|
||||
|
||||
@override_settings(GLOBAL_SCRIPTS={'script_name': {'typeclass': 'evennia.utils.tests.test_containers.NoScript'}})
|
||||
@override_settings(
|
||||
GLOBAL_SCRIPTS={
|
||||
"script_name": {"typeclass": "evennia.utils.tests.test_containers.NoScript"}
|
||||
}
|
||||
)
|
||||
def test_start_with_nonexistent_script(self):
|
||||
"""Missing script class should fall back to base"""
|
||||
gsc = containers.GlobalScriptContainer()
|
||||
|
|
@ -48,35 +54,53 @@ class TestGlobalScriptContainer(unittest.TestCase):
|
|||
gsc.start()
|
||||
|
||||
self.assertEqual(len(gsc.typeclass_storage), 1)
|
||||
self.assertIn('script_name', gsc.typeclass_storage)
|
||||
self.assertEqual(gsc.typeclass_storage['script_name'], _BASE_TYPECLASS)
|
||||
self.assertIn("script_name", gsc.typeclass_storage)
|
||||
self.assertEqual(gsc.typeclass_storage["script_name"], _BASE_TYPECLASS)
|
||||
|
||||
@override_settings(GLOBAL_SCRIPTS={'script_name': {'typeclass': 'evennia.utils.tests.test_containers.GoodScript'}})
|
||||
@override_settings(
|
||||
GLOBAL_SCRIPTS={
|
||||
"script_name": {"typeclass": "evennia.utils.tests.test_containers.GoodScript"}
|
||||
}
|
||||
)
|
||||
def test_start_with_valid_script(self):
|
||||
gsc = containers.GlobalScriptContainer()
|
||||
|
||||
gsc.start()
|
||||
|
||||
self.assertEqual(len(gsc.typeclass_storage), 1)
|
||||
self.assertIn('script_name', gsc.typeclass_storage)
|
||||
self.assertEqual(gsc.typeclass_storage['script_name'], GoodScript)
|
||||
self.assertIn("script_name", gsc.typeclass_storage)
|
||||
self.assertEqual(gsc.typeclass_storage["script_name"], GoodScript)
|
||||
|
||||
@override_settings(GLOBAL_SCRIPTS={'script_name': {'typeclass': 'evennia.utils.tests.test_containers.InvalidScript'}})
|
||||
@override_settings(
|
||||
GLOBAL_SCRIPTS={
|
||||
"script_name": {"typeclass": "evennia.utils.tests.test_containers.InvalidScript"}
|
||||
}
|
||||
)
|
||||
def test_start_with_invalid_script(self):
|
||||
"""Script class doesn't implement required methods methods"""
|
||||
gsc = containers.GlobalScriptContainer()
|
||||
|
||||
with self.assertRaises(AttributeError) as err:
|
||||
with self.assertRaises(AttributeError) as err:
|
||||
gsc.start()
|
||||
# check for general attribute failure on the invalid class to preserve against future code-rder changes
|
||||
self.assertTrue(str(err.exception).startswith("type object 'InvalidScript' has no attribute"), err.exception)
|
||||
self.assertTrue(
|
||||
str(err.exception).startswith("type object 'InvalidScript' has no attribute"),
|
||||
err.exception,
|
||||
)
|
||||
|
||||
@override_settings(GLOBAL_SCRIPTS={'script_name': {'typeclass': 'evennia.utils.tests.data.broken_script.BrokenScript'}})
|
||||
@override_settings(
|
||||
GLOBAL_SCRIPTS={
|
||||
"script_name": {"typeclass": "evennia.utils.tests.data.broken_script.BrokenScript"}
|
||||
}
|
||||
)
|
||||
def test_start_with_broken_script(self):
|
||||
"""Un-importable script should traceback"""
|
||||
gsc = containers.GlobalScriptContainer()
|
||||
|
||||
with self.assertRaises(Exception) as err:
|
||||
with self.assertRaises(Exception) as err:
|
||||
gsc.start()
|
||||
# exception raised by imported module
|
||||
self.assertTrue(str(err.exception).startswith("cannot import name 'nonexistent_module' from 'evennia'"), err.exception)
|
||||
self.assertTrue(
|
||||
str(err.exception).startswith("cannot import name 'nonexistent_module' from 'evennia'"),
|
||||
err.exception,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -353,12 +353,9 @@ class TestTextToHTMLparser(TestCase):
|
|||
|
||||
def test_non_url_with_www(self):
|
||||
self.assertEqual(
|
||||
self.parser.convert_urls('Awwww.this should not be highlighted'),
|
||||
'Awwww.this should not be highlighted'
|
||||
self.parser.convert_urls("Awwww.this should not be highlighted"),
|
||||
"Awwww.this should not be highlighted",
|
||||
)
|
||||
|
||||
def test_invalid_www_url(self):
|
||||
self.assertEqual(
|
||||
self.parser.convert_urls('www.t'),
|
||||
'www.t'
|
||||
)
|
||||
self.assertEqual(self.parser.convert_urls("www.t"), "www.t")
|
||||
|
|
|
|||
|
|
@ -721,10 +721,10 @@ class TestIntConversions(TestCase):
|
|||
# basic mapped numbers
|
||||
self.assertEqual(3, utils.str2int("three"))
|
||||
self.assertEqual(20, utils.str2int("twenty"))
|
||||
|
||||
|
||||
# multi-place numbers
|
||||
self.assertEqual(2345, utils.str2int("two thousand, three hundred and forty-five"))
|
||||
|
||||
|
||||
# ordinal numbers
|
||||
self.assertEqual(1, utils.str2int("1st"))
|
||||
self.assertEqual(1, utils.str2int("first"))
|
||||
|
|
@ -734,4 +734,4 @@ class TestIntConversions(TestCase):
|
|||
self.assertEqual(20, utils.str2int("twentieth"))
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
utils.str2int("not a number")
|
||||
utils.str2int("not a number")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue