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__)
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)
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)
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)