formatting

This commit is contained in:
Istvan Ruzman
2020-08-07 16:39:49 +02:00
parent dc2a24402b
commit e8dce3e2cf
2 changed files with 26 additions and 11 deletions

View File

@@ -9,7 +9,17 @@ Classes and Types to parse and represent a RADIUS dictionary.
from enum import IntEnum, Enum, auto
from dataclasses import dataclass
from os.path import dirname, isabs, join, normpath
from typing import cast, Dict, Generator, IO, List, Optional, Sequence, Tuple, Union
from typing import (
cast,
Dict,
Generator,
IO,
List,
Optional,
Sequence,
Tuple,
Union,
)
import logging
@@ -389,7 +399,10 @@ class Dictionary:
has_tag, encrypt = self._parse_attribute_flags(tokens, line_num)
name, attr_code, datatype = tokens[1:4]
if datatype in {"concat", "extended", "evs", "long-extended" } and self.cur_vendor != self.rfc_vendor:
if (
datatype in {"concat", "extended", "evs", "long-extended"}
and self.cur_vendor != self.rfc_vendor
):
raise ParseError(
filename,
'vendor attributes are not allowed to have the datatype "concat"',
@@ -440,7 +453,9 @@ class Dictionary:
len(codes) > 1,
)
attrcode: Union[int, Tuple[int, ...]] = codes[0] if len(codes) == 1 else tuple(codes)
attrcode: Union[int, Tuple[int, ...]] = codes[0] if len(
codes
) == 1 else tuple(codes)
self.cur_vendor.attrs[attrcode] = attribute
if self.cur_vendor != self.rfc_vendor:
@@ -461,14 +476,14 @@ class Dictionary:
(attr_name, key, vvalue) = tokens[1:]
try:
if '.' in vvalue:
if "." in vvalue:
# quick and dirty way to make floats values an error
raise ValueError
value = _parse_number(vvalue)
except ValueError:
raise ParseError(filename,
f"Invalid number {vvalue} for VALUE {key}",
line_num)
raise ParseError(
filename, f"Invalid number {vvalue} for VALUE {key}", line_num
)
attribute = self.attrindex[attr_name]
try:

View File

@@ -86,8 +86,7 @@ def test_valid_attribute_numbers(number):
@pytest.mark.parametrize(
"invalid_number",
["ABCD", "-1", "inf", "INF", "-INF", "2e4", "2.5e3"],
"invalid_number", ["ABCD", "-1", "inf", "INF", "-INF", "2e4", "2.5e3"],
)
def test_invalid_attribute_numbers(invalid_number):
dictionary = StringIO(f"ATTRIBUTE NAME {invalid_number} integer64")
@@ -269,7 +268,8 @@ def test_invalid_datatypes_in_vendor_space(datatype):
)
def test_invalid_attribute_numbers(invalid_number):
dictionary = StringIO(
f"ATTRIBUTE TEST-ATTRIBUTE 1 integer\n"
f"VALUE TEST-ATTRIBUTE TEST-VALUE {invalid_number}")
f"ATTRIBUTE TEST-ATTRIBUTE 1 integer\n"
f"VALUE TEST-ATTRIBUTE TEST-VALUE {invalid_number}"
)
with pytest.raises(ParseError):
Dictionary("", dictionary)