예제 #1
0
    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]
예제 #2
0
    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
예제 #3
0
 def test_extended_interpolation(self):
     Config.CONFIG = None  # Force config file reload
     with mock.patch.dict(
             "os.environ",
         {
             "APPDATA": os.path.dirname(__file__),
             "XDG_CONFIG_HOME": os.path.dirname(__file__),
         },
     ):
         config = Config("INTERPOLATION", config_interpolation="extended")
         assert config.custom["basic_interpolation"] == "%(reddit_url)s"
         assert config.custom["extended_interpolation"] == config.reddit_url
예제 #4
0
 def test_unset_value_has_useful_string_representation(self):
     config = Config("DEFAULT", password=Config.CONFIG_NOT_SET)
     assert str(config.password) == "NotSet"
예제 #5
0
 def test_short_url_not_defined(self):
     config = Config("DEFAULT", short_url=None)
     with pytest.raises(ClientException) as excinfo:
         config.short_url
     assert str(excinfo.value) == "No short domain specified."
예제 #6
0
 def test_short_url(self):
     config = Config("DEFAULT")
     assert config.short_url == "https://redd.it"
예제 #7
0
 def test_custom__no_extra_values_set(self):
     config = Config("DEFAULT")
     assert config.custom == {}
예제 #8
0
 def test_custom__extra_values_set(self):
     config = Config("DEFAULT", user1="foo", user2="bar")
     assert config.custom == {"user1": "foo", "user2": "bar"}
예제 #9
0
 def test_check_for_updates__true(self):
     for value in [True, "1", "true", "YES", "on"]:
         config = Config("DEFAULT", check_for_updates=value)
         assert config.check_for_updates is True
예제 #10
0
 def test_check_for_updates__false(self):
     for value in [False, "False", "other"]:
         config = Config("DEFAULT", check_for_updates=value)
         assert config.check_for_updates is False