Skip to content

Commit a4ab444

Browse files
authored
Merge pull request loli#62 from cancan101/py3_tests
update tests to work on python3
2 parents 7e9e332 + 57a9c3f commit a4ab444

File tree

11 files changed

+48
-48
lines changed

11 files changed

+48
-48
lines changed

tests/features_/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from histogram import TestHistogramFeatures
2-
from intensity import TestIntensityFeatures
3-
from texture import TestTextureFeatures
1+
from .histogram import TestHistogramFeatures
2+
from .intensity import TestIntensityFeatures
3+
from .texture import TestTextureFeatures

tests/filter_/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
from houghtransform import TestHoughTransform
2-
from IntensityRangeStandardization import TestIntensityRangeStandardization
1+
from .houghtransform import TestHoughTransform
2+
from .IntensityRangeStandardization import TestIntensityRangeStandardization

tests/graphcut_/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#from cut import TestCut # deactivated since faulty
2-
from graph import TestGraph
3-
from energy_label import TestEnergyLabel
4-
from energy_voxel import TestEnergyVoxel
1+
#from cut import TestCut # deactivated since faulty
2+
from .graph import TestGraph
3+
from .energy_label import TestEnergyLabel
4+
from .energy_voxel import TestEnergyVoxel

tests/graphcut_/cut.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ def test_region_based(self):
129129
# build graph cut graph from graph
130130
gcgraph = GraphDouble(len(graph_new.get_nodes()), len(graph_new.get_nweights()))
131131
gcgraph.add_node(len(graph_new.get_nodes()))
132-
for node, weight in graph_new.get_tweights().iteritems():
132+
for node, weight in graph_new.get_tweights().items():
133133
gcgraph.add_tweights(int(node - 1), weight[0], weight[1])
134-
for edge, weight in graph_new.get_nweights().iteritems():
134+
for edge, weight in graph_new.get_nweights().items():
135135
gcgraph.add_edge(int(edge[0] - 1), int(edge[1] - 1), weight[0], weight[1])
136136

137137
# execute min-cut / executing BK_MFMC
@@ -153,7 +153,7 @@ def test_region_based(self):
153153
def __boundary_term(graph, label_image, boundary_term_args):
154154
"The boundary term function used for this tests."
155155
dic = TestCut.__get_mapping()
156-
for key, value in dic.iteritems():
156+
for key, value in dic.items():
157157
dic[key] = (value, value)
158158
return dic
159159

tests/graphcut_/energy_label.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def validate_nweights(self, unittest, expected_result, msg_base = ''):
167167
"""Compares the nweights hold by the graph with the once provided (as a dict)."""
168168
unittest.assertTrue(len(self.__nweights) == len(expected_result), '{}: Expected {} edges, but {} were added.'.format(msg_base, len(expected_result), len(self.__nweights)))
169169
node_id_set = set()
170-
for key in self.__nweights.iterkeys():
170+
for key in self.__nweights.keys():
171171
node_id_set.add(key[0])
172172
node_id_set.add(key[1])
173173
unittest.assertTrue(len(node_id_set) == self.__nodes), '{}: Not all {} node-ids appeared in the edges, but only {}. Missing are {}.'.format(msg_base, self.__nodes, len(node_id_set), set(range(0, self.__nodes)) - node_id_set)
@@ -176,15 +176,15 @@ def validate_nweights(self, unittest, expected_result, msg_base = ''):
176176
def __compare_dictionaries(self, unittest, result, expected_result, msg_base = ''):
177177
"""Evaluates the returned results."""
178178
unittest.assertEqual(len(expected_result), len(result), '{}: The expected result dict contains {} entries (for 4-connectedness), instead found {}.'.format(msg_base, len(expected_result), len(result)))
179-
for key, value in result.iteritems():
179+
for key, value in result.items():
180180
unittest.assertTrue(key in expected_result, '{}: Region border {} unexpectedly found in expected results.'.format(msg_base, key))
181181
if key in expected_result:
182182
unittest.assertAlmostEqual(value[0], expected_result[key][0], msg='{}: Weight for region border {} is {}. Expected {}.'.format(msg_base, key, value, expected_result[key]), delta=sys.float_info.epsilon)
183183
unittest.assertAlmostEqual(value[1], expected_result[key][1], msg='{}: Weight for region border {} is {}. Expected {}.'.format(msg_base, key, value, expected_result[key]), delta=sys.float_info.epsilon)
184184
unittest.assertGreater(value[0], 0.0, '{}: Encountered a weight {} <= 0.0 for key {}.'.format(msg_base, value, key))
185185
unittest.assertGreater(value[1], 0.0, '{}: Encountered a weight {} <= 0.0 for key {}.'.format(msg_base, value, key))
186186

