Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1531)

Side by Side Diff: build/android/emma_coverage_stats_test.py

Issue 1284083004: Fractional line coverage + logging change. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/android/emma_coverage_stats.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import os 6 import os
7 import sys 7 import sys
8 import unittest 8 import unittest
9 from xml.etree import ElementTree 9 from xml.etree import ElementTree
10 10
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 'total': 5 394 'total': 5
395 }, 395 },
396 'incremental': { 396 'incremental': {
397 'covered': 2.05, 397 'covered': 2.05,
398 'total': 3 398 'total': 3
399 }, 399 },
400 'source': [ 400 'source': [
401 { 401 {
402 'line': line_coverage[0].source, 402 'line': line_coverage[0].source,
403 'coverage': line_coverage[0].covered_status, 403 'coverage': line_coverage[0].covered_status,
404 'changed': True 404 'changed': True,
405 'fractional_coverage': line_coverage[0].fractional_line_coverage,
405 }, 406 },
406 { 407 {
407 'line': line_coverage[1].source, 408 'line': line_coverage[1].source,
408 'coverage': line_coverage[1].covered_status, 409 'coverage': line_coverage[1].covered_status,
409 'changed': False 410 'changed': False,
411 'fractional_coverage': line_coverage[1].fractional_line_coverage,
410 }, 412 },
411 { 413 {
412 'line': line_coverage[2].source, 414 'line': line_coverage[2].source,
413 'coverage': line_coverage[2].covered_status, 415 'coverage': line_coverage[2].covered_status,
414 'changed': True 416 'changed': True,
417 'fractional_coverage': line_coverage[2].fractional_line_coverage,
415 }, 418 },
416 { 419 {
417 'line': line_coverage[3].source, 420 'line': line_coverage[3].source,
418 'coverage': line_coverage[3].covered_status, 421 'coverage': line_coverage[3].covered_status,
419 'changed': False 422 'changed': False,
423 'fractional_coverage': line_coverage[3].fractional_line_coverage,
420 }, 424 },
421 { 425 {
422 'line': line_coverage[4].source, 426 'line': line_coverage[4].source,
423 'coverage': line_coverage[4].covered_status, 427 'coverage': line_coverage[4].covered_status,
424 'changed': True 428 'changed': True,
429 'fractional_coverage': line_coverage[4].fractional_line_coverage,
425 }, 430 },
426 { 431 {
427 'line': line_coverage[5].source, 432 'line': line_coverage[5].source,
428 'coverage': line_coverage[5].covered_status, 433 'coverage': line_coverage[5].covered_status,
429 'changed': True 434 'changed': True,
435 'fractional_coverage': line_coverage[5].fractional_line_coverage,
430 } 436 }
431 ] 437 ]
432 } 438 }
433 result_dict = self.simple_coverage.GetCoverageDictForFile( 439 result_dict = self.simple_coverage.GetCoverageDictForFile(
434 '/fake/src', lines) 440 '/fake/src', lines)
435 self.assertDictEqual(result_dict, expected_dict) 441 self.assertDictEqual(result_dict, expected_dict)
436 442
437 def testGetCoverageDictForFile_emptyCoverage(self): 443 def testGetCoverageDictForFile_emptyCoverage(self):
438 expected_dict = { 444 expected_dict = {
439 'absolute': {'covered': 0, 'total': 0}, 445 'absolute': {'covered': 0, 'total': 0},
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 1, '', emma_coverage_stats.NOT_COVERED, 1.0), 481 1, '', emma_coverage_stats.NOT_COVERED, 1.0),
476 emma_coverage_stats.LineCoverage( 482 emma_coverage_stats.LineCoverage(
477 2, '', emma_coverage_stats.COVERED, 1.0) 483 2, '', emma_coverage_stats.COVERED, 1.0)
478 ] 484 ]
479 } 485 }
480 expected_dict = { 486 expected_dict = {
481 'files': { 487 'files': {
482 '/path/2/File2.java': { 488 '/path/2/File2.java': {
483 'absolute': {'covered': 1, 'total': 2}, 489 'absolute': {'covered': 1, 'total': 2},
484 'incremental': {'covered': 1, 'total': 2}, 490 'incremental': {'covered': 1, 'total': 2},
485 'source': [{'changed': True, 'coverage': 0, 'line': ''}, 491 'source': [{'changed': True, 'coverage': 0,
486 {'changed': True, 'coverage': 1, 'line': ''}] 492 'line': '', 'fractional_coverage': 1.0},
493 {'changed': True, 'coverage': 1,
494 'line': '', 'fractional_coverage': 1.0}]
487 }, 495 },
488 '/path/to/1/File1.java': { 496 '/path/to/1/File1.java': {
489 'absolute': {'covered': 2.5, 'total': 3}, 497 'absolute': {'covered': 2.5, 'total': 3},
490 'incremental': {'covered': 2, 'total': 2}, 498 'incremental': {'covered': 2, 'total': 2},
491 'source': [{'changed': True, 'coverage': 1, 'line': ''}, 499 'source': [{'changed': True, 'coverage': 1,
492 {'changed': False, 'coverage': 2, 'line': ''}, 500 'line': '', 'fractional_coverage': 1.0},
493 {'changed': True, 'coverage': -1, 'line': ''}, 501 {'changed': False, 'coverage': 2,
494 {'changed': True, 'coverage': 1, 'line': ''}] 502 'line': '', 'fractional_coverage': 0.5},
503 {'changed': True, 'coverage': -1,
504 'line': '', 'fractional_coverage': 1.0},
505 {'changed': True, 'coverage': 1,
506 'line': '', 'fractional_coverage': 1.0}]
495 } 507 }
496 }, 508 },
497 'patch': {'incremental': {'covered': 3, 'total': 4}} 509 'patch': {'incremental': {'covered': 3, 'total': 4}}
498 } 510 }
499 # Return the relevant coverage info for each file. We aren't testing 511 # Return the relevant coverage info for each file.
500 # _GetCoverageStatusForFile here.
501 self.simple_coverage._emma_parser.GetLineCoverage = ( 512 self.simple_coverage._emma_parser.GetLineCoverage = (
502 lambda x: coverage_info[x]) 513 lambda x: coverage_info[x])
503 result_dict = self.simple_coverage.GetCoverageDict(files_for_coverage) 514 result_dict = self.simple_coverage.GetCoverageDict(files_for_coverage)
504 self.assertDictEqual(result_dict, expected_dict) 515 self.assertDictEqual(result_dict, expected_dict)
505 516
506 def testGetCoverageDict_noCoverage(self): 517 def testGetCoverageDict_noCoverage(self):
507 result_dict = self.simple_coverage.GetCoverageDict({}) 518 result_dict = self.simple_coverage.GetCoverageDict({})
508 self.assertDictEqual(result_dict, EMPTY_COVERAGE_STATS_DICT) 519 self.assertDictEqual(result_dict, EMPTY_COVERAGE_STATS_DICT)
509 520
510 521
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 mock_open = mock.mock_open() 555 mock_open = mock.mock_open()
545 mock_open.side_effect = [mock.mock_open(read_data=side_effect).return_value 556 mock_open.side_effect = [mock.mock_open(read_data=side_effect).return_value
546 for side_effect in side_effects] 557 for side_effect in side_effects]
547 with mock.patch('__builtin__.open', mock_open): 558 with mock.patch('__builtin__.open', mock_open):
548 return func(**kwargs), mock_open 559 return func(**kwargs), mock_open
549 560
550 561
551 if __name__ == '__main__': 562 if __name__ == '__main__':
552 # Suppress logging messages. 563 # Suppress logging messages.
553 unittest.main(buffer=True) 564 unittest.main(buffer=True)
OLDNEW
« no previous file with comments | « build/android/emma_coverage_stats.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698