@@ -16,34 +16,16 @@ def run_cli(args):
1616 return result
1717
1818
19- def strip_whitespace (string ):
19+ def strip (string ):
2020 return re .sub ('\s+' , '' , string )
2121
2222
23- def compare_output (args , expected ):
24- output = strip_whitespace (run_cli (args ).output )
25- expected_output = strip_whitespace (expected )
26- return output == expected_output
23+ def assert_output_eq (args , expected ):
24+ assert strip (run_cli (args ).output ) == strip (expected )
2725
2826
29- EMPTY_MESSAGE = """{
30- "attributes": {},
31- "description": "",
32- "host": "%s",
33- "metric_d": 0,
34- "metric_f": 0,
35- "metric_sint64": 0,
36- "service": "",
37- "state": "",
38- "tags": [],
39- "time": 0,
40- "ttl": 0
41- }
42- """
43-
44-
45- def test_send_blank ():
46- assert compare_output (['send' ], EMPTY_MESSAGE % socket .gethostname ())
27+ def test_send_empty_message ():
28+ assert_output_eq (['send' ], '{"host": "%s"}' % socket .gethostname ())
4729
4830
4931POPULATED_MESSAGE = """{
@@ -52,9 +34,7 @@ def test_send_blank():
5234 },
5335 "description": "description",
5436 "host": "%s",
55- "metric_d": 0,
5637 "metric_f": 11.1,
57- "metric_sint64": 0,
5838 "service": "service",
5939 "state": "state",
6040 "tags": [
@@ -63,11 +43,11 @@ def test_send_blank():
6343 "time": 1408030991,
6444 "ttl": 120
6545}
66- """
46+ """ % socket . gethostname ()
6747
6848
6949def test_send ():
70- assert compare_output ([
50+ assert_output_eq ([
7151 'send' ,
7252 '--attribute' , 'key=value' ,
7353 '--description' , 'description' ,
@@ -77,11 +57,11 @@ def test_send():
7757 '--tag' , 'tag' ,
7858 '--time' , '1408030991' ,
7959 '--ttl' , '120'
80- ], POPULATED_MESSAGE % socket . gethostname () )
60+ ], POPULATED_MESSAGE )
8161
8262
8363def test_send_short ():
84- assert compare_output ([
64+ assert_output_eq ([
8565 'send' ,
8666 '-a' , 'key=value' ,
8767 '-d' , 'description' ,
@@ -91,8 +71,8 @@ def test_send_short():
9171 '-t' , 'tag' ,
9272 '-T' , '1408030991' ,
9373 '-l' , '120'
94- ], POPULATED_MESSAGE % socket . gethostname () )
74+ ], POPULATED_MESSAGE )
9575
9676
9777def test_query ():
98- assert compare_output (['query' , 'true' ], '[]' )
78+ assert_output_eq (['query' , 'true' ], '[]' )
0 commit comments