|
19 | 19 | import unittest
|
20 | 20 |
|
21 | 21 | from compare_perf_tests import PerformanceTestResult
|
| 22 | +from compare_perf_tests import ReportFormatter |
22 | 23 | from compare_perf_tests import ResultComparison
|
23 | 24 | from compare_perf_tests import TestComparator
|
24 | 25 | from compare_perf_tests import parse_args
|
@@ -226,6 +227,149 @@ def names(tests):
|
226 | 227 | self.assertEquals(tc.decreased, [])
|
227 | 228 |
|
228 | 229 |
|
| 230 | +class TestReportFormatter(OldAndNewLog): |
| 231 | + def setUp(self): |
| 232 | + super(TestReportFormatter, self).setUp() |
| 233 | + self.tc = TestComparator(self.old_log, self.new_log, 0.05) |
| 234 | + self.rf = ReportFormatter(self.tc, '', '', changes_only=False) |
| 235 | + self.markdown = self.rf.markdown() |
| 236 | + self.git = self.rf.git() |
| 237 | + self.html = self.rf.html() |
| 238 | + |
| 239 | + def assert_report_contains(self, texts, report): |
| 240 | + # assert not isinstance(texts, str) |
| 241 | + if isinstance(texts, str): |
| 242 | + self.assertIn(texts, report) |
| 243 | + else: |
| 244 | + for text in texts: |
| 245 | + self.assertIn(text, report) |
| 246 | + |
| 247 | + def assert_markdown_contains(self, texts): |
| 248 | + self.assert_report_contains(texts, self.markdown) |
| 249 | + |
| 250 | + def assert_git_contains(self, texts): |
| 251 | + self.assert_report_contains(texts, self.git) |
| 252 | + |
| 253 | + def assert_html_contains(self, texts): |
| 254 | + self.assert_report_contains(texts, self.html) |
| 255 | + |
| 256 | + def test_justified_columns(self): |
| 257 | + """Table columns are all formated with same width, defined by the |
| 258 | + longest value. |
| 259 | + """ |
| 260 | + print self.markdown |
| 261 | + self.assert_markdown_contains([ |
| 262 | + 'AnyHashableWithAClass | 247027 | 319065 | 259056 | 10250445', |
| 263 | + 'Array2D | 335831 | 335831 | +0.0% | 1.00x']) |
| 264 | + self.assert_git_contains([ |
| 265 | + 'AnyHashableWithAClass 247027 319065 259056 10250445', |
| 266 | + 'Array2D 335831 335831 +0.0% 1.00x']) |
| 267 | + |
| 268 | + def test_column_headers(self): |
| 269 | + """Report contains table headers for ResultComparisons and changed |
| 270 | + PerformanceTestResults. |
| 271 | + """ |
| 272 | + print self.git |
| 273 | + self.assert_markdown_contains([ |
| 274 | + 'TEST | OLD | NEW | DELTA | SPEEDUP', |
| 275 | + '--- | --- | --- | --- | --- ', |
| 276 | + 'TEST | MIN | MAX | MEAN | MAX_RSS']) |
| 277 | + self.assert_git_contains([ |
| 278 | + 'TEST OLD NEW DELTA SPEEDUP', |
| 279 | + 'TEST MIN MAX MEAN MAX_RSS']) |
| 280 | + self.assert_html_contains([ |
| 281 | + """ |
| 282 | + <th align='left'>OLD</th> |
| 283 | + <th align='left'>NEW</th> |
| 284 | + <th align='left'>DELTA</th> |
| 285 | + <th align='left'>SPEEDUP</th>""", |
| 286 | + """ |
| 287 | + <th align='left'>MIN</th> |
| 288 | + <th align='left'>MAX</th> |
| 289 | + <th align='left'>MEAN</th> |
| 290 | + <th align='left'>MAX_RSS</th>"""]) |
| 291 | + |
| 292 | + def test_emphasize_speedup(self): |
| 293 | + """Emphasize speedup values for regressions and improvements""" |
| 294 | + # tests in No Changes don't have emphasized speedup |
| 295 | + self.assert_markdown_contains([ |
| 296 | + 'BitCount | 3 | 9 | +199.9% | **0.33x**', |
| 297 | + 'ByteSwap | 4 | 0 | -100.0% | **4001.00x**', |
| 298 | + 'AngryPhonebook | 10458 | 10458 | +0.0% | 1.00x ', |
| 299 | + 'ArrayAppend | 23641 | 20000 | -15.4% | **1.18x (?)**' |
| 300 | + ]) |
| 301 | + self.assert_git_contains([ |
| 302 | + 'BitCount 3 9 +199.9% **0.33x**', |
| 303 | + 'ByteSwap 4 0 -100.0% **4001.00x**', |
| 304 | + 'AngryPhonebook 10458 10458 +0.0% 1.00x', |
| 305 | + 'ArrayAppend 23641 20000 -15.4% **1.18x (?)**' |
| 306 | + ]) |
| 307 | + print self.html |
| 308 | + self.assert_html_contains([ |
| 309 | + """ |
| 310 | + <tr> |
| 311 | + <td align='left'>BitCount</td> |
| 312 | + <td align='left'>3</td> |
| 313 | + <td align='left'>9</td> |
| 314 | + <td align='left'>+199.9%</td> |
| 315 | + <td align='left'><font color='red'>0.33x</font></td> |
| 316 | + </tr>""", |
| 317 | + """ |
| 318 | + <tr> |
| 319 | + <td align='left'>ByteSwap</td> |
| 320 | + <td align='left'>4</td> |
| 321 | + <td align='left'>0</td> |
| 322 | + <td align='left'>-100.0%</td> |
| 323 | + <td align='left'><font color='green'>4001.00x</font></td> |
| 324 | + </tr>""", |
| 325 | + """ |
| 326 | + <tr> |
| 327 | + <td align='left'>AngryPhonebook</td> |
| 328 | + <td align='left'>10458</td> |
| 329 | + <td align='left'>10458</td> |
| 330 | + <td align='left'>+0.0%</td> |
| 331 | + <td align='left'><font color='black'>1.00x</font></td> |
| 332 | + </tr>""" |
| 333 | + ]) |
| 334 | + |
| 335 | + def test_sections(self): |
| 336 | + """Report is divided into sections with summaries.""" |
| 337 | + self.assert_markdown_contains([ |
| 338 | + """<details open> |
| 339 | + <summary>Regression (1)</summary>""", |
| 340 | + """<details > |
| 341 | + <summary>Improvement (2)</summary>""", |
| 342 | + """<details > |
| 343 | + <summary>No Changes (2)</summary>""", |
| 344 | + """<details open> |
| 345 | + <summary>Added (1)</summary>""", |
| 346 | + """<details open> |
| 347 | + <summary>Removed (1)</summary>"""]) |
| 348 | + self.assert_git_contains([ |
| 349 | + 'Regression (1): \n', |
| 350 | + 'Improvement (2): \n', |
| 351 | + 'No Changes (2): \n', |
| 352 | + 'Added (1): \n', |
| 353 | + 'Removed (1): \n']) |
| 354 | + self.assert_html_contains([ |
| 355 | + "<th align='left'>Regression (1)</th>", |
| 356 | + "<th align='left'>Improvement (2)</th>", |
| 357 | + "<th align='left'>No Changes (2)</th>", |
| 358 | + "<th align='left'>Added (1)</th>", |
| 359 | + "<th align='left'>Removed (1)</th>"]) |
| 360 | + |
| 361 | + def test_report_only_changes(self): |
| 362 | + """Leave out tests without significant change.""" |
| 363 | + rf = ReportFormatter(self.tc, '', '', changes_only=True) |
| 364 | + markdown, git, html = rf.markdown(), rf.git(), rf.html() |
| 365 | + self.assertNotIn('No Changes', markdown) |
| 366 | + self.assertNotIn('AngryPhonebook', markdown) |
| 367 | + self.assertNotIn('No Changes', git) |
| 368 | + self.assertNotIn('AngryPhonebook', git) |
| 369 | + self.assertNotIn('No Changes', html) |
| 370 | + self.assertNotIn('AngryPhonebook', html) |
| 371 | + |
| 372 | + |
229 | 373 | class Test_parse_args(unittest.TestCase):
|
230 | 374 | required = ['--old-file', 'old.log', '--new-file', 'new.log']
|
231 | 375 |
|
@@ -260,6 +404,12 @@ def test_delta_threshold_argument(self):
|
260 | 404 | self.assertRaises(SystemExit, parse_args,
|
261 | 405 | self.required + ['--delta-threshold', '2,2'])
|
262 | 406 |
|
| 407 | + def test_output_argument(self): |
| 408 | + self.assertEquals(parse_args(self.required).output, None) |
| 409 | + self.assertEquals(parse_args(self.required + |
| 410 | + ['--output', 'report.log']).output, |
| 411 | + 'report.log') |
| 412 | + |
263 | 413 | def test_changes_only_argument(self):
|
264 | 414 | self.assertFalse(parse_args(self.required).changes_only)
|
265 | 415 | self.assertTrue(parse_args(self.required +
|
|
0 commit comments