187-
for key, value in expected_result.iteritems():
187+
for key, value in expected_result.items():
188188
unittest.assertTrue(key in result, '{}: Region border {} expectedly but not found in results.'.format(msg_base, key))
189189

190190

tests/graphcut_/energy_voxel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,4 @@ def __print_nweights(self, graph):
170170
for i in range(n):
171171
for j in range(i, n):
172172
if not i == j:
173-
print i, j, graph.get_edge(i, j)
173+
print(i, j, graph.get_edge(i, j))

tests/graphcut_/graph.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ def test_GCGraph(self):
3636

3737
# SETTER TESTS
3838
# set_source_nodes should accept a sequence and raise an error if an invalid node id was passed
39-
graph.set_source_nodes(range(0, nodes))
39+
graph.set_source_nodes(list(range(0, nodes)))
4040
self.assertRaises(ValueError, graph.set_source_nodes, [-1])
4141
self.assertRaises(ValueError, graph.set_source_nodes, [nodes])
4242
# set_sink_nodes should accept a sequence and raise an error if an invalid node id was passed
43-
graph.set_sink_nodes(range(0, nodes))
43+
graph.set_sink_nodes(list(range(0, nodes)))
4444
self.assertRaises(ValueError, graph.set_sink_nodes, [-1])
4545
self.assertRaises(ValueError, graph.set_sink_nodes, [nodes])
4646
# set_nweight should accept integers resp. floats and raise an error if an invalid node id was passed or the weight is zero or negative
@@ -79,7 +79,7 @@ def test_GCGraph(self):
7979
# SOME MINOR GETTERS
8080
self.assertEqual(graph.get_node_count(), nodes)
8181
self.assertEqual(graph.get_edge_count(), edges)
82-
self.assertSequenceEqual(graph.get_nodes(), range(0, nodes))
82+
self.assertSequenceEqual(graph.get_nodes(), list(range(0, nodes)))
8383

8484
if __name__ == '__main__':
8585
unittest.main()

tests/io_/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
from loadsave import TestIOFacilities
2-
from metadata import TestMetadataConsistency
1+
from .loadsave import TestIOFacilities
2+
from .metadata import TestMetadataConsistency

tests/io_/loadsave.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def test_SaveLoad(self):
174174
try:
175175
for ndim in __ndims:
176176
logger.debug('Testing for dimension {}...'.format(ndim))
177-
arr_base = scipy.random.randint(0, 10, range(10, ndim + 10))
177+
arr_base = scipy.random.randint(0, 10, list(range(10, ndim + 10)))
178178
for dtype in __dtypes:
179179
arr_save = arr_base.astype(dtype)
180180
for suffix in __suffixes:
@@ -212,29 +212,29 @@ def test_SaveLoad(self):
212212
raise
213213

214214
if supported:
215-
print '\nsave() and load() support (at least) the following image configurations:'
216-
print 'type\tndim\tdtypes'
215+
print('\nsave() and load() support (at least) the following image configurations:')
216+
print('type\tndim\tdtypes')
217217
for suffix in valid_types:
218-
for ndim, dtypes in valid_types[suffix].iteritems():
218+
for ndim, dtypes in valid_types[suffix].items():
219219
if list == type(dtypes) and not 0 == len(dtypes):
220-
print '{}\t{}D\t{}'.format(suffix, ndim, map(lambda x: str(x).split('.')[-1][:-2], dtypes))
220+
print('{}\t{}D\t{}'.format(suffix, ndim, [str(x).split('.')[-1][:-2] for x in dtypes]))
221221
if notsupported:
222-
print '\nthe following configurations are not supported:'
223-
print 'type\tndim\tdtype\t\terror'
222+
print('\nthe following configurations are not supported:')
223+
print('type\tndim\tdtype\t\terror')
224224
for suffix in unsupported_type:
225225
for ndim in unsupported_type[suffix]:
226-
for dtype, msg in unsupported_type[suffix][ndim].iteritems():
226+
for dtype, msg in unsupported_type[suffix][ndim].items():
227227
if msg:
228-
print '{}\t{}D\t{}\t\t{}'.format(suffix, ndim, str(dtype).split('.')[-1][:-2], msg)
228+
print('{}\t{}D\t{}\t\t{}'.format(suffix, ndim, str(dtype).split('.')[-1][:-2], msg))
229229

