| 9 | |
| 10 | |
| 11 | class TestFromFile: |
| 12 | def test_from_all(self): |
| 13 | assert isinstance(box_from_file(Path(test_root, "data", "json_file.json")), Box) |
| 14 | assert isinstance(box_from_file(Path(test_root, "data", "toml_file.tml")), Box) |
| 15 | assert isinstance(box_from_file(Path(test_root, "data", "yaml_file.yaml")), Box) |
| 16 | assert isinstance(box_from_file(Path(test_root, "data", "json_file.json"), file_type="json"), Box) |
| 17 | assert isinstance(box_from_file(Path(test_root, "data", "toml_file.tml"), file_type="toml"), Box) |
| 18 | assert isinstance(box_from_file(Path(test_root, "data", "yaml_file.yaml"), file_type="yaml"), Box) |
| 19 | assert isinstance(box_from_file(Path(test_root, "data", "json_list.json")), BoxList) |
| 20 | assert isinstance(box_from_file(Path(test_root, "data", "yaml_list.yaml")), BoxList) |
| 21 | assert isinstance(box_from_file(Path(test_root, "data", "msgpack_file.msgpack")), Box) |
| 22 | assert isinstance(box_from_file(Path(test_root, "data", "msgpack_list.msgpack")), BoxList) |
| 23 | assert isinstance(box_from_file(Path(test_root, "data", "csv_file.csv")), BoxList) |
| 24 | |
| 25 | def test_from_file_box_options_csv(self): |
| 26 | bl = box_from_file(Path(test_root, "data", "csv_file.csv"), frozen_box=True) |
| 27 | assert bl[1].Name == "Sam" |
| 28 | with pytest.raises(BoxError): |
| 29 | bl[1].Name = "Pat" |
| 30 | |
| 31 | def test_bad_file(self): |
| 32 | with pytest.raises(BoxError): |
| 33 | box_from_file(Path(test_root, "data", "bad_file.txt"), file_type="json") |
| 34 | with pytest.raises(BoxError): |
| 35 | box_from_file(Path(test_root, "data", "bad_file.txt"), file_type="toml") |
| 36 | with pytest.raises(BoxError): |
| 37 | box_from_file(Path(test_root, "data", "bad_file.txt"), file_type="yaml") |
| 38 | with pytest.raises(BoxError): |
| 39 | box_from_file(Path(test_root, "data", "bad_file.txt"), file_type="msgpack") |
| 40 | with pytest.raises(BoxError): |
| 41 | box_from_file(Path(test_root, "data", "bad_file.txt"), file_type="unknown") |
| 42 | with pytest.raises(BoxError): |
| 43 | box_from_file(Path(test_root, "data", "bad_file.txt")) |
| 44 | with pytest.raises(BoxError): |
| 45 | box_from_file("does not exist") |
| 46 | |
| 47 | def test_from_string_all(self): |
| 48 | with open(Path(test_root, "data", "json_file.json"), "r") as f: |
| 49 | box_from_string(f.read()) |
| 50 | |
| 51 | with open(Path(test_root, "data", "toml_file.tml"), "r") as f: |
| 52 | box_from_string(f.read(), string_type="toml") |
| 53 | |
| 54 | with open(Path(test_root, "data", "yaml_file.yaml"), "r") as f: |
| 55 | box_from_string(f.read(), string_type="yaml") |
nothing calls this directly
no outgoing calls
no test coverage detected