1
|
|
|
""" |
2
|
|
|
:Copyright: 2007-2021 Jochen Kupperschmidt |
3
|
|
|
:License: MIT, see LICENSE for details. |
4
|
|
|
""" |
5
|
|
|
|
6
|
|
|
import pytest |
7
|
|
|
|
8
|
|
|
from syslog2irc.network import format_port, parse_port, Port, TransportProtocol |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
@pytest.mark.parametrize( |
12
|
|
|
'port, expected', |
13
|
|
|
[ |
14
|
|
|
(Port(514, TransportProtocol.TCP), '514/tcp'), |
15
|
|
|
(Port(514, TransportProtocol.UDP), '514/udp'), |
16
|
|
|
(Port(12514, TransportProtocol.UDP), '12514/udp'), |
17
|
|
|
], |
18
|
|
|
) |
19
|
|
|
def test_format_port(port, expected): |
20
|
|
|
assert format_port(port) == expected |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
@pytest.mark.parametrize( |
24
|
|
|
'value, expected', |
25
|
|
|
[ |
26
|
|
|
('514/tcp', Port(514, TransportProtocol.TCP)), |
27
|
|
|
('514/udp', Port(514, TransportProtocol.UDP)), |
28
|
|
|
('12514/udp', Port(12514, TransportProtocol.UDP)), |
29
|
|
|
], |
30
|
|
|
) |
31
|
|
|
def test_parse_port(value, expected): |
32
|
|
|
assert parse_port(value) == expected |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
@pytest.mark.parametrize( |
36
|
|
|
'value', |
37
|
|
|
[ |
38
|
|
|
'', |
39
|
|
|
'514', |
40
|
|
|
'514/x', |
41
|
|
|
'-514/udp', |
42
|
|
|
'/tcp', |
43
|
|
|
'udp/514', |
44
|
|
|
'udp', |
45
|
|
|
], |
46
|
|
|
) |
47
|
|
|
def test_parse_port_failure(value): |
48
|
|
|
with pytest.raises(ValueError): |
49
|
|
|
parse_port(value) |
50
|
|
|
|