def test_structure_roundtrip(pytestconfig, specimen_id, strict, tmp_path): """Test that pandasdmx.ML StructureMessages can be 'round-tripped'.""" # Read a specimen file with specimen(specimen_id) as f: msg0 = pandasdmx.read_sdmx(f) # Write to file path = tmp_path / "output.xml" path.write_bytes(pandasdmx.to_xml(msg0, pretty_print=True)) # Read again msg1 = pandasdmx.read_sdmx(path) # Contents are identical assert msg0.compare(msg1, strict), ( path.read_text() if pytestconfig.getoption("verbose") else path )
def test_structuremessage(tmp_path, structuremessage): result = pandasdmx.to_xml(structuremessage, pretty_print=True) print(result.decode()) # Message can be round-tripped to/from file path = tmp_path / "output.xml" path.write_bytes(result) msg = pandasdmx.read_sdmx(path) # Contents match the original object assert ( msg.codelist["CL_COLLECTION"]["A"].name["en"] == structuremessage.codelist["CL_COLLECTION"]["A"].name["en"] ) # False because `structuremessage` lacks URNs, which are constructed automatically # by `to_xml` assert not msg.compare(structuremessage, strict=True) # Compares equal when allowing this difference assert msg.compare(structuremessage, strict=False)
def test_data_roundtrip(pytestconfig, data_id, structure_id, tmp_path): """Test that SDMX-ML DataMessages can be 'round-tripped'.""" # Read structure from file with specimen(structure_id) as f: dsd = pandasdmx.read_sdmx(f).structure[0] # Read data from file, using the DSD with specimen(data_id) as f: msg0 = pandasdmx.read_sdmx(f, dsd=dsd) # Write to file path = tmp_path / "output.xml" path.write_bytes(pandasdmx.to_xml(msg0, pretty_print=True)) # Read again, using the same DSD msg1 = pandasdmx.read_sdmx(path, dsd=dsd) # Contents are identical assert msg0.compare(msg1, strict=True), ( path.read_text() if pytestconfig.getoption("verbose") else path )
def test_not_implemented(): msg = DataMessage() with pytest.raises(NotImplementedError, match="write DataMessage to XML"): pandasdmx.to_xml(msg)
def test_codelist(tmp_path, codelist): result = pandasdmx.to_xml(codelist, pretty_print=True) print(result.decode())