Exemple #1
0
def test_callable_func_converters(parser):
    with pytest.raises(TypeError, match=("'float' object is not callable")):
        read_xml(xml_types, converters={"degrees": float()}, parser=parser)
Exemple #2
0
def test_wrong_encoding(datapath, parser):
    filename = datapath("io", "data", "xml", "baby_names.xml")
    with pytest.raises(UnicodeDecodeError,
                       match=("'utf-8' codec can't decode")):
        read_xml(filename, parser=parser)
Exemple #3
0
def test_ascii_encoding(datapath, parser):
    filename = datapath("io", "data", "xml", "baby_names.xml")
    with pytest.raises(UnicodeDecodeError,
                       match=("'ascii' codec can't decode byte")):
        read_xml(filename, encoding="ascii", parser=parser)
Exemple #4
0
def test_missing_prefix_definition_etree(datapath):
    filename = datapath("io", "data", "xml", "cta_rail_lines.kml")
    with pytest.raises(SyntaxError,
                       match=("you used an undeclared namespace prefix")):
        read_xml(filename, xpath=".//kml:Placemark", parser="etree")
Exemple #5
0
def test_names_option_wrong_length(datapath, parser):
    filename = datapath("io", "data", "xml", "books.xml")

    with pytest.raises(ValueError, match=("names does not match length")):
        read_xml(filename, names=["Col1", "Col2", "Col3"], parser=parser)
Exemple #6
0
def test_empty_xpath_lxml(datapath):
    filename = datapath("io", "data", "xml", "books.xml")
    with pytest.raises(ValueError, match=("xpath does not return any nodes")):
        read_xml(filename, xpath=".//python", parser="lxml")
Exemple #7
0
def test_bad_xpath_lxml(datapath):
    from lxml.etree import XPathEvalError

    filename = datapath("io", "data", "xml", "books.xml")
    with pytest.raises(XPathEvalError, match=("Invalid expression")):
        read_xml(filename, xpath=".//[book]", parser="lxml")
Exemple #8
0
def test_parser_consistency_file(datapath):
    filename = datapath("io", "data", "xml", "books.xml")
    df_file_lxml = read_xml(filename, parser="lxml")
    df_file_etree = read_xml(filename, parser="etree")

    tm.assert_frame_equal(df_file_lxml, df_file_etree)
Exemple #9
0
def test_file_only_attrs(datapath, parser):
    filename = datapath("io", "data", "xml", "books.xml")
    df_file = read_xml(filename, attrs_only=True, parser=parser)
    df_expected = DataFrame({"category": ["cooking", "children", "web"]})

    tm.assert_frame_equal(df_file, df_expected)
Exemple #10
0
def test_wrong_encoding_option_lxml(datapath, parser, encoding):
    filename = datapath("io", "data", "xml", "baby_names.xml")
    df_file = read_xml(filename, encoding="ISO-8859-1", parser="lxml")

    with tm.ensure_clean("test.xml") as path:
        df_file.to_xml(path, index=False, encoding=encoding, parser=parser)
Exemple #11
0
def test_wrong_compression_gz(parser, comp):
    with tm.ensure_clean() as path:
        geom_df.to_xml(path, parser=parser, compression=comp)

        with pytest.raises(OSError, match="Not a gzipped file"):
            read_xml(path, parser=parser, compression="gzip")
Exemple #12
0
def test_correct_encoding_file(datapath):
    filename = datapath("io", "data", "xml", "baby_names.xml")
    df_file = read_xml(filename, encoding="ISO-8859-1", parser="lxml")

    with tm.ensure_clean("test.xml") as path:
        df_file.to_xml(path, index=False, encoding="ISO-8859-1", parser="lxml")
Exemple #13
0
def test_wrong_parse_dates_type(parser):
    with pytest.raises(
            TypeError,
            match=("Only booleans, lists, and dictionaries are accepted")):
        read_xml(xml_dates, parse_dates={"date"}, parser=parser)
Exemple #14
0
def test_callable_str_converters(parser):
    with pytest.raises(TypeError, match=("'str' object is not callable")):
        read_xml(xml_types, converters={"degrees": "float"}, parser=parser)
Exemple #15
0
def test_empty_string_etree(val):
    from xml.etree.ElementTree import ParseError

    with pytest.raises(ParseError, match="no element found"):
        read_xml(val, parser="etree")
