def test_parameter_type_multicolumn(self): spec = load_spec({ "id_name": "testme", "name": "Test Module", "category": "Clean", "parameters": [ { "id_name": "hello", "type": "multicolumn", "name": "Hello there!", "placeholder": "Fill me", "column_types": ["text"], "tab_parameter": "tab", }, { "id_name": "tab", "type": "tab", "name": "Hello there 2!" }, ], }) result = find_spec_messages(spec) expected = { "_spec.name": "Test Module", "_spec.parameters.hello.name": "Hello there!", "_spec.parameters.hello.placeholder": "Fill me", "_spec.parameters.tab.name": "Hello there 2!", } self.assertDictEqual(result, expected)
def test_parameter_type_list(self): spec = load_spec({ "id_name": "testme", "name": "Test Module", "category": "Clean", "parameters": [{ "id_name": "hello", "type": "list", "name": "Hello there!", "child_parameters": [{ "id_name": "hello2", "type": "statictext", "name": "Hello there 2!", }], }], }) result = find_spec_messages(spec) expected = { "_spec.name": "Test Module", "_spec.parameters.hello.name": "Hello there!", "_spec.parameters.hello.child_parameters.hello2.name": "Hello there 2!", } self.assertDictEqual(result, expected)
def test_parameter_type_radio(self): spec = ModuleSpec( **{ "id_name": "testme", "name": "Test Module", "category": "Clean", "parameters": [ { "id_name": "hello", "type": "radio", "name": "Hello there!", "options": [ {"label": "First", "value": "first"}, {"label": "Second", "value": True}, ], "default": "first", } ], } ) result = find_spec_messages(spec) expected = { "_spec.name": "Test Module", "_spec.parameters.hello.name": "Hello there!", "_spec.parameters.hello.options.first.label": "First", "_spec.parameters.hello.options.True.label": "Second", } self.assertDictEqual(result, expected)
def test_everything_except_parameters(self): spec = load_spec({ "id_name": "testme", "name": "Test Module", "category": "Clean", "parameters": [], "description": "I do that", "deprecated": { "message": "Please use something else", "end_date": "2030-12-31", }, "icon": "url", "link": "http://example.com/module", "loads_data": False, "uses_data": True, "html_output": False, "has_zen_mode": True, "row_action_menu_entry_title": "Solve your problem", "help_url": "/testme", }) result = find_spec_messages(spec) expected = { "_spec.name": "Test Module", "_spec.description": "I do that", "_spec.deprecated.message": "Please use something else", "_spec.row_action_menu_entry_title": "Solve your problem", } self.assertDictEqual(result, expected)
def test_parameter_type_secret_string(self): spec = ModuleSpec( **{ "id_name": "testme", "name": "Test Module", "category": "Clean", "parameters": [ { "id_name": "hello", "type": "secret", "secret_logic": { "provider": "string", "label": "Secret", "pattern": "[A-Z]{10,12}", "placeholder": "AAAAAAAAAAAA", "help": "Find it there", "help_url_prompt": "Take me there", "help_url": "https://example.com/get_secret", }, } ], } ) result = find_spec_messages(spec) expected = { "_spec.name": "Test Module", "_spec.parameters.hello.secret_logic.label": "Secret", "_spec.parameters.hello.secret_logic.help": "Find it there", "_spec.parameters.hello.secret_logic.help_url_prompt": "Take me there", "_spec.parameters.hello.secret_logic.help_url": "https://example.com/get_secret", } self.assertDictEqual(result, expected)
def test_parameter_type_string(self): spec = load_spec({ "id_name": "testme", "name": "Test Module", "category": "Clean", "parameters": [{ "id_name": "hello", "type": "string", "name": "Hello there!", "placeholder": "Hey", "multiline": False, "default": "H", }], }) result = find_spec_messages(spec) expected = { "_spec.name": "Test Module", "_spec.parameters.hello.name": "Hello there!", "_spec.parameters.hello.placeholder": "Hey", "_spec.parameters.hello.default": "H", } self.assertDictEqual(result, expected)
def test_ignore_empty(self): spec = ModuleSpec( **{ "id_name": "testme", "name": "Test Module", "description": "", "category": "Clean", "parameters": [ { "id_name": "hello", "type": "list", "name": "", "child_parameters": [ {"id_name": "hello2", "type": "statictext", "name": ""} ], }, { "id_name": "hello3", "type": "string", "name": "Hello there!", "placeholder": "", "multiline": True, "default": "", }, ], } ) result = find_spec_messages(spec) expected = { "_spec.name": "Test Module", "_spec.parameters.hello3.name": "Hello there!", } self.assertDictEqual(result, expected)
def test_parameter_type_gdrivefile(self): spec = load_spec({ "id_name": "googlesheets", "name": "Test Module", "category": "Clean", "parameters": [ { "id_name": "google", "type": "secret", "secret_logic": { "provider": "oauth2", "service": "google" }, }, { "id_name": "hello2", "type": "gdrivefile", "secret_parameter": "google", }, ], }) result = find_spec_messages(spec) expected = {"_spec.name": "Test Module"} self.assertDictEqual(result, expected)
def test_parameter_type_menu(self): spec = ModuleSpec( **{ "id_name": "testme", "name": "Test Module", "category": "Clean", "parameters": [ { "id_name": "hello", "type": "menu", "name": "Hello there!", "placeholder": "Choose something...", "options": [ {"label": "First", "value": "first"}, "separator", {"label": "Second", "value": "second"}, ], "default": "first", } ], } ) result = find_spec_messages(spec) expected = { "_spec.name": "Test Module", "_spec.parameters.hello.name": "Hello there!", "_spec.parameters.hello.placeholder": "Choose something...", "_spec.parameters.hello.options.first.label": "First", "_spec.parameters.hello.options.second.label": "Second", } self.assertDictEqual(result, expected)
def test_only_required(self): spec = load_spec({ "id_name": "testme", "name": "Test Module", "category": "Clean", "parameters": [], }) result = find_spec_messages(spec) expected = {"_spec.name": "Test Module"} self.assertDictEqual(result, expected)
def test_parameter_type_file(self): spec = ModuleSpec( **{ "id_name": "testme", "name": "Test Module", "category": "Clean", "parameters": [{"id_name": "hello", "type": "file"}], } ) result = find_spec_messages(spec) expected = {"_spec.name": "Test Module"} self.assertDictEqual(result, expected)
def test_parameter_type_custom(self): spec = ModuleSpec( **{ "id_name": "testme", "name": "Test Module", "category": "Clean", "parameters": [ {"id_name": "hello", "type": "custom", "name": "Hello there!"} ], } ) result = find_spec_messages(spec) expected = { "_spec.name": "Test Module", "_spec.parameters.hello.name": "Hello there!", } self.assertDictEqual(result, expected)
def test_parameter_type_secret_oauth1a(self): spec = ModuleSpec( **{ "id_name": "twitter", "name": "Test Module", "category": "Clean", "parameters": [ { "id_name": "hello", "type": "secret", "secret_logic": {"provider": "oauth1a", "service": "twitter"}, } ], } ) result = find_spec_messages(spec) expected = {"_spec.name": "Test Module"} self.assertDictEqual(result, expected)
def _build_source_catalog( spec: ModuleSpec, module_code_path: pathlib.Path, module_root_directory: pathlib.Path, ) -> Catalog: source_catalog = Catalog(default_locale) for message_id, source_string in find_spec_messages(spec).items(): source_catalog.add(message_id, string=source_string) for message_id, message_properties in find_messages_in_module_code( module_code_path, module_root_directory).items(): source_catalog.add( message_id, string=message_properties["string"], auto_comments=message_properties["comments"], locations=message_properties["locations"], ) return source_catalog
def _build_source_catalog(module_zipfile: ModuleZipfile) -> Catalog: source_catalog = Catalog(default_locale) spec = module_zipfile.get_spec() for message_id, source_string in find_spec_messages(spec).items(): source_catalog.add(message_id, string=source_string) with zipfile.ZipFile(module_zipfile.path, mode="r") as zf: for info in zf.infolist(): if info.filename.endswith(".py"): with zf.open(info) as code_io: for message_id, message_properties in find_messages_in_module_code( code_io, info.filename).items(): source_catalog.add( message_id, string=message_properties["string"], auto_comments=message_properties["comments"], locations=message_properties["locations"], ) return source_catalog
def test_parameter_type_radio(self): spec = _make_module_spec({ "id_name": "testme", "name": "Test Module", "category": "Clean", "parameters": [{ "id_name": "hello", "type": "button", "name": "Hello there!" }], }) result = find_spec_messages(spec) expected = { "_spec.name": "Test Module", "_spec.parameters.hello.name": "Hello there!", } self.assertDictEqual(result, expected)
def test_parameter_type_multichartseries(self): spec = load_spec({ "id_name": "testme", "name": "Test Module", "category": "Clean", "parameters": [{ "id_name": "hello", "type": "multichartseries", "name": "Hello there!", }], }) result = find_spec_messages(spec) expected = { "_spec.name": "Test Module", "_spec.parameters.hello.name": "Hello there!", } self.assertDictEqual(result, expected)
def test_parameter_type_numberformat(self): spec = _make_module_spec({ "id_name": "testme", "name": "Test Module", "category": "Clean", "parameters": [{ "id_name": "hello", "type": "numberformat", "name": "Hello there!", "placeholder": "Fill me", }], }) result = find_spec_messages(spec) expected = { "_spec.name": "Test Module", "_spec.parameters.hello.name": "Hello there!", "_spec.parameters.hello.placeholder": "Fill me", } self.assertDictEqual(result, expected)
def test_parameter_type_integer(self): spec = ModuleSpec( **{ "id_name": "testme", "name": "Test Module", "category": "Clean", "parameters": [{ "id_name": "hello", "type": "integer", "name": "Hello there!", "placeholder": "Hey", "default": 3, }], }) result = find_spec_messages(spec) expected = { "_spec.name": "Test Module", "_spec.parameters.hello.name": "Hello there!", "_spec.parameters.hello.placeholder": "Hey", } self.assertDictEqual(result, expected)