コード例 #1
0
    def test_load_FileDoesNotExist_RaisesFileNotFoundError(self, tmpdir):
        config_file = tmpdir.join('config')  # file was not created here
        config_filepath = str(config_file)
        config = ConfigurationFile()

        with pytest.raises(FileNotFoundError):
            config.load(config_filepath)
コード例 #2
0
    def test_load_FileMissingOneOfThe3Params_RaisesLoadError(
            self, tmpdir):
        config_file = tmpdir.join('config')
        config_file.write("""
        {
            "db_file": "file.db",
            "cache_dir": "cache"
        }""")
        config = ConfigurationFile()

        with pytest.raises(LoadError) as error:
            config.load(str(config_file))
        assert str(error.value) == "configuration file '%s' " \
                                   "missing one parameter" % config_file
コード例 #3
0
    def test_load_FileMissingQuotesInTheParamNames_RaisesLoadError(
            self, tmpdir):
        config_file = tmpdir.join('config')
        config_file.write("""
        {
            db_file: "file.db",
            cache_dir: "cache",
            store_dir: "store"
        }""")
        config = ConfigurationFile()

        with pytest.raises(LoadError) as error:
            config.load(str(config_file))
        assert str(error.value).startswith("configuration file '%s' is not in "
                                           "the correct format: " % config_file)
コード例 #4
0
    def test_load_FileMissingColonsBetweenParamNamesAndValues_RaisesLoadError(
            self, tmpdir):
        config_file = tmpdir.join('config')
        config_file.write("""
        {
            "db_file" "file.db",
            "cache_dir" "cache",
            "store_dir" "store"
        }""")
        config = ConfigurationFile()

        with pytest.raises(LoadError) as error:
            config.load(str(config_file))
        assert str(error.value).startswith("configuration file '%s' is not in "
                                           "the correct format: " % config_file)
コード例 #5
0
    def test_load_FileWithThe3Params_LoadsConfigFileWithRespectiveValues(
            self, tmpdir):
        config_file = tmpdir.join('config')
        config_file.write("""
        {
            "db_file": "file.db",
            "cache_dir": "cache",
            "store_dir": "store"
        }""")
        config = ConfigurationFile()

        config.load(str(config_file))

        assert config.db_file == "file.db"
        assert config.cache_dir == "cache"
        assert config.store_dir == "store"
コード例 #6
0
    def test_load_FileWithThe3ParamsAndExtraInvalidParam_RaisesLoadError(
            self, tmpdir):
        config_file = tmpdir.join('config')
        config_file.write("""
        {
            "db_file": "file.db",
            "cache_dir": "cache",
            "store_dir": "store",
            "extra": "extra"
        }""")
        config = ConfigurationFile()

        with pytest.raises(LoadError) as error:
            config.load(str(config_file))
        assert str(error.value) == "configuration file '%s' has unknown " \
                                   "parameters" % config_file