def test_property_table_json(): tbl = PropertyTable(data=dummy_data, metadata={"baz": "2"}) s = tbl.dumps() parsed = json.loads(s) assert parsed["data"] == tbl.data.as_list() tmp_dir = scratch_path / "property_table_json" tmp_dir.mkdir() tbl.dump((tmp_dir / "tbl.json").open("w")) parsed = json.load((tmp_dir / "tbl.json").open()) assert parsed["data"] == tbl.data.as_list()
def test_property_table_json(): tbl = PropertyTable(data=dummy_data, metadata={"baz": "2"}) s = tbl.dumps() parsed = json.loads(s) assert parsed["data"] == tbl.data.as_list() with TempDir() as d: fp = open(os.path.join(d, "tbl.json"), "w") tbl.dump(fp) fp.close() fp = open(os.path.join(d, "tbl.json"), "r") parsed = json.load(fp) assert parsed["data"] == tbl.data.as_list()
def test_property_table_json(): tbl = PropertyTable(data=dummy_data, metadata={'baz': '2'}) s = tbl.dumps() parsed = json.loads(s) assert parsed['data'] == tbl.data.as_list() with TempDir() as d: fp = open(os.path.join(d, 'tbl.json'), 'w') tbl.dump(fp) fp.close() fp = open(os.path.join(d, 'tbl.json'), 'r') parsed = json.load(fp) assert parsed['data'] == tbl.data.as_list()
def test_property_table_from_json(): tmp_dir = scratch_path / "property_table_from_json" tmp_dir.mkdir() prop_path = tmp_dir / "prop.json" for gj in good_table_json: json.dump(gj, prop_path.open("w")) tbl = PropertyTable.load(prop_path.open()) assert tbl.data.num_columns == 2
def test_property_table_from_json(): with TempDir() as d: filename = os.path.join(d, "prop.json") for gj in good_table_json: fp = open(filename, "w") json.dump(gj, fp) fp.close() fp = open(filename, "r") tbl = PropertyTable.load(fp) assert tbl.data.num_columns == 2 os.unlink(filename)
def test_property_table_objinit(): d = PropertyData(dummy_data) m = PropertyMetadata({"bar": "y"}) tbl = PropertyTable(data=d, metadata=m) assert tbl.data.as_list()[0]["units"] == "none" assert tbl.metadata[0].as_dict()["bar"] == "y"
def test_property_table(): tbl = PropertyTable(data=dummy_data, metadata=[]) assert tbl.data is not None assert tbl.metadata is not None
def test_property_table_empty(): with pytest.raises(ValueError): PropertyTable(data=[], metadata=[])
def test_property_table_objinit(): d = PropertyData(dummy_data) m = PropertyMetadata({'bar': 'y'}) tbl = PropertyTable(data=d, metadata=m) assert tbl.data.as_list()[0]['units'] == 'none' assert tbl.metadata[0].as_dict()['bar'] == 'y'