Added unit test for to_stl method
@@ -13,9 +13,7 @@ class ExportTest():
self.path = os.path.dirname(os.path.abspath(sys.argv[0]))
def test_export_to_palabos(self):
- X = 20
- Y = 20
- Z = 20
+ X = Y = Z = 20
S = X * Y * Z
im = ps.generators.blobs(shape=[X, Y, Z], porosity=0.7, blobiness=1)
tmp = os.path.join(self.path, 'palabos.dat')
@@ -45,23 +43,22 @@ class ExportTest():
def test_to_vtk_2d(self):
im = ps.generators.blobs(shape=[20, 20])
- ps.io.to_vtk(im, path='vtk_func_test')
+ ps.io.to_vtk(im, filename='vtk_func_test')
assert os.stat('vtk_func_test.vti').st_size == 831
os.remove('vtk_func_test.vti')
def test_to_vtk_3d(self):
im = ps.generators.blobs(shape=[20, 20, 20])
- ps.io.to_vtk(im, path='vtk_func_test')
+ ps.io.to_vtk(im, filename='vtk_func_test')
assert os.stat('vtk_func_test.vti').st_size == 8433
os.remove('vtk_func_test.vti')
def test_dict_to_vtk(self):
im = ps.generators.blobs(shape=[20, 20, 20])
- ps.io.dict_to_vtk({'im': im})
+ ps.io.dict_to_vtk({'im': im}, filename="dictvtk")
a = os.stat('dictvtk.vti').st_size
os.remove('dictvtk.vti')
- ps.io.dict_to_vtk({'im': im,
- 'im_neg': ~im})
+ ps.io.dict_to_vtk({'im': im, 'im_neg': ~im}, filename="dictvtk")
b = os.stat('dictvtk.vti').st_size
assert a < b
os.remove('dictvtk.vti')
@@ -84,15 +81,19 @@ class ExportTest():
volume_total = np.prod(net.spacing * net.shape)
porosity_desired = volume_void / volume_total
- assert_allclose(actual=porosity_actual, desired=porosity_desired,
- rtol=0.05)
+ assert_allclose(actual=porosity_actual, desired=porosity_desired, rtol=0.05)
+ def test_to_stl(self):
+ im = ps.generators.blobs(shape=[50, 50, 50], spacing=0.1)
+ ps.io.to_stl(im, filename="im2stl")
+ os.remove("im2stl.stl")
-if __name__ == '__main__':
+
+if __name__ == "__main__":
t = ExportTest()
self = t
t.setup_class()
for item in t.__dir__():
- if item.startswith('test'):
- print('running test: '+item)
+ if item.startswith("test"):
+ print(f"Running test: {item}")
t.__getattribute__(item)()
