Add support for testing with other settings than the default one. Implements #774.
This commit is contained in:
parent
73cd97e10a
commit
4d3ea8df07
1 changed files with 31 additions and 4 deletions
|
|
@ -57,8 +57,10 @@ SERVER_RESTART = None
|
||||||
PORTAL_RESTART = None
|
PORTAL_RESTART = None
|
||||||
SERVER_PY_FILE = None
|
SERVER_PY_FILE = None
|
||||||
PORTAL_PY_FILE = None
|
PORTAL_PY_FILE = None
|
||||||
|
TEST_MODE = False
|
||||||
|
ENFORCED_SETTING = False
|
||||||
|
|
||||||
|
# requirements
|
||||||
PYTHON_MIN = '2.7'
|
PYTHON_MIN = '2.7'
|
||||||
TWISTED_MIN = '16.0.0'
|
TWISTED_MIN = '16.0.0'
|
||||||
DJANGO_MIN = '1.8'
|
DJANGO_MIN = '1.8'
|
||||||
|
|
@ -370,6 +372,21 @@ NOTE_KEYBOARDINTERRUPT = \
|
||||||
STOP: Caught keyboard interrupt while in interactive mode.
|
STOP: Caught keyboard interrupt while in interactive mode.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
NOTE_TEST_DEFAULT = \
|
||||||
|
"""
|
||||||
|
TESTING: Using Evennia's default settings file (evennia.settings_default).
|
||||||
|
(use 'evennia --settings settings.py test .' to run tests on the game dir)
|
||||||
|
"""
|
||||||
|
|
||||||
|
NOTE_TEST_CUSTOM = \
|
||||||
|
"""
|
||||||
|
TESTING: Using specified settings file '{settings_dotpath}'.
|
||||||
|
|
||||||
|
(Obs: Evennia's full test suite may not pass if the settings are very
|
||||||
|
different from the default. Use 'test .' as arguments to run only tests
|
||||||
|
on the game dir.)
|
||||||
|
"""
|
||||||
|
|
||||||
#------------------------------------------------------------
|
#------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Functions
|
# Functions
|
||||||
|
|
@ -831,8 +848,13 @@ def init_game_directory(path, check_db=True):
|
||||||
# Add gamedir to python path
|
# Add gamedir to python path
|
||||||
sys.path.insert(0, GAMEDIR)
|
sys.path.insert(0, GAMEDIR)
|
||||||
|
|
||||||
if sys.argv[1] == 'test':
|
if TEST_MODE:
|
||||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'evennia.settings_default'
|
if ENFORCED_SETTING:
|
||||||
|
print(NOTE_TEST_CUSTOM.format(settings_dotpath=SETTINGS_DOTPATH))
|
||||||
|
os.environ['DJANGO_SETTINGS_MODULE'] = SETTINGS_DOTPATH
|
||||||
|
else:
|
||||||
|
print(NOTE_TEST_DEFAULT)
|
||||||
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'evennia.settings_default'
|
||||||
else:
|
else:
|
||||||
os.environ['DJANGO_SETTINGS_MODULE'] = SETTINGS_DOTPATH
|
os.environ['DJANGO_SETTINGS_MODULE'] = SETTINGS_DOTPATH
|
||||||
|
|
||||||
|
|
@ -1239,12 +1261,14 @@ def main():
|
||||||
if args.altsettings:
|
if args.altsettings:
|
||||||
# use alternative settings file
|
# use alternative settings file
|
||||||
sfile = args.altsettings[0]
|
sfile = args.altsettings[0]
|
||||||
global SETTINGSFILE, SETTINGS_DOTPATH
|
global SETTINGSFILE, SETTINGS_DOTPATH, ENFORCED_SETTING
|
||||||
SETTINGSFILE = sfile
|
SETTINGSFILE = sfile
|
||||||
|
ENFORCED_SETTING = True
|
||||||
SETTINGS_DOTPATH = "server.conf.%s" % sfile.rstrip(".py")
|
SETTINGS_DOTPATH = "server.conf.%s" % sfile.rstrip(".py")
|
||||||
print("Using settings file '%s' (%s)." % (
|
print("Using settings file '%s' (%s)." % (
|
||||||
SETTINGSFILE, SETTINGS_DOTPATH))
|
SETTINGSFILE, SETTINGS_DOTPATH))
|
||||||
|
|
||||||
|
|
||||||
if args.initsettings:
|
if args.initsettings:
|
||||||
# create new settings file
|
# create new settings file
|
||||||
global GAMEDIR
|
global GAMEDIR
|
||||||
|
|
@ -1281,6 +1305,9 @@ def main():
|
||||||
# to use the shell we need to initialize it first,
|
# to use the shell we need to initialize it first,
|
||||||
# and this only works if the database is set up
|
# and this only works if the database is set up
|
||||||
check_db = True
|
check_db = True
|
||||||
|
if option == "test":
|
||||||
|
global TEST_MODE
|
||||||
|
TEST_MODE = True
|
||||||
init_game_directory(CURRENT_DIR, check_db=check_db)
|
init_game_directory(CURRENT_DIR, check_db=check_db)
|
||||||
|
|
||||||
args = [option]
|
args = [option]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue