diff --git a/evennia/commands/default/tests.py b/evennia/commands/default/tests.py index ceb7ffe316..792212bd92 100644 --- a/evennia/commands/default/tests.py +++ b/evennia/commands/default/tests.py @@ -305,6 +305,6 @@ class TestComms(CommandTest): class TestBatchProcess(CommandTest): def test_batch_commands(self): # cannot test batchcode here, it must run inside the server process - self.call(batchprocess.CmdBatchCommands(), "batch_cmds", "Running Batchcommand processor Automatic mode for batch_cmds") + self.call(batchprocess.CmdBatchCommands(), "example_batch_cmds", "Running Batchcommand processor Automatic mode for example_batch_cmds") #self.call(batchprocess.CmdBatchCode(), "examples.batch_code", "") diff --git a/evennia/contrib/tutorial_examples/batch_cmds.ev b/evennia/contrib/tutorial_examples/example_batch_cmds.ev similarity index 100% rename from evennia/contrib/tutorial_examples/batch_cmds.ev rename to evennia/contrib/tutorial_examples/example_batch_cmds.ev diff --git a/evennia/contrib/tutorial_examples/example_batch_code.py b/evennia/contrib/tutorial_examples/example_batch_code.py new file mode 100644 index 0000000000..85c4597ebc --- /dev/null +++ b/evennia/contrib/tutorial_examples/example_batch_code.py @@ -0,0 +1,85 @@ +# +# Batchcode script +# +# +# The Batch-code processor accepts full python modules (e.g. "batch.py") that +# looks identical to normal Python files with a few exceptions that allows them +# to the executed in blocks. This way of working assures a sequential execution +# of the file and allows for features like stepping from block to block +# (without executing those coming before), as well as automatic deletion +# of created objects etc. You can however also run a batch-code python file +# directly using Python (and can also be de). + +# Code blocks are separated by python comments starting with special code words. + +# #HEADER - this denotes commands global to the entire file, such as +# import statements and global variables. They will +# automatically be made available for each block. Observe +# that changes to these variables made in one block is not +# preserved between blocks!) +# #CODE (infotext) [objname, objname, ...] - This designates a code block that +# will be executed like a stand-alone piece of code together with +# any #HEADER defined. +# infotext is a describing text about what goes in in this block. +# It will be shown by the batchprocessing command. +# s mark the (variable-)names of objects created in +# the code, and which may be auto-deleted by the processor if +# desired (such as when debugging the script). E.g., if the code +# contains the command myobj = create.create_object(...), you could +# put 'myobj' in the #CODE header regardless of what the created +# object is actually called in-game. +# #INSERT filename - this includes another code batch file. The named file will +# be loaded and run at this point. Note that code from the inserted +# file will NOT share #HEADERs with the importing file, but will +# only use the headers in the importing file. Make sure to not +# create a cyclic import here! + +# The following variable is automatically made available for the script: + +# caller - the object executing the script +# + + +#HEADER + +# everything in this block will be appended to the beginning of +# all other #CODE blocks when they are executed. + +from evennia import create_object, search_object +from evennia.contrib.tutorial_examples import red_button +from evennia import DefaultObject + +limbo = search_object('Limbo')[0] + + +#CODE (create red button) + +# This is the first code block. Within each block, python +# code works as normal. Note how we make use if imports and +# 'limbo' defined in the #HEADER block. This block's header +# offers no information about red_button variable, so it +# won't be able to be deleted in debug mode. + +# create a red button in limbo +red_button = create_object(red_button.RedButton, key="Red button", + location=limbo, aliases=["button"]) + +# we take a look at what we created +caller.msg("A %s was created." % red_button.key) + +#CODE (create table and chair) table, chair + +# this code block has 'table' and 'chair' set as deletable +# objects. This means that when the batchcode processor runs in +# testing mode, objects created in these variables will be deleted +# again (so as to avoid duplicate objects when testing the script many +# times). + +# the python variables we assign to must match the ones given in the +# header for the system to be able to delete them afterwards during a +# debugging run. +table = create_object(DefaultObject, key="Table", location=limbo) +chair = create_object(DefaultObject, key="Chair", location=limbo) + +string = "A %s and %s were created. If debug was active, they were deleted again." +caller.msg(string % (table, chair)) diff --git a/evennia/contrib/tutorial_examples/red_button.py b/evennia/contrib/tutorial_examples/red_button.py index 74c656df52..2f3d961fd6 100644 --- a/evennia/contrib/tutorial_examples/red_button.py +++ b/evennia/contrib/tutorial_examples/red_button.py @@ -12,8 +12,8 @@ Note that you must drop the button before you can see its messages! """ import random from evennia import DefaultObject -from contrib.tutorial_examples import red_button_scripts as scriptexamples -from contrib.tutorial_examples import cmdset_red_button as cmdsetexamples +from evennia.contrib.tutorial_examples import red_button_scripts as scriptexamples +from evennia.contrib.tutorial_examples import cmdset_red_button as cmdsetexamples # # Definition of the object itself diff --git a/evennia/contrib/tutorial_examples/red_button_scripts.py b/evennia/contrib/tutorial_examples/red_button_scripts.py index 8cc3bb9755..4146d2f418 100644 --- a/evennia/contrib/tutorial_examples/red_button_scripts.py +++ b/evennia/contrib/tutorial_examples/red_button_scripts.py @@ -7,7 +7,7 @@ on uses of scripts are included. """ from evennia import DefaultScript -from contrib.tutorial_examples import cmdset_red_button as cmdsetexamples +from evennia.contrib.tutorial_examples import cmdset_red_button as cmdsetexamples # # Scripts as state-managers diff --git a/evennia/server/tests.py b/evennia/server/tests.py index c5e2657943..7ae98dcfcc 100644 --- a/evennia/server/tests.py +++ b/evennia/server/tests.py @@ -68,7 +68,7 @@ def suite(): 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", "*.py")): + for path in glob.glob(os.path.join(settings.EVENNIA_DIR, "tests", "test_*.py")): testmod = mod_import(path) tsuite.addTest(unittest.defaultTestLoader.loadTestsFromModule(testmod)) diff --git a/evennia/settings_default.py b/evennia/settings_default.py index d9abee5791..c067827830 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -104,19 +104,16 @@ WEBSOCKET_INTERFACES = ['0.0.0.0'] # standard Django admin is used. EVENNIA_ADMIN = True # The path to the root directory -if test: - # Tests must be run within a migrated initialized game. - ROOT_DIR = os.getcwd() -else: - ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Path to the lib directory containing the bulk of the codebase's code. EVENNIA_DIR = os.path.join(ROOT_DIR, 'evennia') # Path to the game directory (containing the database file if using sqlite). if test: - GAME_DIR = ROOT_DIR + GAME_DIR = os.getcwd() else: - GAME_DIR = os.path.join(ROOT_DIR, 'game_template') + # Fallback location + GAME_DIR = os.path.join(EVENNIA_DIR, 'game_template') # Place to put log files LOG_DIR = os.path.join(GAME_DIR, 'server', 'logs') @@ -336,7 +333,7 @@ TYPECLASS_AGGRESSIVE_CACHE = True # Python path to a directory to be searched for batch scripts # for the batch processors (.ev and/or .py files). -BASE_BATCHPROCESS_PATHS = ['world', 'evennia.contrib'] +BASE_BATCHPROCESS_PATHS = ['world', 'evennia.contrib', 'evennia.contrib.tutorial_examples'] ###################################################################### # Game Time setup diff --git a/evennia/tests/test_scripts_models.py b/evennia/tests/test_scripts_models.py index f047885418..c9d460d9a5 100644 --- a/evennia/tests/test_scripts_models.py +++ b/evennia/tests/test_scripts_models.py @@ -3,7 +3,7 @@ from django.utils.unittest import TestCase from evennia.scripts.models import ScriptDB, ObjectDoesNotExist from evennia.utils.create import create_script -from evennia.scripts import DoNothing +from evennia.scripts.scripts import DoNothing import unittest from django.conf import settings diff --git a/evennia/utils/utils.py b/evennia/utils/utils.py index a7931abfcf..f2784df182 100644 --- a/evennia/utils/utils.py +++ b/evennia/utils/utils.py @@ -325,9 +325,6 @@ def pypath_to_realpath(python_path, file_ending='.py'): existence before being returned, so this may be an empty list. """ - print "settings.EVENNIA_DIR:", settings.EVENNIA_DIR - print "settings.GAME_DIR:", settings.GAME_DIR - print python_path pathsplit = python_path.strip().split('.') paths = [os.path.join(settings.EVENNIA_DIR, *pathsplit), os.path.join(settings.GAME_DIR, *pathsplit)] @@ -337,7 +334,6 @@ def pypath_to_realpath(python_path, file_ending='.py'): paths = ["%s%s" % (p, file_ending) if not p.endswith(file_ending) else p for p in paths] # check so the paths actually exists before returning - print "py to path:", paths return [p for p in paths if os.path.isfile(p)]