Skip to content

Commit 3ea676a

Browse files
committed
refactor test cases for file input handling in PointCloud
1 parent d1f3fbd commit 3ea676a

1 file changed

Lines changed: 11 additions & 32 deletions

File tree

tests/unit/test_file_io_pointcloud.py

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -67,54 +67,33 @@ def test_from_file_xyz(testxyz_diamond: Path):
6767
np.testing.assert_allclose(pointcloud.data.loc[0, ["x", "y", "z"]].to_numpy(), [0.5, 0.0, 0.5])
6868

6969

70-
def test_from_file_xyz_with_header(tmp_path: Path):
71-
testfile_name = tmp_path.joinpath("with_header.xyz")
72-
pd.DataFrame(
73-
{
74-
"x": [0.5, 0.0],
75-
"y": [0.0, 0.5],
76-
"z": [0.5, 0.5],
77-
"intensity": [1.0, 2.0],
78-
}
79-
).to_csv(testfile_name, index=False, sep=" ")
80-
81-
pointcloud = pointcloudset.PointCloud.from_file(testfile_name)
70+
def test_from_file_xyz_with_header(testxyz_with_header: Path):
71+
pointcloud = pointcloudset.PointCloud.from_file(testxyz_with_header)
8272
check.equal(type(pointcloud), PointCloud)
8373
check.equal(list(pointcloud.data.columns), ["x", "y", "z", "intensity"])
8474
np.testing.assert_allclose(pointcloud.data[["x", "y", "z"]].to_numpy(), [[0.5, 0.0, 0.5], [0.0, 0.5, 0.5]])
8575

8676

87-
def test_from_file_pcd(testpcd_tree: Path):
88-
pointcloud = pointcloudset.PointCloud.from_file(testpcd_tree)
77+
def test_from_file_csv_diamond(testcsv_diamond: Path):
78+
pointcloud = pointcloudset.PointCloud.from_file(testcsv_diamond)
8979
check.equal(type(pointcloud), PointCloud)
9080
check.greater(len(pointcloud), 0)
9181
check.is_true({"x", "y", "z"}.issubset(set(pointcloud.data.columns)))
9282

9383

94-
def test_from_file_csv_without_header(tmp_path: Path):
95-
testfile_name = tmp_path.joinpath("headerless.csv")
96-
testfile_name.write_text("0.5,0.0,0.5,1.0\n0.0,0.5,0.5,2.0\n")
97-
84+
def test_from_file_csv_without_header(testcsv_headerless: Path):
9885
with pytest.warns(UserWarning, match="Assuming first three columns are x, y, z"):
99-
pointcloud = pointcloudset.PointCloud.from_file(testfile_name)
86+
pointcloud = pointcloudset.PointCloud.from_file(testcsv_headerless)
10087

10188
check.equal(type(pointcloud), PointCloud)
10289
check.equal(list(pointcloud.data.columns), ["x", "y", "z", "field_3"])
103-
np.testing.assert_allclose(pointcloud.data[["x", "y", "z", "field_3"]].to_numpy(), [[0.5, 0.0, 0.5, 1.0], [0.0, 0.5, 0.5, 2.0]])
104-
90+
np.testing.assert_allclose(
91+
pointcloud.data[["x", "y", "z", "field_3"]].to_numpy(), [[0.5, 0.0, 0.5, 1.0], [0.0, 0.5, 0.5, 2.0]]
92+
)
10593

106-
def test_from_file_csv_with_header(tmp_path: Path):
107-
testfile_name = tmp_path.joinpath("with_header.csv")
108-
pd.DataFrame(
109-
{
110-
"x": [0.5, 0.0],
111-
"y": [0.0, 0.5],
112-
"z": [0.5, 0.5],
113-
"intensity": [1.0, 2.0],
114-
}
115-
).to_csv(testfile_name, index=False)
11694

117-
pointcloud = pointcloudset.PointCloud.from_file(testfile_name)
95+
def test_from_file_csv_with_header(testcsv_with_header: Path):
96+
pointcloud = pointcloudset.PointCloud.from_file(testcsv_with_header)
11897
check.equal(type(pointcloud), PointCloud)
11998
check.equal(list(pointcloud.data.columns), ["x", "y", "z", "intensity"])
12099
np.testing.assert_allclose(pointcloud.data[["x", "y", "z"]].to_numpy(), [[0.5, 0.0, 0.5], [0.0, 0.5, 0.5]])

0 commit comments

Comments
 (0)