MCPcopy
hub / github.com/dmlc/dgl / _test_load_yaml_with_sanity_check

Function _test_load_yaml_with_sanity_check

tests/python/common/data/test_data.py:794–943  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

792
793
794def _test_load_yaml_with_sanity_check():
795 from dgl.data.csv_dataset_base import load_yaml_with_sanity_check
796
797 with tempfile.TemporaryDirectory() as test_dir:
798 yaml_path = os.path.join(test_dir, "meta.yaml")
799 # workable but meaningless usually
800 yaml_data = {
801 "dataset_name": "default",
802 "node_data": [],
803 "edge_data": [],
804 }
805 with open(yaml_path, "w") as f:
806 yaml.dump(yaml_data, f, sort_keys=False)
807 meta = load_yaml_with_sanity_check(yaml_path)
808 assert meta.version == "1.0.0"
809 assert meta.dataset_name == "default"
810 assert meta.separator == ","
811 assert len(meta.node_data) == 0
812 assert len(meta.edge_data) == 0
813 assert meta.graph_data is None
814 # minimum with required fields only
815 yaml_data = {
816 "version": "1.0.0",
817 "dataset_name": "default",
818 "node_data": [{"file_name": "nodes.csv"}],
819 "edge_data": [{"file_name": "edges.csv"}],
820 }
821 with open(yaml_path, "w") as f:
822 yaml.dump(yaml_data, f, sort_keys=False)
823 meta = load_yaml_with_sanity_check(yaml_path)
824 for ndata in meta.node_data:
825 assert ndata.file_name == "nodes.csv"
826 assert ndata.ntype == "_V"
827 assert ndata.graph_id_field == "graph_id"
828 assert ndata.node_id_field == "node_id"
829 for edata in meta.edge_data:
830 assert edata.file_name == "edges.csv"
831 assert edata.etype == ["_V", "_E", "_V"]
832 assert edata.graph_id_field == "graph_id"
833 assert edata.src_id_field == "src_id"
834 assert edata.dst_id_field == "dst_id"
835 # optional fields are specified
836 yaml_data = {
837 "version": "1.0.0",
838 "dataset_name": "default",
839 "separator": "|",
840 "node_data": [
841 {
842 "file_name": "nodes.csv",
843 "ntype": "user",
844 "graph_id_field": "xxx",
845 "node_id_field": "xxx",
846 }
847 ],
848 "edge_data": [
849 {
850 "file_name": "edges.csv",
851 "etype": ["user", "follow", "user"],

Callers 1

test_csvdatasetFunction · 0.85

Calls 5

dumpMethod · 0.80
joinMethod · 0.45
keysMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected