def test_dataset_xml_str_source_at_line_invalid_line_number( self, data, num_lines_xml): """Test obtaining source of a particular line. Line numbers are not valid.""" with pytest.raises(ValueError): data.source_at_line(-1) with pytest.raises(ValueError): data.source_at_line(num_lines_xml)
def test_dataset_xml_str_source_at_line_matches_tree(self, line_el_pair): """Test obtaining source of a particular line. Line numbers are valid. Ensure that the line numbers from which source is being returned are the same ones provided by the `sourceline` attribute from tree elements. """ data = iati.tests.resources.load_as_dataset('valid_not_iati') split_xml_str = [''] + data.xml_str.split('\n') line_num = line_el_pair['line'] el_from_tree = data.xml_tree.xpath(line_el_pair['el'])[0] str_from_tree = etree.tostring( el_from_tree, pretty_print=True).strip().decode('utf-8').split('\n')[0] assert el_from_tree.sourceline == line_num assert data.source_at_line(line_num) == str_from_tree assert data.source_at_line(line_num) == split_xml_str[line_num].strip()
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)
def test_dataset_xml_str_source_at_line_invalid_line_type( self, invalid_value, data): """Test obtaining source of a particular line. Line numbers are not valid.""" with pytest.raises(TypeError): data.source_at_line(invalid_value)
def test_dataset_xml_str_source_at_line_valid_line_number( self, data, split_xml_str): """Test obtaining source of a particular line. Line numbers are valid.""" for idx, line in enumerate(split_xml_str): assert data.source_at_line(idx) == line.strip()