Example #1
0
    def test_dataset_xml_str_source_around_line_negative_context_lines(
            self, data, num_lines_xml):
        """Test obtaining source around a particular line.

        The number of context lines is negative.
        """
        for line_num in range(0, num_lines_xml):
            with pytest.raises(ValueError):
                data.source_around_line(line_num, -1)
Example #2
0
    def test_dataset_xml_str_source_around_line_invalid_context_lines(
            self, invalid_value, data, num_lines_xml):
        """Test obtaining source of a particular line.

        The specified number of context lines is not an integer.
        """
        for line_num in range(0, num_lines_xml):
            with pytest.raises(TypeError):
                data.source_around_line(line_num, invalid_value)
Example #3
0
    def test_dataset_xml_str_source_around_line_single_line(
            self, data, split_xml_str, num_lines_xml):
        """Test obtaining source around a particular line.

        The context is such that only the specified line will be returned.
        """
        for line_num in range(0, num_lines_xml):
            assert data.source_around_line(line_num,
                                           0) == split_xml_str[line_num]
            assert data.source_around_line(
                line_num, 0).strip() == data.source_at_line(line_num)
Example #4
0
    def test_dataset_xml_str_source_around_line_first_line(
            self, data, split_xml_str):
        """Test obtaining source around a particular line.

        The line is at the start of an XML document such that there will not be full context before the specified line, but will be afterwards.
        Line numbers are valid.
        Uses the default number of surrounding context lines.
        """
        assert data.source_around_line(0) == '\n'.join(split_xml_str[1:2])
Example #5
0
    def test_dataset_xml_str_source_around_line_full_file(
            self, data, num_lines_xml):
        """Test obtaining source around a particular line.

        The context is such that the full file will be returned.
        """
        line_num = int(num_lines_xml / 2)
        context_lines = num_lines_xml

        assert data.source_around_line(line_num, context_lines) == data.xml_str
Example #6
0
    def test_dataset_xml_str_source_around_line_last_line(
            self, data, split_xml_str, num_lines_xml):
        """Test obtaining source around a particular line.

        The line is at the end of an XML document such that there will not be full context after the specified line, but will be before.
        Line numbers are valid.
        Uses the default number of surrounding context lines.
        """
        assert data.source_around_line(num_lines_xml - 1) == '\n'.join(
            split_xml_str[-2:])
Example #7
0
    def test_dataset_xml_str_source_around_line_valid_line_number(
            self, data, split_xml_str, num_lines_xml):
        """Test obtaining source around a particular line.

        The line is in the middle of an XML document so that there will be full context both before and after the specified line number.
        Line numbers are valid.
        Uses the default number of surrounding context lines.
        """
        for line_num in range(2, num_lines_xml):
            desired_source = '\n'.join(split_xml_str[line_num - 1:line_num +
                                                     2])
            actual_source = data.source_around_line(line_num)

            assert actual_source == desired_source
Example #8
0
    def test_dataset_xml_str_source_around_line_late_line_custom_context(
            self, data, split_xml_str, num_lines_xml):
        """Test obtaining source around a particular line.

        The lines are around the end of an XML document such that there will not be full context after the specified line, but will be before.
        Line numbers are valid.
        Uses the default number of surrounding context lines.
        """
        for context_lines in range(1, math.ceil(num_lines_xml / 2)):
            for line_num in range(0, context_lines):
                desired_source = '\n'.join(
                    split_xml_str[-(line_num + context_lines + 1):])
                actual_source = data.source_around_line(
                    num_lines_xml - line_num - 1, context_lines)

                assert actual_source == desired_source
Example #9
0
    def test_dataset_xml_str_source_around_line_valid_line_number_custom_context(
            self, data, split_xml_str, num_lines_xml):
        """Test obtaining source around a particular line.

        The lines are in the middle of an XML document so that there will be full context both before and after the specified line number.
        Line numbers are valid.
        Uses a custom number of surrounding context lines.
        """
        for context_lines in range(1, math.ceil(num_lines_xml / 2)):
            for line_num in range(context_lines,
                                  num_lines_xml - context_lines):
                desired_source = '\n'.join(
                    split_xml_str[max(line_num - context_lines, 1):line_num +
                                  context_lines + 1])
                actual_source = data.source_around_line(
                    line_num, context_lines)

                assert actual_source == desired_source