Exemplo n.º 1
0
    def test_covered_and_uncovered_src(self, mock_num_file_lines):

        # Set an expected source file
        coverage_data = CoverageData()
        coverage_data.add_expected_src('/root_dir', 'uncovered.js')

        # Configure the num file lines for the source file
        num_lines = 10
        mock_num_file_lines.return_value = num_lines

        # Provide coverage info for other source files,
        # but not the one we passed to the constructor
        coverage_data.load_from_dict('/root_dir', '', self.TEST_COVERAGE_DICT)

        # Expect that all sources are reported (including the uncovered src)
        self.assertEqual(coverage_data.src_list(), 
                         [u'/root_dir/src1.js',
                          u'/root_dir/subdir/src2.js',
                          u'/root_dir/uncovered.js'])

        # Expect that the source is reported as 0% covered
        self.assertEqual(coverage_data.line_dict_for_src('/root_dir/uncovered.js'),
                         {line_num: False for line_num in range(num_lines)})

        # Expect that total coverage is smaller because
        # of the uncovered file.
        expected_coverage = 6.0 / (8.0 + num_lines)
        self.assertEqual(coverage_data.total_coverage(), expected_coverage)
Exemplo n.º 2
0
    def test_missing_key(self):

        # Load data with a JSON dict that is missing the line keys
        coverage_data = CoverageData()
        coverage_data.load_from_dict('root_dir', '',
                                     {'/src1': {'missing key': True}})

        # Expect that no coverage information is loaded
        self.assertEqual(coverage_data.src_list(), [])
        self.assertIs(coverage_data.line_dict_for_src('root_dir/src1'), None)
Exemplo n.º 3
0
    def test_load_from_dict(self):

        # Load the data
        coverage_data = CoverageData()
        coverage_data.load_from_dict('/root_dir', '', self.TEST_COVERAGE_DICT)

        # Check that it gets parsed correctly
        self.assertEqual(coverage_data.src_list(),
                         [u'/root_dir/src1.js', u'/root_dir/subdir/src2.js'])

        self.assertEqual(coverage_data.line_dict_for_src('/root_dir/src1.js'),
                         {0: True, 2: True, 3: False, 5: True})

        self.assertEqual(coverage_data.line_dict_for_src('/root_dir/subdir/src2.js'),
                         {0: True, 1: True, 2: True, 3: False})
Exemplo n.º 4
0
    def test_different_root_dirs(self):

        # Load data from two different root dirs
        coverage_data = CoverageData()
        coverage_data.load_from_dict('/root_1', '', self.TEST_COVERAGE_DICT)
        coverage_data.load_from_dict('/root_2', '', self.TEST_COVERAGE_DICT)

        # We should get two separate sources
        self.assertEqual(coverage_data.src_list(),
                         ['/root_1/src1.js', '/root_1/subdir/src2.js',
                          '/root_2/src1.js', '/root_2/subdir/src2.js'])

        # But the data in each should be the same
        expected = {0: True, 2: True, 3: False, 5: True}
        self.assertEqual(coverage_data.line_dict_for_src('/root_1/src1.js'),
                         expected)
        self.assertEqual(coverage_data.line_dict_for_src('/root_2/src1.js'),
                         expected)
Exemplo n.º 5
0
    def test_uncovered_src(self, mock_num_file_lines):

        # Set an expected source file
        coverage_data = CoverageData()
        coverage_data.add_expected_src('/root_dir', 'src1.js')

        # Configure the num file lines for the source file
        num_lines = 10
        mock_num_file_lines.return_value = num_lines

        # Provide no coverage information (did NOT call `load_from_dict()`)

        # Expect that the source is still reported
        self.assertEqual(coverage_data.src_list(), ['/root_dir/src1.js'])
        self.assertEqual(coverage_data.rel_src_path('/root_dir/src1.js'), 'src1.js')

        # Expect that the source is reported as 0% covered
        self.assertEqual(coverage_data.line_dict_for_src('/root_dir/src1.js'),
                         {line_num: False for line_num in range(num_lines)})

        # Expect that total coverage is 0%
        self.assertEqual(coverage_data.total_coverage(), 0.0)