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 setUp(self):
     self.good_source_to_emma = {
         '/path/to/1/File1.java': '/emma/1.html',
         '/path/2/File2.java': '/emma/2.html',
         '/path/2/File3.java': '/emma/3.html'
     }
     self.line_coverage = [
         emma_coverage_stats.LineCoverage(1, '',
                                          emma_coverage_stats.COVERED, 1.0),
         emma_coverage_stats.LineCoverage(2, '',
                                          emma_coverage_stats.COVERED, 1.0),
         emma_coverage_stats.LineCoverage(
             3, '', emma_coverage_stats.NOT_EXECUTABLE, 1.0),
         emma_coverage_stats.LineCoverage(4, '',
                                          emma_coverage_stats.NOT_COVERED,
                                          1.0),
         emma_coverage_stats.LineCoverage(
             5, '', emma_coverage_stats.PARTIALLY_COVERED, 0.85),
         emma_coverage_stats.LineCoverage(
             6, '', emma_coverage_stats.PARTIALLY_COVERED, 0.20)
     ]
     self.lines_for_coverage = [1, 3, 5, 6]
     with mock.patch('emma_coverage_stats._EmmaHtmlParser._FindElements',
                     return_value=[]):
         self.simple_coverage = emma_coverage_stats._EmmaCoverageStats(
             'fake_dir', {})
Beispiel #3
0
 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 = {
     'emma_1': [
       emma_coverage_stats.LineCoverage(
           1, '', emma_coverage_stats.COVERED, 1.0),
       emma_coverage_stats.LineCoverage(
           2, '', emma_coverage_stats.PARTIALLY_COVERED, 0.5),
       emma_coverage_stats.LineCoverage(
           3, '', emma_coverage_stats.NOT_EXECUTABLE, 1.0),
       emma_coverage_stats.LineCoverage(
           4, '', emma_coverage_stats.COVERED, 1.0)
     ],
     'emma_2': [
       emma_coverage_stats.LineCoverage(
           1, '', emma_coverage_stats.NOT_COVERED, 1.0),
       emma_coverage_stats.LineCoverage(
           2, '', emma_coverage_stats.COVERED, 1.0)
     ]
   }
   expected_dict = {
     'files': {
       '/path/2/File2.java': {
         'absolute': {'covered': 1, 'total': 2},
         'incremental': {'covered': 1, 'total': 2},
         'source': [{'changed': True, 'coverage': 0,
                     'line': '', 'fractional_coverage': 1.0},
                    {'changed': True, 'coverage': 1,
                     'line': '', 'fractional_coverage': 1.0}]
       },
       '/path/to/1/File1.java': {
         'absolute': {'covered': 2.5, 'total': 3},
         'incremental': {'covered': 2, 'total': 2},
         'source': [{'changed': True, 'coverage': 1,
                     'line': '', 'fractional_coverage': 1.0},
                    {'changed': False, 'coverage': 2,
                     'line': '', 'fractional_coverage': 0.5},
                    {'changed': True, 'coverage': -1,
                     'line': '', 'fractional_coverage': 1.0},
                    {'changed': True, 'coverage': 1,
                     'line': '', 'fractional_coverage': 1.0}]
       }
     },
     'patch': {'incremental': {'covered': 3, 'total': 4}}
   }
   # Return the relevant coverage info for each file.
   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 testGetCoverageDictFor_basic(self):
     files_for_coverage = {
         '/path/to/1/File1.java': [1, 3, 4],
         '/path/2/File2.java': [1, 2]
     }
     coverage_info = {
         '/path/to/1/File1.java': [
             emma_coverage_stats.LineCoverage(1, '',
                                              emma_coverage_stats.COVERED,
                                              1.0),
             emma_coverage_stats.LineCoverage(
                 2, '', emma_coverage_stats.PARTIALLY_COVERED, 0.5),
             emma_coverage_stats.LineCoverage(
                 3, '', emma_coverage_stats.NOT_EXECUTABLE, 1.0),
             emma_coverage_stats.LineCoverage(4, '',
                                              emma_coverage_stats.COVERED,
                                              1.0)
         ],
         '/path/2/File2.java': [
             emma_coverage_stats.LineCoverage(
                 1, '', emma_coverage_stats.NOT_COVERED, 1.0),
             emma_coverage_stats.LineCoverage(2, '',
                                              emma_coverage_stats.COVERED,
                                              1.0)
         ]
     }
     expected_dict = {
         'files': {
             '/path/2/File2.java': {
                 'absolute': {
                     'covered': 1,
                     'total': 2
                 },
                 'incremental': {
                     'covered': 1,
                     'total': 2
                 },
                 'source': [{
                     'changed': True,
                     'coverage': 0,
                     'line': ''
                 }, {
                     'changed': True,
                     'coverage': 1,
                     'line': ''
                 }]
             },
             '/path/to/1/File1.java': {
                 'absolute': {
                     'covered': 2.5,
                     'total': 3
                 },
                 'incremental': {
                     'covered': 2,
                     'total': 2
                 },
                 'source': [{
                     'changed': True,
                     'coverage': 1,
                     'line': ''
                 }, {
                     'changed': False,
                     'coverage': 2,
                     'line': ''
                 }, {
                     'changed': True,
                     'coverage': -1,
                     'line': ''
                 }, {
                     'changed': True,
                     'coverage': 1,
                     'line': ''
                 }]
             }
         },
         'patch': {
             'incremental': {
                 'covered': 3,
                 'total': 4
             }
         }
     }
     # 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.assertDictEqual(result_dict, expected_dict)