Files
driver-standard/template/tests/test_parsers.py
T
christianmanivong db6b2e4ea7
CI / test (3.11) (push) Successful in 34s
CI / test (3.12) (push) Successful in 30s
CI / test (3.13) (push) Successful in 37s
feat: standards, shared CI and release tooling for NAPALM drivers
STANDARDS.md binds every repository in the NAPALM org: one default branch,
Conventional Commits, the device-types contract, test-driven development,
clean-code limits, a quality ratchet for existing code, packaging rules and
releases by tag to PyPI.

napalm-standard holds what a tool can check: the conformance check (with
release rules on a tag), the quality ratchet (ported from netOrk's
quality_ratchet.py), and the Gitea release from the CHANGELOG section.
.gitea/workflows/driver.yml is the CI every driver calls; template/ is a new
driver's starting point and passes the check as it is.
2026-10-22 19:01:14 +02:00

42 lines
1.1 KiB
Python

"""Parsers against recorded device output."""
from __future__ import annotations
import pathlib
import pytest
from napalm_example.parsers import parse_uptime, parse_version
FIXTURES = pathlib.Path(__file__).parent / "fixtures"
def test_version_output_becomes_facts() -> None:
text = (FIXTURES / "example24-1.0.0-show-version.txt").read_text()
assert parse_version(text) == {
"model": "Example 24",
"hostname": "sw-lab-01",
"os_version": "1.0.0",
"serial_number": "EX0000000001",
"uptime": 273906.0,
}
def test_a_missing_field_is_an_error_not_an_empty_value() -> None:
with pytest.raises(ValueError, match="Serial number"):
parse_version("Example 24 Switch\nHostname : a\nFirmware : 1\nUptime : 0:00:01\n")
@pytest.mark.parametrize(
("text", "seconds"),
[("0:00:01", 1.0), ("1 day, 0:00:00", 86400.0), ("3 days, 4:05:06", 273906.0)],
)
def test_uptime(text: str, seconds: float) -> None:
assert parse_uptime(text) == seconds
def test_an_unreadable_uptime_is_an_error() -> None:
with pytest.raises(ValueError, match="uptime"):
parse_uptime("soon")