~homeworkprod/syslogmp

329b9539c79171bade13b862f607780c7a7b8117 — Jochen Kupperschmidt 3 years ago 1e3da99
Use f-strings
2 files changed, 4 insertions(+), 6 deletions(-)

M syslogmp/parser.py
M tests/test_parser.py
M syslogmp/parser.py => syslogmp/parser.py +2 -4
@@ 87,8 87,7 @@ class Parser(object):
        # given ("ValueError: day is out of range for month") in which
        # case the (non-leap) year 1900 would be used.
        current_year = datetime.today().year
        timestamp_ascii_with_year = '{:d} {}'.format(current_year,
                                                     timestamp_ascii)
        timestamp_ascii_with_year = f'{current_year:d} {timestamp_ascii}'

        try:
            timestamp = datetime.strptime(timestamp_ascii_with_year,


@@ 126,8 125,7 @@ class PriorityValue(namedtuple('PriorityValue', 'facility severity')):
            priority_value_number = int(priority_value)
        except ValueError:
            raise MessageFormatError(
                "Priority value must be a number, but is '{}'."
                    .format(priority_value))
                "Priority value must be a number, but is '{priority_value}'.")

        facility_id, severity_id = divmod(priority_value_number, 8)


M tests/test_parser.py => tests/test_parser.py +2 -2
@@ 135,7 135,7 @@ def test_parse_erroneous_message(data):
)
def test_parse_leap_day_in_leap_year(current_year):
    data = b'<165>Feb 29 19:56:43 localhost foobar'
    fake_date = '{:d}-01-01'.format(current_year)
    fake_date = f'{current_year:d}-01-01'
    expected_timestamp = datetime(current_year, 2, 29, 19, 56, 43)

    with freeze_time(fake_date):


@@ 155,7 155,7 @@ def test_parse_leap_day_in_leap_year(current_year):
)
def test_parse_leap_day_in_non_leap_year(current_year):
    data = b'<165>Feb 29 19:56:43 localhost foobar'
    fake_date = '{:d}-01-01'.format(current_year)
    fake_date = f'{current_year:d}-01-01'

    with pytest.raises(MessageFormatError):
        with freeze_time(fake_date):