Skip to content

Commit b9c0c2d

Browse files
committed
increased test coverage to 96%
1 parent 2bee648 commit b9c0c2d

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

stl_tools/numpy2stl.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def numpy2stl(A, fn, scale=0.1, mask_val=-np.inf, ascii=False,
8989
A = scale * (A - A.min())
9090

9191
facets = []
92-
for i, k in product(xrange(m - 1), xrange(n - 1)):
92+
for i, k in product(range(m - 1), range(n - 1)):
9393

9494
this_pt = np.array([i - m / 2., k - n / 2., A[i, k]])
9595
top_right = np.array([i - m / 2., k + 1 - n / 2., A[i, k + 1]])
@@ -132,8 +132,3 @@ def numpy2stl(A, fn, scale=0.1, mask_val=-np.inf, ascii=False,
132132
facets = facets * float(max_height) / zsize
133133

134134
writeSTL(facets, fn, ascii=ascii)
135-
136-
if __name__ == "__main__":
137-
from scipy.misc import lena
138-
A = lena()
139-
numpy2stl(A, "lena.stl")

stl_tools/test/test_stl.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
import numpy as np
66
from scipy.misc import imresize
7-
from stl_tools import text2array, numpy2stl
7+
from stl_tools import text2array, numpy2stl, text2png
88
from qimshow import qimshow
99

1010
"""
@@ -16,7 +16,16 @@
1616

1717
class TestSTL(unittest.TestCase):
1818

19-
def test_text(self):
19+
def test_text2png(self):
20+
""" Tests creation of an image array from a text expression.
21+
Covers the text2png and text2array functions.
22+
"""
23+
24+
text2png("TEST", fontsize=1000)
25+
assert os.path.exists("TEST.png")
26+
os.remove("TEST.png")
27+
28+
def test_text2array(self):
2029
""" Tests creation of an image array from a text expression.
2130
Covers the text2png and text2array functions.
2231
"""
@@ -36,11 +45,18 @@ def test_png(self):
3645
assert os.stat(output_name).st_size > 1500000
3746

3847
# test binary output
39-
A = imresize([[0, 1], [1, 0]], (64, 64))
4048
numpy2stl(A, output_name, scale=0.05, mask_val=3., ascii=False)
4149
assert os.path.exists(output_name)
4250
assert os.stat(output_name).st_size > 200000
4351
os.remove(output_name)
4452

53+
def test_calc_normals(self):
54+
output_name = "OUT_.stl"
55+
A = imresize([[0, 1], [1, 0]], (64, 64))
56+
numpy2stl(A, output_name, scale=0.05, mask_val=3., calc_normals=True)
57+
assert os.path.exists(output_name)
58+
assert os.stat(output_name).st_size > 200000
59+
os.remove(output_name)
60+
4561
if __name__ == '__main__':
4662
unittest.main()

stl_tools/text2png.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ def text2array(text, fontsize=100):
4242
"""
4343

4444
text2png(text, fn="_text", fontsize=fontsize)
45-
A = pylab.imread("_text.png")[:,:,:3].mean(axis=2)
45+
A = pylab.imread("_text.png")[:, :, :3].mean(axis=2)
4646
os.remove("_text.png")
4747
return A.max() - A
48-
49-
if __name__ == "__main__":
50-
# LaTeX for Navier-Stokes equation
51-
text = ("$\\frac{\partial \\rho}{\partial t} + \\frac{\partial}{\partial "
52-
"x_j}\left[ \\rho u_j \\right] = 0$")
53-
text2png(text, "NavierStokes")

0 commit comments

Comments
 (0)