Index: build/android/emma_coverage_stats_test.py |
diff --git a/build/android/emma_coverage_stats_test.py b/build/android/emma_coverage_stats_test.py |
index d12c3252dae416cdc04ff66f193c83961a5fbf88..e4f95069544dced5e44d4150721493a9576a3cd4 100755 |
--- a/build/android/emma_coverage_stats_test.py |
+++ b/build/android/emma_coverage_stats_test.py |
@@ -3,7 +3,6 @@ |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
-import json |
import os |
import sys |
import unittest |
@@ -233,11 +232,6 @@ class _EmmaHtmlParserTest(unittest.TestCase): |
return_dict = self.parser.GetPackageNameToEmmaFileDict() |
self.assertDictEqual({}, return_dict) |
- def testGetPackageNameToEmmaFileDict_badFilePath(self): |
- self.parser._FindElements = mock.Mock(return_value=[]) |
- return_dict = self.parser.GetPackageNameToEmmaFileDict() |
- self.assertEqual(return_dict, {}) |
- |
def testGetLineCoverage_status_basic(self): |
line_coverage = self.GetLineCoverageWithFakeElements([self.covered_tr_html]) |
self.assertEqual(line_coverage[0].covered_status, |
@@ -281,11 +275,7 @@ class _EmmaHtmlParserTest(unittest.TestCase): |
self.assertEqual(len(line_coverage), 3) |
def GetLineCoverageWithFakeElements(self, html_elements): |
- """Wraps GetLineCoverage to work with extra whitespace characters. |
- |
- The test HTML strings include extra whitespace characters to make the HTML |
- human readable. This isn't the case with EMMA HTML files, so we need to |
- remove all the unnecessary whitespace. |
+ """Wraps GetLineCoverage so mock HTML can easily be used. |
Args: |
html_elements: List of strings each representing an HTML element. |
@@ -393,27 +383,10 @@ class _EmmaCoverageStatsTest(unittest.TestCase): |
package_names.keys()) |
self.assertDictEqual(result_dict, self.good_source_to_emma) |
- def testGetLineCoverageForFile_basic(self): |
- java_file_path = '/path/to/1/File1.java' |
- line_coverage = emma_coverage_stats.LineCoverage( |
- 1, '', emma_coverage_stats.COVERED, 1.0) |
- expected_line_coverage = list(line_coverage) |
- coverage_stats = self.simple_coverage |
- coverage_stats._source_to_emma = self.good_source_to_emma |
- coverage_stats._emma_parser.GetLineCoverage = mock.MagicMock( |
- return_value=expected_line_coverage) |
- coverage_info = coverage_stats._GetLineCoverageForFile(java_file_path) |
- self.assertListEqual(coverage_info, expected_line_coverage) |
- |
- def testGetLineCoverageForFile_noInfo(self): |
- with mock.patch('os.path.exists', return_value=False): |
- coverage_info = self.simple_coverage._GetLineCoverageForFile('fake_path') |
- self.assertIsNone(coverage_info) |
- |
def testGetCoverageDictForFile(self): |
line_coverage = self.line_coverage |
- self.simple_coverage._GetLineCoverageForFile = mock.Mock( |
- return_value=line_coverage) |
+ self.simple_coverage._emma_parser.GetLineCoverage = lambda x: line_coverage |
+ self.simple_coverage._source_to_emma = {'/fake/src': 'fake/emma'} |
lines = self.lines_for_coverage |
expected_dict = { |
'absolute': { |
@@ -458,26 +431,36 @@ class _EmmaCoverageStatsTest(unittest.TestCase): |
] |
} |
result_dict = self.simple_coverage.GetCoverageDictForFile( |
- line_coverage, lines) |
+ '/fake/src', lines) |
self.assertDictEqual(result_dict, expected_dict) |
def testGetCoverageDictForFile_emptyCoverage(self): |
expected_dict = { |
- 'absolute': {'covered': 0, 'total': 0}, |
- 'incremental': {'covered': 0, 'total': 0}, |
- 'source': [] |
+ 'absolute': {'covered': 0, 'total': 0}, |
+ 'incremental': {'covered': 0, 'total': 0}, |
+ 'source': [] |
} |
- self.simple_coverage._GetLineCoverageForFile = mock.Mock(return_value=[]) |
+ self.simple_coverage._emma_parser.GetLineCoverage = lambda x: [] |
+ self.simple_coverage._source_to_emma = {'fake_dir': 'fake/emma'} |
result_dict = self.simple_coverage.GetCoverageDictForFile('fake_dir', {}) |
self.assertDictEqual(result_dict, expected_dict) |
- def testGetCoverageDictFor_basic(self): |
+ def testGetCoverageDictForFile_missingCoverage(self): |
+ self.simple_coverage._source_to_emma = {} |
+ result_dict = self.simple_coverage.GetCoverageDictForFile('fake_file', {}) |
+ self.assertIsNone(result_dict) |
+ |
+ def testGetCoverageDict_basic(self): |
files_for_coverage = { |
'/path/to/1/File1.java': [1, 3, 4], |
'/path/2/File2.java': [1, 2] |
} |
+ self.simple_coverage._source_to_emma = { |
+ '/path/to/1/File1.java': 'emma_1', |
+ '/path/2/File2.java': 'emma_2' |
+ } |
coverage_info = { |
- '/path/to/1/File1.java': [ |
+ 'emma_1': [ |
emma_coverage_stats.LineCoverage( |
1, '', emma_coverage_stats.COVERED, 1.0), |
emma_coverage_stats.LineCoverage( |
@@ -487,7 +470,7 @@ class _EmmaCoverageStatsTest(unittest.TestCase): |
emma_coverage_stats.LineCoverage( |
4, '', emma_coverage_stats.COVERED, 1.0) |
], |
- '/path/2/File2.java': [ |
+ 'emma_2': [ |
emma_coverage_stats.LineCoverage( |
1, '', emma_coverage_stats.NOT_COVERED, 1.0), |
emma_coverage_stats.LineCoverage( |
@@ -515,9 +498,9 @@ class _EmmaCoverageStatsTest(unittest.TestCase): |
} |
# Return the relevant coverage info for each file. We aren't testing |
# _GetCoverageStatusForFile here. |
- self.simple_coverage._GetLineCoverageForFile = lambda x: coverage_info[x] |
- result_dict = self.simple_coverage.GetCoverageDict( |
- files_for_coverage) |
+ self.simple_coverage._emma_parser.GetLineCoverage = ( |
+ lambda x: coverage_info[x]) |
+ result_dict = self.simple_coverage.GetCoverageDict(files_for_coverage) |
self.assertDictEqual(result_dict, expected_dict) |
def testGetCoverageDict_noCoverage(self): |