from pyra.plugins.base import BasePlugin, ConfigField def test_config_field_minimal(): f = ConfigField("mykey", "My Label", "text") assert f.key == "mykey" assert f.label == "My Label" assert f.type == "text" assert f.default == "" assert f.options == [] assert f.description == "" def test_config_field_options_are_independent(): f1 = ConfigField("k", "L", "select") f2 = ConfigField("k", "L", "select") f1.options.append("x") assert f2.options == [], "options lists must not be shared between instances" def test_config_field_all_args(): f = ConfigField("url", "API URL", "select", "http://a.com", ["opt1", "opt2"], "hint text") assert f.default == "http://a.com" assert f.options == ["opt1", "opt2"] assert f.description == "hint text" def test_config_field_bool_type(): f = ConfigField("enabled", "Enable feature", "bool", True) assert f.type == "bool" assert f.default is True def test_base_plugin_config_fields_returns_empty(): assert BasePlugin().config_fields() == [] def test_plugin_subclass_config_fields_override(): class MyPlugin(BasePlugin): name = "test" description = "test plugin" version = "1.0" def config_fields(self): return [ ConfigField("api_url", "API URL", "text", "http://example.com"), ConfigField("verify_ssl", "Verify SSL", "bool", True), ] fields = MyPlugin().config_fields() assert len(fields) == 2 assert fields[0].key == "api_url" assert fields[0].type == "text" assert fields[1].key == "verify_ssl" assert fields[1].type == "bool" assert fields[1].default is True