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

        assert f'yaml file must be of type Path or str but you provided {type(yaml_file)}' == str(
            exc_info.value)
Esempio n. 2
0
    def test_should_raise_error_when_file_is_not_valid_yaml(self, tmp_path):
        yaml_file = tmp_path / 'foo.yaml'
        lines = """
        [scalpel]
        foo = bar
        """
        yaml_file.write_text(lines)

        with pytest.raises(DecodeError):
            Configuration.load_from_yaml(yaml_file)
Esempio n. 3
0
    def test_should_return_correct_config_when_given_correct_yaml_file(self, tmp_path):
        lines = """---
        scalpel:
          fetch_timeout: 4.0
          user_agent: Mozilla/5.0
          follow_robots_txt: true
          foo: bar
        """
        yaml_file = tmp_path / 'settings.yml'
        yaml_file.write_text(lines)
        expected_config = Configuration(fetch_timeout=4.0, user_agent='Mozilla/5.0', follow_robots_txt=True)

        for item in [f'{yaml_file}', yaml_file]:
            config = Configuration.load_from_yaml(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