6
6
7
7
def test_search_with_no_arg (runner ):
8
8
result = runner .invoke (run , [])
9
- regex = re .compile (' ^Usage:' )
9
+ regex = re .compile (" ^Usage:" )
10
10
assert result .exit_code == 2
11
11
assert regex .match (result .output )
12
12
13
13
14
14
def test_search_with_multiple_args (runner ):
15
- result = runner .invoke (run , [' foo' , ' bar' ])
16
- regex = re .compile (' ^Usage:' )
15
+ result = runner .invoke (run , [" foo" , " bar" ])
16
+ regex = re .compile (" ^Usage:" )
17
17
assert result .exit_code == 2
18
18
assert regex .match (result .output )
19
19
20
20
21
21
def test_search_str_port (runner , create_ports ):
22
22
create_ports ([["foo" , "1234" , "My description" , "tcp" ]])
23
- result = runner .invoke (run , [' foo' ])
23
+ result = runner .invoke (run , [" foo" ])
24
24
assert result .exit_code == 0
25
25
assert "foo" in result .output
26
26
assert "1234" in result .output
@@ -30,7 +30,7 @@ def test_search_str_port(runner, create_ports):
30
30
31
31
def test_search_int_port (runner , create_ports ):
32
32
create_ports ([["foo" , "1234" , "My description" , "tcp" ]])
33
- result = runner .invoke (run , [' 1234' ])
33
+ result = runner .invoke (run , [" 1234" ])
34
34
assert result .exit_code == 0
35
35
assert "foo" in result .output
36
36
assert "1234" in result .output
@@ -39,42 +39,50 @@ def test_search_int_port(runner, create_ports):
39
39
40
40
41
41
def test_search_str_like_port (runner , create_ports ):
42
- create_ports ([
43
- ["foo" , "1" , "My description" , "tcp" ],
44
- ["foobar" , "2" , "My description" , "udp" ],
45
- ["baz" , "3" , "My description" , "tcp" ]
46
- ])
47
-
48
- result = runner .invoke (run , ['foo' , '--like' ])
42
+ create_ports (
43
+ [
44
+ ["foo" , "1" , "My description" , "tcp" ],
45
+ ["foobar" , "2" , "My description" , "udp" ],
46
+ ["baz" , "3" , "My description" , "tcp" ],
47
+ ]
48
+ )
49
+
50
+ result = runner .invoke (run , ["foo" , "--like" ])
49
51
assert result .exit_code == 0
50
- assert result .output .count (' foo' ) == 2
52
+ assert result .output .count (" foo" ) == 2
51
53
52
- result = runner .invoke (run , [' bar' , ' --like' ])
54
+ result = runner .invoke (run , [" bar" , " --like" ])
53
55
assert result .exit_code == 0
54
- assert result .output .count (' bar' ) == 1
56
+ assert result .output .count (" bar" ) == 1
55
57
56
58
57
59
def test_search_int_like_port (runner , create_ports ):
58
- create_ports ([
59
- ["foo" , "8" , "My description" , "tcp" ],
60
- ["foobar" , "9" , "My description" , "udp" ],
61
- ["baz" , "80" , "My description" , "tcp" ]
62
- ])
63
-
64
- result = runner .invoke (run , ['8' , '--like' ])
60
+ create_ports (
61
+ [
62
+ ["foo" , "8" , "My description" , "tcp" ],
63
+ ["foobar" , "9" , "My description" , "udp" ],
64
+ ["baz" , "80" , "My description" , "tcp" ],
65
+ ]
66
+ )
67
+
68
+ result = runner .invoke (run , ["8" , "--like" ])
65
69
assert result .exit_code == 0
66
- assert result .output .count ('8' ) == 2
70
+ assert result .output .count ("8" ) == 2
67
71
68
72
69
73
def test_search_port_returns_json (runner , create_ports ):
70
74
create_ports ([["foo" , "1234" , "My description" , "tcp" ]])
71
- result = runner .invoke (run , [' --json' , ' foo' ])
75
+ result = runner .invoke (run , [" --json" , " foo" ])
72
76
73
77
result = json .loads (result .output )
74
- wanted = [{
75
- 'description' : 'My description' ,
76
- 'name' : 'foo' ,
77
- 'port' : '1234' ,
78
- 'protocol' : 'tcp'
79
- }]
80
- assert sorted (result , key = lambda p : p ["name" ]) == sorted (wanted , key = lambda p : p ["name" ])
78
+ wanted = [
79
+ {
80
+ "description" : "My description" ,
81
+ "name" : "foo" ,
82
+ "port" : "1234" ,
83
+ "protocol" : "tcp" ,
84
+ }
85
+ ]
86
+ assert sorted (result , key = lambda p : p ["name" ]) == sorted (
87
+ wanted , key = lambda p : p ["name" ]
88
+ )
0 commit comments