def test_special_character(self): """Make paths have special characters and check some basic operations""" outer = tempfile.mkdtemp(self.__class__.odd_characters) inner = str(os.path.join(outer, self.__class__.odd_characters)) inner2 = str(os.path.join(outer, self.__class__.odd_characters + "2")) PATHS.USER_DATA_DIR = inner PATHS.LOG_DIR = os.path.join(inner, "log") PATHS.USER_MAPS_DIR = os.path.join(inner, "maps") PATHS.SCREENSHOT_DIR = os.path.join(inner, "screenshots") PATHS.SAVEGAME_DIR = os.path.join(inner, "save") create_user_dirs(migrate=False) scenario_file = os.listdir(SavegameManager.scenarios_dir)[0] shutil.copy(os.path.join(SavegameManager.scenarios_dir, scenario_file), inner) SavegameManager.scenarios_dir = inner SavegameManager.autosave_dir = inner2 SavegameManager.init() # try to read scenario files SavegameManager.get_available_scenarios() os.remove(os.path.join(inner, scenario_file)) SavegameManager.create_autosave_filename() for dirpath, _dirnames, _filenames in os.walk(inner, topdown=False): os.rmdir(dirpath) os.rmdir(inner2) os.rmdir(outer)
def test_special_character(self): """Make paths have special characters and check some basic operations""" outer = tempfile.mkdtemp(self.__class__.odd_characters) inner = str(os.path.join(outer, self.__class__.odd_characters)) inner2 = str(os.path.join(outer, self.__class__.odd_characters + "2")) PATHS.USER_DATA_DIR = inner create_user_dirs() scenario_file = os.listdir(SavegameManager.scenarios_dir)[0] shutil.copy(os.path.join(SavegameManager.scenarios_dir, scenario_file), inner) SavegameManager.scenarios_dir = inner SavegameManager.autosave_dir = inner2 SavegameManager.init() # try to read scenario files SavegameManager.get_available_scenarios() os.remove(os.path.join(inner, scenario_file)) SavegameManager.create_autosave_filename() os.rmdir(inner) os.rmdir(inner2) os.rmdir(outer)
def main(): # abort silently on signal signal.signal(signal.SIGINT, functools.partial(exithandler, 130)) signal.signal(signal.SIGTERM, functools.partial(exithandler, 1)) # avoid crashing when writing to unavailable standard streams setup_streams() # use locale-specific time.strftime handling try: locale.setlocale(locale.LC_TIME, '') except locale.Error: # Workaround for "locale.Error: unsupported locale setting" pass # Change the working directory to the parent of the content directory os.chdir(get_content_dir_parent_path()) logging.config.dictConfig({ 'version': 1, 'disable_existing_loggers': False, 'handlers': { 'default': { 'class': 'logging.StreamHandler', 'level': 'WARN', 'stream': 'ext://sys.stderr' } }, 'root': { 'handlers': ['default'] } }) import horizons.main from horizons.i18n import gettext as T from horizons.util import create_user_dirs from horizons.util.cmdlineoptions import get_option_parser check_requirements() create_user_dirs() options = get_option_parser().parse_args()[0] setup_debugging(options) init_environment(True) # Start UH. ret = horizons.main.start(options) if logfile: logfile.close() if ret: print(T('Thank you for using Unknown Horizons!')) else: # Game didn't end successfully sys.exit(1)
def pytest_namespace(): """ This needs to run at first to avoid that other code gets a reference to the real fife module. """ global FIFE_MOCK_INSTALLED if FIFE_MOCK_INSTALLED: return def mock_fife(): """ Using a custom import hook, we catch all imports of fife and provide a dummy module. """ from tests.dummy import Dummy class Finder(PathFinder): @staticmethod def find_spec(fullname, path, target=None): if fullname.startswith('fife'): return ModuleSpec(fullname, DummyLoader()) class DummyLoader(Loader): @staticmethod def load_module(module): sys.modules.setdefault(module, Dummy()) sys.meta_path.insert(0, Finder) mock_fife() import horizons.globals import fife horizons.globals.fife = fife.fife from horizons.util import create_user_dirs create_user_dirs() import horizons.i18n horizons.i18n.change_language() FIFE_MOCK_INSTALLED = True
def test_normal(self): create_user_dirs(migrate=False)
def test_normal(self): create_user_dirs()