Esempio n. 1
0
    def test_should_raise_error_when_file_is_not_path_or_string(
            self, toml_file):
        with pytest.raises(TypeError) as exc_info:
            Configuration.load_from_toml(toml_file)

        assert f'toml file must be of type Path or str but you provided {type(toml_file)}' == str(
            exc_info.value)
Esempio n. 2
0
    def test_should_return_correct_config_when_given_correct_toml_file(self, tmp_path):
        toml_file = tmp_path / 'settings.toml'
        lines = """
        [scalpel]
        foo = "bar"
        user_agent = "Mozilla/5.0"
        fetch_timeout = 4.0
        follow_robots_txt = true
        """
        toml_file.write_text(lines)
        expected_config = Configuration(fetch_timeout=4.0, user_agent='Mozilla/5.0', follow_robots_txt=True)

        for item in [f'{toml_file}', toml_file]:
            config = Configuration.load_from_toml(item)
            assert expected_config.fetch_timeout == config.fetch_timeout
            assert expected_config.user_agent == config.user_agent
            assert expected_config.follow_robots_txt == config.follow_robots_txt
Esempio n. 3
0
    def test_should_raise_error_when_file_is_not_valid_toml(self, tmp_path):
        toml_file = tmp_path / 'settings.toml'
        toml_file.write_text('Hello!')

        with pytest.raises(DecodeError):
            Configuration.load_from_toml(toml_file)