Skip to content

Commit d2681cd

Browse files
committed
Moving the common lines in complex matchers into a function
1 parent f2fc824 commit d2681cd

File tree

3 files changed

+25
-43
lines changed

3 files changed

+25
-43
lines changed

build/templates/_matchers.py.mako

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,15 @@ class ViReal64PointerMatcher(_PointerMatcher):
283283

284284

285285
% if are_complex_parameters_used:
286+
def _compare_complex_number_arrays(expected, actual):
287+
for i in range(expected.expected_size):
288+
expected_value = expected.expected_data[i]
289+
actual_value = actual[i]
290+
if expected_value.real != actual_value.real or expected_value.imag != actual_value.imag:
291+
return False
292+
return True
293+
294+
286295
class NIComplexNumberPointerMatcher(_PointerMatcher):
287296
def __init__(self, expected_data, expected_size):
288297
_PointerMatcher.__init__(self, _complextype.NIComplexNumber)
@@ -291,13 +300,7 @@ class NIComplexNumberPointerMatcher(_PointerMatcher):
291300

292301
def __eq__(self, other):
293302
_PointerMatcher.__eq__(self, other)
294-
295-
for i in range(self.expected_size):
296-
expected_value = self.expected_data[i]
297-
actual_value = other[i]
298-
if expected_value.real != actual_value.real or expected_value.imag != actual_value.imag:
299-
return False
300-
return True
303+
return _compare_complex_number_arrays(self, other)
301304

302305
def __repr__(self):
303306
return f"NIComplexNumberPointerMatcher({self.expected_data})"
@@ -311,13 +314,7 @@ class NIComplexNumberF32PointerMatcher(_PointerMatcher):
311314

312315
def __eq__(self, other):
313316
_PointerMatcher.__eq__(self, other)
314-
315-
for i in range(self.expected_size):
316-
expected_value = self.expected_data[i]
317-
actual_value = other[i]
318-
if expected_value.real != actual_value.real or expected_value.imag != actual_value.imag:
319-
return False
320-
return True
317+
return _compare_complex_number_arrays(self, other)
321318

322319
def __repr__(self):
323320
return f"NIComplexNumberF32PointerMatcher({self.expected_data})"
@@ -331,13 +328,7 @@ class NIComplexI16PointerMatcher(_PointerMatcher):
331328

332329
def __eq__(self, other):
333330
_PointerMatcher.__eq__(self, other)
334-
335-
for i in range(self.expected_size):
336-
expected_value = self.expected_data[i]
337-
actual_value = other[i]
338-
if expected_value.real != actual_value.real or expected_value.imag != actual_value.imag:
339-
return False
340-
return True
331+
return _compare_complex_number_arrays(self, other)
341332

342333
def __repr__(self):
343334
return f"NIComplexI16PointerMatcher({self.expected_data})"

build/unit_tests/test_codegen_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ def test_get_ctype_variable_declaration_snippet_case_s220():
12171217

12181218
def test_get_ctype_variable_declaration_snippet_case_b510():
12191219
snippet = get_ctype_variable_declaration_snippet(parameters_for_testing[7], parameters_for_testing, IviDanceStep.NOT_APPLICABLE, config_for_testing, use_numpy_array=True)
1220-
assert snippet == ["output_ctype = _get_ctypes_pointer_for_buffer(value=output, library_type=numpy.ViInt64) # case B510"]
1220+
assert snippet == ["output_ctype = _get_ctypes_pointer_for_buffer(value=output) # case B510"]
12211221

12221222

12231223
def test_get_ctype_variable_declaration_snippet_case_b540():

generated/nifake/nifake/unit_tests/_matchers.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,15 @@ def __init__(self):
272272
_PointerMatcher.__init__(self, _visatype.ViReal64)
273273

274274

275+
def _compare_complex_number_arrays(expected, actual):
276+
for i in range(expected.expected_size):
277+
expected_value = expected.expected_data[i]
278+
actual_value = actual[i]
279+
if expected_value.real != actual_value.real or expected_value.imag != actual_value.imag:
280+
return False
281+
return True
282+
283+
275284
class NIComplexNumberPointerMatcher(_PointerMatcher):
276285
def __init__(self, expected_data, expected_size):
277286
_PointerMatcher.__init__(self, _complextype.NIComplexNumber)
@@ -280,13 +289,7 @@ def __init__(self, expected_data, expected_size):
280289

281290
def __eq__(self, other):
282291
_PointerMatcher.__eq__(self, other)
283-
284-
for i in range(self.expected_size):
285-
expected_value = self.expected_data[i]
286-
actual_value = other[i]
287-
if expected_value.real != actual_value.real or expected_value.imag != actual_value.imag:
288-
return False
289-
return True
292+
return _compare_complex_number_arrays(self, other)
290293

291294
def __repr__(self):
292295
return f"NIComplexNumberPointerMatcher({self.expected_data})"
@@ -300,13 +303,7 @@ def __init__(self, expected_data, expected_size):
300303

301304
def __eq__(self, other):
302305
_PointerMatcher.__eq__(self, other)
303-
304-
for i in range(self.expected_size):
305-
expected_value = self.expected_data[i]
306-
actual_value = other[i]
307-
if expected_value.real != actual_value.real or expected_value.imag != actual_value.imag:
308-
return False
309-
return True
306+
return _compare_complex_number_arrays(self, other)
310307

311308
def __repr__(self):
312309
return f"NIComplexNumberF32PointerMatcher({self.expected_data})"
@@ -320,13 +317,7 @@ def __init__(self, expected_data, expected_size):
320317

321318
def __eq__(self, other):
322319
_PointerMatcher.__eq__(self, other)
323-
324-
for i in range(self.expected_size):
325-
expected_value = self.expected_data[i]
326-
actual_value = other[i]
327-
if expected_value.real != actual_value.real or expected_value.imag != actual_value.imag:
328-
return False
329-
return True
320+
return _compare_complex_number_arrays(self, other)
330321

331322
def __repr__(self):
332323
return f"NIComplexI16PointerMatcher({self.expected_data})"

0 commit comments

Comments
 (0)