def pytest_runtest_setup(item): engine_marker = item.get_marker("engine") if engine_marker is not None: engines = engine_marker.args engine_marker = engine_marker.args[0] if item.callspec.params['engine'] not in engines: pytest.skip("test requires engine %s" % engine_marker) for uid in list(micropsi_runtime.nodenets.keys()): micropsi_runtime.stop_nodenetrunner(uid) for uid in list(micropsi_runtime.nodenets.keys()): micropsi_runtime.delete_nodenet(uid) for uid in list(micropsi_runtime.worlds.keys()): micropsi_runtime.delete_world(uid) for item in os.listdir(testpath): path = os.path.join(testpath, item) if os.path.isdir(path): shutil.rmtree(path) else: os.remove(path) open(os.path.join(testpath, '__init__.py'), 'w').close() os.mkdir(os.path.join(testpath, 'worlds')) os.mkdir(os.path.join(testpath, 'nodenets')) os.mkdir(os.path.join(testpath, 'nodenets', '__autosave__')) os.mkdir(os.path.join(testpath, 'nodetypes')) os.mkdir(os.path.join(testpath, 'recipes')) os.mkdir(os.path.join(testpath, 'operations')) os.mkdir(os.path.join(testpath, 'nodetypes', 'Test')) open(os.path.join(testpath, 'nodetypes', 'Test', '__init__.py'), 'w').close() micropsi_runtime.reload_code() micropsi_runtime.logger.clear_logs() micropsi_runtime.set_runner_properties(0, True) set_logging_levels()
def test_island(resourcepath): success, world_uid = micropsi.new_world("Misland", "Island", owner="tester") assert success world = runtime.worlds[world_uid] assert world.__class__.__name__ == 'Island' runtime.add_worldobject(world_uid, "Lightsource", (10, 10), uid='foobar', name='foobar', parameters={}) runtime.save_world(world_uid) runtime.revert_world(world_uid) world = runtime.worlds[world_uid] assert world.objects["foobar"].__class__.__name__ == 'Lightsource' assert world.objects["foobar"].position == [10, 10] assert world.data['objects']['foobar']['position'] == [10, 10] assert world.__class__.__name__ == 'Island' runtime.set_worldobject_properties(world_uid, "foobar", position=(5, 5)) assert world.objects["foobar"].position == (5, 5) assert world.data['objects']['foobar']['position'] == (5, 5) assert runtime.get_world_view(world_uid, -1)['objects']['foobar']['position'] == (5, 5) runtime.delete_world(world_uid)
def test_world(request): """ Fixture: A test world of type Island """ global world_uid success, world_uid = micropsi.new_world("World of Pain", "Island", "Pytest User", uid=world_uid) yield world_uid try: micropsi.delete_world(world_uid) except: pass
def default_world(request): """ Fixture: A test world of type Island """ global world_uid success, world_uid = micropsi_runtime.new_world("World of Pain", "DefaultWorld", "Pytest User") yield world_uid try: micropsi_runtime.delete_world(world_uid) except: pass
def test_new_world(resourcepath, test_world): success, world_uid = micropsi.new_world("Waterworld", "World", owner="tester") assert success assert world_uid != test_world world_properties = micropsi.get_world_properties(world_uid) assert world_properties["name"] == "Waterworld" w_path = os.path.join(resourcepath, runtime.WORLD_DIRECTORY, world_uid + ".json") assert os.path.exists(w_path) # get_available_worlds worlds = micropsi.get_available_worlds() myworlds = micropsi.get_available_worlds("tester") assert test_world in worlds assert world_uid in worlds assert world_uid in myworlds assert test_world not in myworlds # delete_world micropsi.delete_world(world_uid) assert world_uid not in micropsi.get_available_worlds() assert not os.path.exists(w_path)
def delete_world(world_uid): return runtime.delete_world(world_uid)
def fin(): if DELETE_TEST_FILES_ON_EXIT: try: micropsi.delete_world(world_uid) except: pass
def fin(): if DELETE_TEST_FILES_ON_EXIT: micropsi.delete_world(world_uid)
def delete_world(world_uid): """ Delete the given world """ return runtime.delete_world(world_uid)
def fin(): try: micropsi.delete_world(world_uid) except: pass # world was deleted in test