Exemple #16
0
def test_parser_consistency_with_encoding(datapath):
    filename = datapath("io", "data", "xml", "baby_names.xml")
    df_lxml = read_xml(filename, parser="lxml", encoding="ISO-8859-1")
    df_etree = read_xml(filename, parser="etree", encoding="iso-8859-1")

    tm.assert_frame_equal(df_lxml, df_etree)
Exemple #17
0
def test_wrong_url(parser):
    with pytest.raises(HTTPError, match=("HTTP Error 404: Not Found")):
        url = "https://www.w3schools.com/xml/python.xml"
        read_xml(url, xpath=".//book[count(*)=4]", parser=parser)
Exemple #18
0
def test_wrong_compression_bz2(parser, comp):
    with tm.ensure_clean() as path:
        geom_df.to_xml(path, parser=parser, compression=comp)

        with pytest.raises(OSError, match="Invalid data stream"):
            read_xml(path, parser=parser, compression="bz2")
Exemple #19
0
def test_bad_xpath_etree(datapath):
    filename = datapath("io", "data", "xml", "books.xml")
    with pytest.raises(
            SyntaxError,
            match=("You have used an incorrect or unsupported XPath")):
        read_xml(filename, xpath=".//[book]", parser="etree")
Exemple #20
0
def test_wrong_dict_value(datapath, parser):
    filename = datapath("io", "data", "xml", "books.xml")
    with pytest.raises(
            TypeError,
            match="<class 'str'> is not a valid type for value in iterparse"):
        read_xml(filename, parser=parser, iterparse={"book": "category"})
Exemple #21
0
def test_missing_prefix_with_default_namespace(datapath, parser):
    filename = datapath("io", "data", "xml", "books.xml")
    with pytest.raises(ValueError, match=("xpath does not return any nodes")):
        read_xml(filename, xpath=".//Placemark", parser=parser)
Exemple #22
0
def test_unsuported_compression(parser):
    with pytest.raises(ValueError, match="Unrecognized compression type"):
        with tm.ensure_clean() as path:
            read_xml(path, parser=parser, compression="7z")
Exemple #23
0
def test_missing_prefix_definition_lxml(datapath):
    from lxml.etree import XPathEvalError

    filename = datapath("io", "data", "xml", "cta_rail_lines.kml")
    with pytest.raises(XPathEvalError, match=("Undefined namespace prefix")):
        read_xml(filename, xpath=".//kml:Placemark", parser="lxml")
Exemple #24
0
def read_xml_iterparse(data, **kwargs):
    with tm.ensure_clean() as path:
        with open(path, "w") as f:
            f.write(data)
        return read_xml(path, **kwargs)
Exemple #25
0
def test_names_option_wrong_type(datapath, parser):
    filename = datapath("io", "data", "xml", "books.xml")

    with pytest.raises(TypeError, match=("is not a valid type for names")):
        read_xml(filename, names="Col1, Col2, Col3", parser=parser)
Exemple #26
0
def read_xml_iterparse_comp(comp_path, compression_only, **kwargs):
    with get_handle(comp_path, "r", compression=compression_only) as handles:
        with tm.ensure_clean() as path:
            with open(path, "w") as f:
                f.write(handles.handle.read())
            return read_xml(path, **kwargs)
Exemple #27
0
def test_unknown_encoding(datapath, parser):
    filename = datapath("io", "data", "xml", "baby_names.xml")
    with pytest.raises(LookupError, match=("unknown encoding: UFT-8")):
        read_xml(filename, encoding="UFT-8", parser=parser)
Exemple #28
0
def test_empty_string_lxml(val):
    from lxml.etree import XMLSyntaxError

    with pytest.raises(XMLSyntaxError, match="Document is empty"):
        read_xml(val, parser="lxml")
Exemple #29
0
def test_wrong_parser(datapath):
    filename = datapath("io", "data", "xml", "books.xml")

    with pytest.raises(ValueError,
                       match=("Values for parser can only be lxml or etree.")):
        read_xml(filename, parser="bs4")
Exemple #30
0
def test_wrong_converters_type(parser):
    with pytest.raises(TypeError,
                       match=("Type converters must be a dict or subclass")):
        read_xml(xml_types, converters={"degrees", str}, parser=parser)