def _assert_config_read(environment, mock_config): mock_instance = mock_config.return_value Config.CONFIG = None # Force config file reload prev_environment = {environment: None} for env_name in ["APPDATA", "HOME", "XDG_CONFIG_HOME"]: if env_name in os.environ: prev_environment[env_name] = os.environ[env_name] del os.environ[env_name] os.environ[environment] = "/MOCK" module_dir = os.path.dirname(sys.modules["asyncpraw"].__file__) environ_path = os.path.join("/MOCK", ".config" if environment == "HOME" else "", "praw.ini") locations = [ os.path.join(module_dir, "praw.ini"), environ_path, "praw.ini", ] try: Config._load_config() mock_instance.read.assert_called_with(locations) finally: Config.CONFIG = None # Force config file reload for env_name in prev_environment: if prev_environment[env_name] is None: del os.environ[env_name] else: os.environ[env_name] = prev_environment[env_name]
def test_load_ini_with_no_config_directory(self, mock_config): mock_instance = mock_config.return_value Config.CONFIG = None # Force config file reload prev_environment = {} for key in ["APPDATA", "HOME", "XDG_CONFIG_HOME"]: if key in os.environ: prev_environment[key] = os.environ[key] del os.environ[key] module_dir = os.path.dirname(sys.modules["asyncpraw"].__file__) locations = [os.path.join(module_dir, "praw.ini"), "praw.ini"] try: Config._load_config() mock_instance.read.assert_called_with(locations) finally: Config.CONFIG = None # Force config file reload for key, value in prev_environment.items(): os.environ[key] = value