Esempio n. 1
0
def test_write_data_arguments():
    msg = pandasdmx.read_sdmx(test_files(kind="data")["argvalues"][0])

    # Attributes must be a string
    with raises(TypeError):
        pandasdmx.to_pandas(msg, attributes=2)

    # Attributes must contain only 'dgso'
    with raises(ValueError):
        pandasdmx.to_pandas(msg, attributes="foobarbaz")
Esempio n. 2
0
def pytest_generate_tests(metafunc):
    if "data_path" in metafunc.fixturenames:
        params = []
        tf = test_files(kind="data")
        for value, id in zip(tf["argvalues"], tf["ids"]):
            kwargs = dict(id=id)
            for cond, info in file_marks.items():
                if cond in str(value):
                    kwargs["marks"] = pytest.mark.skip(reason=info[2])
                    break

            params.append(pytest.param(value, **kwargs))

        metafunc.parametrize("data_path", params)
Esempio n. 3
0
import pytest

import pandasdmx
from pandasdmx.tests.data import specimen, test_files


@pytest.mark.parametrize("path", **test_files(format="json"))
def test_json_read(path):
    """Test that the samples from the pandasdmx.JSON spec can be read."""
    pandasdmx.read_sdmx(path)


def test_header():
    with specimen("flat.json") as f:
        resp = pandasdmx.read_sdmx(f)
    assert resp.header.id == "62b5f19d-f1c9-495d-8446-a3661ed24753"
Esempio n. 4
0
def test_write_data(data_path):
    msg = pandasdmx.read_sdmx(data_path)

    result = pandasdmx.to_pandas(msg)

    expected = expected_data(data_path)
    if expected is not None:
        print(expected, result, sep="\n")
    assert_pd_equal(expected, result)

    # TODO incomplete
    assert isinstance(result, (pd.Series, pd.DataFrame, list)), type(result)


@pytest.mark.parametrize("path", **test_files(kind="data"))
def test_write_data_attributes(path):
    msg = pandasdmx.read_sdmx(path)

    result = pandasdmx.to_pandas(msg, attributes="osgd")
    # TODO incomplete
    assert isinstance(result, (pd.Series, pd.DataFrame, list)), type(result)


def test_write_agencyscheme():
    # Convert an agency scheme
    with specimen("ECB/orgscheme.xml") as f:
        msg = pandasdmx.read_sdmx(f)
        data = pandasdmx.to_pandas(msg)

    assert data["organisation_scheme"]["AGENCIES"]["ESTAT"] == "Eurostat"
Esempio n. 5
0
import re
from io import BytesIO
from itertools import chain

import pytest
from lxml import etree

import pandasdmx
from pandasdmx.format.xml import qname
from pandasdmx.model import Facet, FacetType, FacetValueType
from pandasdmx.reader.sdmxml import Reader, XMLParseError
from pandasdmx.tests.data import specimen, test_files


# Read example data files
@pytest.mark.parametrize("path", **test_files(format="xml", kind="data"))
def test_read_xml(path):
    pandasdmx.read_sdmx(path)


# Read example structure files
@pytest.mark.parametrize("path", **test_files(format="xml", kind="structure"))
def test_read_xml_structure(path):
    pandasdmx.read_sdmx(path)


def test_read_xml_structure_insee():
    with specimen("IPI-2010-A21-structure.xml") as f:
        msg = pandasdmx.read_sdmx(f)

    # Same objects referenced