Skip to content

Commit d72d55d

Browse files
author
Dwight Hubbard
committed
Fix tests to not fail if run from the parent directory
Add missing PyPNG dependency
1 parent c9cd524 commit d72d55d

File tree

6 files changed

+39
-21
lines changed

6 files changed

+39
-21
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"Topic :: Scientific/Engineering :: Mathematics",
2222
],
2323
packages=find_packages(),
24-
install_requires=['euclid', 'png'],
24+
install_requires=['euclid', 'PyPNG'],
2525
)
2626

2727

solid/solidpython.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,18 @@ def disable( openscad_obj):
125125
# --include() makes those methods available AND executes all code in
126126
# scad_file_path.scad, which may have side effects.
127127
# Unless you have a specific need, call use().
128-
def use( scad_file_path, use_not_include=True):
128+
def use(scad_file_path, use_not_include=True):
129129
'''
130130
TODO: doctest needed
131131
'''
132132
# Opens scad_file_path, parses it for all usable calls,
133133
# and adds them to caller's namespace
134134
try:
135-
module = open( scad_file_path)
135+
module = open(scad_file_path)
136136
contents = module.read()
137137
module.close()
138138
except Exception, e:
139-
raise Exception( "Failed to import SCAD module '%(scad_file_path)s' with error: %(e)s "%vars())
139+
raise Exception("Failed to import SCAD module '%(scad_file_path)s' with error: %(e)s "%vars())
140140

141141
# Once we have a list of all callables and arguments, dynamically
142142
# add openscad_object subclasses for all callables to the calling module's

solid/test/ExpandedTestCase.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ def assertEqual(self, first, second, msg=None):
1010
"""
1111
Override assertEqual and print a context diff if msg=None
1212
"""
13-
if not msg:
14-
msg = 'Strings are not equal:\n' + ''.join(
15-
difflib.unified_diff(first, second, fromfile='actual', tofile='expected')
16-
)
13+
if isinstance(first, basestring) and isinstance(second, basestring):
14+
if not msg:
15+
msg = 'Strings are not equal:\n' + ''.join(
16+
difflib.unified_diff(
17+
first,
18+
second,
19+
fromfile='actual',
20+
tofile='expected'
21+
)
22+
)
1723
return super(DiffOutput, self).assertEqual(first, second, msg=msg)

solid/test/test_screw_thread.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
# Assumes SolidPython is in site-packages or elsewhwere in sys.path
99
import unittest
10-
import ExpandedTestCase
10+
from solid.test.ExpandedTestCase import DiffOutput
1111
from solid import *
1212
from solid.screw_thread import thread, default_thread_section
1313

1414
SEGMENTS = 8
15-
class TestScrewThread(ExpandedTestCase.DiffOutput):
16-
def test_thread( self):
15+
class TestScrewThread(DiffOutput):
16+
def test_thread(self):
1717
tooth_height = 10
1818
tooth_depth = 5
1919
outline = default_thread_section( tooth_height=tooth_height, tooth_depth=tooth_depth)
@@ -36,7 +36,7 @@ def test_thread_internal( self):
3636
expected = '\n\nrender() {\n\tintersection() {\n\t\tpolyhedron(points = [[25.0100000000, 0.0000000000, -5.0000000000], [20.0100000000, 0.0000000000, 0.0000000000], [25.0100000000, 0.0000000000, 5.0000000000], [14.1421356237, 14.1421356237, -2.5000000000], [10.6066017178, 10.6066017178, 2.5000000000], [14.1421356237, 14.1421356237, 7.5000000000], [0.0000000000, 20.0000000000, 0.0000000000], [0.0000000000, 15.0000000000, 5.0000000000], [0.0000000000, 20.0000000000, 10.0000000000], [-14.1421356237, 14.1421356237, 2.5000000000], [-10.6066017178, 10.6066017178, 7.5000000000], [-14.1421356237, 14.1421356237, 12.5000000000], [-20.0000000000, 0.0000000000, 5.0000000000], [-15.0000000000, 0.0000000000, 10.0000000000], [-20.0000000000, 0.0000000000, 15.0000000000], [-14.1421356237, -14.1421356237, 7.5000000000], [-10.6066017178, -10.6066017178, 12.5000000000], [-14.1421356237, -14.1421356237, 17.5000000000], [-0.0000000000, -20.0000000000, 10.0000000000], [-0.0000000000, -15.0000000000, 15.0000000000], [-0.0000000000, -20.0000000000, 20.0000000000], [14.1421356237, -14.1421356237, 12.5000000000], [10.6066017178, -10.6066017178, 17.5000000000], [14.1421356237, -14.1421356237, 22.5000000000], [25.0100000000, -0.0000000000, 15.0000000000], [20.0100000000, -0.0000000000, 20.0000000000], [25.0100000000, -0.0000000000, 25.0000000000]], triangles = [[0, 1, 3], [1, 4, 3], [1, 2, 4], [2, 5, 4], [0, 5, 2], [0, 3, 5], [3, 4, 6], [4, 7, 6], [4, 5, 7], [5, 8, 7], [3, 8, 5], [3, 6, 8], [6, 7, 9], [7, 10, 9], [7, 8, 10], [8, 11, 10], [6, 11, 8], [6, 9, 11], [9, 10, 12], [10, 13, 12], [10, 11, 13], [11, 14, 13], [9, 14, 11], [9, 12, 14], [12, 13, 15], [13, 16, 15], [13, 14, 16], [14, 17, 16], [12, 17, 14], [12, 15, 17], [15, 16, 18], [16, 19, 18], [16, 17, 19], [17, 20, 19], [15, 20, 17], [15, 18, 20], [18, 19, 21], [19, 22, 21], [19, 20, 22], [20, 23, 22], [18, 23, 20], [18, 21, 23], [21, 22, 24], [22, 25, 24], [22, 23, 25], [23, 26, 25], [21, 26, 23], [21, 24, 26], [0, 2, 1], [24, 25, 26]]);\n\t\tcylinder($fn = 8, h = 20, r = 20);\n\t}\n}'
3737
self.assertEqual( expected, actual)
3838

