示例#1
0
    def test_from_json_file_bad_file(self):
        # file not exists
        with pytest.raises(SettingsError):
            Settings.from_json_file("file_not_exists")

        # invalid json file
        with pytest.raises(SettingsError):
            Settings.from_json_file(__file__)
示例#2
0
    def test_from_json_file_bad_data(self, base_json_data, tmpdir):
        # not set url_list_file
        json_data = copy.deepcopy(base_json_data)
        del json_data['url_list_file']
        json_file = self.dump_json_data(json_data, tmpdir)
        with pytest.raises(SettingsError):
            Settings.from_json_file(json_file)

        # not set output_directory
        json_data = copy.deepcopy(base_json_data)
        del json_data['output_directory']
        json_file = self.dump_json_data(json_data, tmpdir)
        with pytest.raises(SettingsError):
            Settings.from_json_file(json_file)
示例#3
0
文件: cli.py 项目: 7c00/minispider
    def parse_cli_arguments(self):
        """Parse cli arguments
        """
        import argparse
        parser = argparse.ArgumentParser(prog="minispider")
        parser.add_argument("-v", "--version", action="version",
                            version="%(prog)s " + __version__)
        parser.add_argument("-c", "--config", required=True,
                            help="set the configuration file path")
        args = parser.parse_args()

        # load settings
        self.settings = Settings.from_json_file(args.config)
示例#4
0
 def test_from_json_file_base(self, base_json_data, base_settings, tmpdir):
     json_file = self.dump_json_data(base_json_data, tmpdir)
     loaded_settings = Settings.from_json_file(json_file)
     assert self.compare_settings(base_settings, loaded_settings)