230230
if inconsistent:
231-
print '\nthe following configurations show inconsistent saving and loading behaviour:'
232-
print 'type\tndim\tdtype\t\terror'
231+
print('\nthe following configurations show inconsistent saving and loading behaviour:')
232+
print('type\tndim\tdtype\t\terror')
233233
for suffix in invalid_types:
234234
for ndim in invalid_types[suffix]:
235-
for dtype, msg in invalid_types[suffix][ndim].iteritems():
235+
for dtype, msg in invalid_types[suffix][ndim].items():
236236
if msg:
237-
print '{}\t{}D\t{}\t\t{}'.format(suffix, ndim, str(dtype).split('.')[-1][:-2], msg)
237+
print('{}\t{}D\t{}\t\t{}'.format(suffix, ndim, str(dtype).split('.')[-1][:-2], msg))
238238

239239
def __diff(self, arr1, arr2):
240240
"""

tests/io_/metadata.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def test_MetadataConsistency(self):
189189
try:
190190
for ndim in __ndims:
191191
logger.debug('Testing for dimension {}...'.format(ndim))
192-
arr_base = scipy.random.randint(0, 10, range(10, ndim + 10))
192+
arr_base = scipy.random.randint(0, 10, list(range(10, ndim + 10)))
193193
for dtype in __dtypes:
194194
arr_save = arr_base.astype(dtype)
195195
for suffix_from in __suffixes:
@@ -264,32 +264,32 @@ def test_MetadataConsistency(self):
264264
raise
265265

266266
if consistent:
267-
print '\nthe following format conversions are meta-data consistent:'
268-
print 'from\tto\tndim\tdtypes'
267+
print('\nthe following format conversions are meta-data consistent:')
268+
print('from\tto\tndim\tdtypes')
269269
for suffix_from in consistent_types:
270270
for suffix_to in consistent_types[suffix_from]:
271-
for ndim, dtypes in consistent_types[suffix_from][suffix_to].iteritems():
271+
for ndim, dtypes in consistent_types[suffix_from][suffix_to].items():
272272
if list == type(dtypes) and not 0 == len(dtypes):
273-
print '{}\t{}\t{}D\t{}'.format(suffix_from, suffix_to, ndim, map(lambda x: str(x).split('.')[-1][:-2], dtypes))
273+
print('{}\t{}\t{}D\t{}'.format(suffix_from, suffix_to, ndim, [str(x).split('.')[-1][:-2] for x in dtypes]))
274274
if inconsistent:
275-
print '\nthe following form conversions are not meta-data consistent:'
276-
print 'from\tto\tndim\tdtype\t\terror'
275+
print('\nthe following form conversions are not meta-data consistent:')
276+
print('from\tto\tndim\tdtype\t\terror')
277277
for suffix_from in inconsistent_types:
278278
for suffix_to in inconsistent_types[suffix_from]:
279279
for ndim in inconsistent_types[suffix_from][suffix_to]:
280-
for dtype, msg in inconsistent_types[suffix_from][suffix_to][ndim].iteritems():
280+
for dtype, msg in inconsistent_types[suffix_from][suffix_to][ndim].items():
281281
if msg:
282-
print '{}\t{}\t{}D\t{}\t\t{}'.format(suffix_from, suffix_to, ndim, str(dtype).split('.')[-1][:-2], msg)
282+
print('{}\t{}\t{}D\t{}\t\t{}'.format(suffix_from, suffix_to, ndim, str(dtype).split('.')[-1][:-2], msg))
283283

284284
if unsupported:
285-
print '\nthe following form conversions could not be tested due to errors:'
286-
print 'from\tto\tndim\tdtype\t\terror'
285+
print('\nthe following form conversions could not be tested due to errors:')
286+
print('from\tto\tndim\tdtype\t\terror')
287287
for suffix_from in unsupported_types:
288288
for suffix_to in unsupported_types[suffix_from]:
289289
for ndim in unsupported_types[suffix_from][suffix_to]:
290-
for dtype, msg in unsupported_types[suffix_from][suffix_to][ndim].iteritems():
290+
for dtype, msg in unsupported_types[suffix_from][suffix_to][ndim].items():
291291
if msg:
292-
print '{}\t{}\t{}D\t{}\t\t{}'.format(suffix_from, suffix_to, ndim, str(dtype).split('.')[-1][:-2], msg)
292+
print('{}\t{}\t{}D\t{}\t\t{}'.format(suffix_from, suffix_to, ndim, str(dtype).split('.')[-1][:-2], msg))
293293

294294
def __diff(self, hdr1, hdr2):
295295
"""

0 commit comments

Comments
 (0)