39-
def test_default_thread_section( self):
39+
def test_default_thread_section(self):
4040
expected = [[0, -5], [5, 0], [0, 5]]
4141
actual = default_thread_section( tooth_height=10, tooth_depth=5)
4242
self.assertEqual( expected, actual)

solid/test/test_solidpython.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import unittest
66
import tempfile
7-
import ExpandedTestCase
7+
from solid.test.ExpandedTestCase import DiffOutput
88
from solid import *
99

1010
scad_test_case_templates = [
@@ -36,8 +36,16 @@
3636
{'name': 'intersection_for', 'kwargs': {}, 'expected': '\n\nintersection_for(n = [0, 1, 2]);', 'args': {'n': [0, 1, 2]}, },
3737
]
3838

39-
class TestSolidPython(ExpandedTestCase.DiffOutput):
39+
class TestSolidPython(DiffOutput):
4040
# test cases will be dynamically added to this instance
41+
scad_path = ['solid', '..', '.']
42+
def expand_scad_path(self, filename):
43+
for path in self.scad_path:
44+
full_path = os.path.join(path, filename)
45+
if os.path.exists(full_path):
46+
return full_path
47+
return None
48+
4149
def test_infix_union( self):
4250
a = cube(2)
4351
b = sphere( 2)
@@ -77,7 +85,7 @@ def test_parse_scad_callables( self):
7785
self.assertEqual( expected, actual)
7886

7987
def test_use( self):
80-
include_file = "../examples/scad_to_include.scad"
88+
include_file = self.expand_scad_path("examples/scad_to_include.scad")
8189
use( include_file)
8290
a = steps(3)
8391
actual = scad_render( a)
@@ -87,8 +95,12 @@ def test_use( self):
8795
self.assertEqual( expected, actual)
8896

8997
def test_include( self):
90-
include_file = "../examples/scad_to_include.scad"
91-
include( include_file)
98+
include_file = self.expand_scad_path("examples/scad_to_include.scad")
99+
self.assertIsNotNone(
100+
include_file,
101+
'examples/scad_to_include.scad not found'
102+
)
103+
include(include_file)
92104
a = steps(3)
93105

94106
actual = scad_render( a)
@@ -97,8 +109,8 @@ def test_include( self):
97109
self.assertEqual( expected, actual)
98110

99111
def test_extra_args_to_included_scad( self):
100-
include_file = "../examples/scad_to_include.scad"
101-
use( include_file)
112+
include_file = self.expand_scad_path("examples/scad_to_include.scad")
113+
use(include_file)
102114
a = steps( 3, external_var=True)
103115
actual = scad_render( a)
104116

solid/test/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from solid.utils import *
99
from euclid import *
1010
import difflib
11-
import ExpandedTestCase
11+
from solid.test.ExpandedTestCase import DiffOutput
1212

1313

1414
tri = [Point3( 0,0,0), Point3( 10,0,0), Point3(0,10,0)]
@@ -52,7 +52,7 @@
5252
]
5353

5454

55-
class TestSPUtils(ExpandedTestCase.DiffOutput):
55+
class TestSPUtils(DiffOutput):
5656
# Test cases will be dynamically added to this instance
5757
# using the test case arrays above
5858

0 commit comments

Comments
 (0)