@@ -85,54 +85,58 @@ def test_format_results_for_report():
8585
8686 search = FakeSearch (config )
8787
88+ # Create a fake result set for _format_results_for_report to work on
8889 fake_results = OrderedDict ()
90+
91+ # First file has 6 annotations. expected_group_id is a special key for this test, allowing us to loop through
92+ # these below and know what group each result should be in.
8993 fake_results ['foo/bar.py' ] = [
9094 {
9195 'found_by' : 'test' ,
9296 'filename' : 'foo/bar.py' ,
9397 'line_number' : 1 ,
9498 'annotation_token' : 'token2' ,
95- 'annotation_data' : 'Group id 1' ,
99+ 'annotation_data' : 'file 1 annotation 1' ,
96100 'expected_group_id' : 1
97101 },
98102 {
99103 'found_by' : 'test' ,
100104 'filename' : 'foo/bar.py' ,
101105 'line_number' : 2 ,
102106 'annotation_token' : 'foo' ,
103- 'annotation_data' : 'Group id 1 ' ,
107+ 'annotation_data' : 'file 1 annotation 2 ' ,
104108 'expected_group_id' : 1
105109 },
106110 {
107111 'found_by' : 'test' ,
108112 'filename' : 'foo/bar.py' ,
109113 'line_number' : 4 ,
110114 'annotation_token' : 'not_in_a_group' ,
111- 'annotation_data' : 'Not in a group ' ,
115+ 'annotation_data' : 'file 1 annotation 3 ' ,
112116 'expected_group_id' : None
113117 },
114118 {
115119 'found_by' : 'test' ,
116120 'filename' : 'foo/bar.py' ,
117121 'line_number' : 10 ,
118122 'annotation_token' : 'token1' ,
119- 'annotation_data' : 'Group id 2 ' ,
123+ 'annotation_data' : 'file 1 annotation 4 ' ,
120124 'expected_group_id' : 2
121125 },
122126 {
123127 'found_by' : 'test' ,
124128 'filename' : 'foo/bar.py' ,
125129 'line_number' : 12 ,
126130 'annotation_token' : 'token2' ,
127- 'annotation_data' : 'Group id 3 ' ,
131+ 'annotation_data' : 'file 1 annotation 5 ' ,
128132 'expected_group_id' : 3
129133 },
130134 {
131135 'found_by' : 'test' ,
132136 'filename' : 'foo/bar.py' ,
133137 'line_number' : 13 ,
134138 'annotation_token' : 'foo' ,
135- 'annotation_data' : 'Group id 3 ' ,
139+ 'annotation_data' : 'file 1 annotation 6 ' ,
136140 'expected_group_id' : 3
137141 },
138142 ]
@@ -143,27 +147,31 @@ def test_format_results_for_report():
143147 'filename' : 'foo/bar.py' ,
144148 'line_number' : 1 ,
145149 'annotation_token' : 'token2' ,
146- 'annotation_data' : 'Group id 1' ,
150+ 'annotation_data' : 'file 2 annotation 1' ,
147151 'expected_group_id' : 4
148152 },
149153 {
150154 'found_by' : 'test' ,
151155 'filename' : 'foo/bar.py' ,
152156 'line_number' : 2 ,
153157 'annotation_token' : 'foo' ,
154- 'annotation_data' : 'Group id 1 ' ,
158+ 'annotation_data' : 'file 1 annotation 2 ' ,
155159 'expected_group_id' : 4
156160 }
157161 ]
158162
163+ # Run the format function
159164 results = search ._format_results_for_report (fake_results ) # pylint: disable=protected-access
160165
161166 for filename in fake_results :
162167 for fake in fake_results [filename ]:
163168 for formatted in results [filename ]:
169+ # When we find the same annotation, make sure that grouping is correct
164170 if fake ['annotation_data' ] == formatted ['annotation_data' ]:
171+ # Ungrouped annotations should not have the 'report_group_id' key
165172 if fake ['expected_group_id' ] is None :
166173 assert 'report_group_id' not in formatted
174+ # Otherwise it should match our expected value
167175 else :
168176 assert fake ['expected_group_id' ] == formatted ['report_group_id' ]
169177 break
0 commit comments