feat: add TYPE_LABEL class attribute to all base driver classes
Each abstract base class now carries a TYPE_LABEL: str attribute that describes the device category in human-readable form: AccessPointDriver → "Access Point" FirewallDriver → "Firewall" HypervisorDriver → "Hypervisor" OSDriver → "OS" ResidentialGatewayDriver → "Gateway" StorageDriver → "Storage" SwitchDriver → "Switch" Concrete drivers can override TYPE_LABEL to express a more specific category (e.g. LinuxDriver sets "Linux"). The backend reads this attribute to expose a type_label in the DriverInfo API response, replacing the hardcoded DRIVER_TYPE map in the frontend. 23 tests covering presence, value, inheritance, and override. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
"""Tests for TYPE_LABEL class attribute on all base driver classes."""
|
||||
|
||||
import pytest
|
||||
from napalm_device_types import (
|
||||
AccessPointDriver,
|
||||
FirewallDriver,
|
||||
HypervisorDriver,
|
||||
OSDriver,
|
||||
ResidentialGatewayDriver,
|
||||
StorageDriver,
|
||||
SwitchDriver,
|
||||
)
|
||||
|
||||
|
||||
BASE_CLASSES = [
|
||||
(AccessPointDriver, "Access Point"),
|
||||
(FirewallDriver, "Firewall"),
|
||||
(HypervisorDriver, "Hypervisor"),
|
||||
(OSDriver, "OS"),
|
||||
(ResidentialGatewayDriver, "Gateway"),
|
||||
(StorageDriver, "Storage"),
|
||||
(SwitchDriver, "Switch"),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("cls, expected_label", BASE_CLASSES)
|
||||
def test_type_label_present(cls, expected_label):
|
||||
assert hasattr(cls, "TYPE_LABEL"), f"{cls.__name__} is missing TYPE_LABEL"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("cls, expected_label", BASE_CLASSES)
|
||||
def test_type_label_value(cls, expected_label):
|
||||
assert cls.TYPE_LABEL == expected_label
|
||||
|
||||
|
||||
@pytest.mark.parametrize("cls, _", BASE_CLASSES)
|
||||
def test_type_label_is_nonempty_string(cls, _):
|
||||
assert isinstance(cls.TYPE_LABEL, str) and cls.TYPE_LABEL
|
||||
|
||||
|
||||
def test_subclass_inherits_type_label():
|
||||
class MySwitch(SwitchDriver):
|
||||
pass
|
||||
|
||||
assert MySwitch.TYPE_LABEL == "Switch"
|
||||
|
||||
|
||||
def test_subclass_can_override_type_label():
|
||||
class MySpecialOS(OSDriver):
|
||||
TYPE_LABEL = "Linux"
|
||||
|
||||
assert MySpecialOS.TYPE_LABEL == "Linux"
|
||||
assert OSDriver.TYPE_LABEL == "OS" # base class unaffected
|
||||
Reference in New Issue
Block a user