Skip to content

Commit 47de9c1

Browse files
authored
Update vlan regex to allow more vlans or vlanranges separated by commas (#49)
* Update vlan regex to allow more vlans or vlanranges separated by commas * Bumpversion to 1.10.3 * Fix code formatting
1 parent d57b527 commit 47de9c1

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.10.2
2+
current_version = 1.10.3
33
commit = False
44
tag = False
55
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?

nwastdlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#
1414
"""The NWA-stdlib module."""
1515

16-
__version__ = "1.10.2"
16+
__version__ = "1.10.3"
1717

1818
from nwastdlib.f import const, identity
1919

nwastdlib/vlans.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from pydantic.json_schema import JsonSchemaValue
2626
from pydantic_core import CoreSchema, SchemaSerializer, core_schema
2727

28-
VLAN_RANGE_JSON_SCHEMA_REGEX = r"^(?:([1-9]|[1-9]\d{1,2}|[1-4]\d{3})(?:-(?:[1-9]|[1-9]\d{1,2}|[1-4]\d{3}))?)$"
28+
VLAN_RANGE_JSON_SCHEMA_REGEX = r"^(?:[1-9]\d{0,2}|[1-4]\d{3})(?:-(?:[1-9]\d{0,2}|[1-4]\d{3}))?(?:\s*,\s*(?:[1-9]\d{0,2}|[1-4]\d{3})(?:-(?:[1-9]\d{0,2}|[1-4]\d{3}))?)*$"
2929

3030

3131
def to_ranges(i: Iterable[int]) -> Iterable[range]:

tests/test_vlans.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,17 @@ def test_vlan_rejected_by_schema(vlan, vr_schema):
317317
jsonschema.validate({"vr": str(vlan)}, vr_schema)
318318

319319

320-
@pytest.mark.parametrize("vlanrange", ["1-1", "9-9", "49-59", "99-300", "999-1001", "3999-4999"])
320+
@pytest.mark.parametrize(
321+
"vlanrange", ["1-1", "9-9", "49-59", "99-300", "999-1001", "3999-4999", "10,20,50-100", "10, 20, 50-100"]
322+
)
321323
def test_vlan_ranges_allowed_by_schema(vlanrange, vr_schema):
322324
"""Test vlan ranges which should be allowed by the JSON Schema."""
323325
assert jsonschema.validate({"vr": vlanrange}, vr_schema) is None
324326

325327

326-
@pytest.mark.parametrize("vlanrange", ["-1", "-10-0", "0-1", "4999-5000", "5000-5002"])
328+
@pytest.mark.parametrize(
329+
"vlanrange", ["-1", "-10-0", "0-1", "4999-5000", "5000-5002", "10,20,5000-5002", "10, 20, 5000-5002"]
330+
)
327331
def test_vlan_ranges_rejected_by_schema(vlanrange, vr_schema):
328332
"""Test vlan ranges which should be rejected by the JSON Schema."""
329333
with pytest.raises(jsonschema.ValidationError):

0 commit comments

Comments
 (0)