Skip to content

Commit 4aefebe

Browse files
authored
Do not compare types (#2034)
* Do not compare types * Don't use type comparisons in unit tests, system tests
1 parent a5b4906 commit 4aefebe

File tree

8 files changed

+27
-27
lines changed

8 files changed

+27
-27
lines changed

build/unit_tests/test_metadata_add_all.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ def _compare_values(actual, expected, k):
1515

1616

1717
def _compare_lists(actual, expected):
18-
assert type(actual) == type(expected), 'Type mismatch, {0} != {1}'.format(type(actual), type(expected))
18+
assert isinstance(actual, type(expected)), 'Type mismatch, {0} != {1}'.format(type(actual), type(expected))
1919
assert len(actual) == len(expected), 'Length mismatch, {0} != {1}'.format(len(actual), len(expected))
2020
for k in range(len(actual)):
2121
_compare_values(actual[k], expected[k], k)
2222

2323

2424
def _compare_dicts(actual, expected):
25-
assert type(actual) == type(expected), 'Type mismatch, {0} != {1}'.format(type(actual), type(expected))
25+
assert isinstance(actual, type(expected)), 'Type mismatch, {0} != {1}'.format(type(actual), type(expected))
2626
for k in actual:
2727
assert k in expected, 'Key {0} not in expected'.format(k)
2828
_compare_values(actual[k], expected[k], k)

generated/nifake/nifake/unit_tests/test_grpc.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ def test_get_custom_type(self):
881881
cs = interpreter.get_custom_type()
882882
assert cs.struct_int == expected_cs.struct_int
883883
assert cs.struct_double == expected_cs.struct_double
884-
assert type(cs) == type(expected_cs)
884+
assert isinstance(cs, type(expected_cs))
885885
self._assert_call(library_func, response_object).assert_called_once_with(vi=GRPC_SESSION_OBJECT_FOR_TEST)
886886

887887
def test_set_custom_type_array(self):
@@ -906,7 +906,7 @@ def test_get_custom_type_array(self):
906906
for actual, expected in zip(cs_test, cs):
907907
assert actual.struct_int == expected.struct_int
908908
assert actual.struct_double == expected.struct_double
909-
assert type(actual) == type(expected)
909+
assert isinstance(actual, type(expected))
910910
self._assert_call(library_func, response_object).assert_called_once_with(
911911
vi=GRPC_SESSION_OBJECT_FOR_TEST, number_of_elements=len(cs)
912912
)
@@ -928,9 +928,9 @@ def test_get_custom_type_typedef(self):
928928
assert csnt_test.struct_custom_struct.struct_double == csnt.struct_custom_struct.struct_double
929929
assert csnt_test.struct_custom_struct_typedef.struct_int == csnt.struct_custom_struct_typedef.struct_int
930930
assert csnt_test.struct_custom_struct_typedef.struct_double == csnt.struct_custom_struct_typedef.struct_double
931-
assert type(csnt_test.struct_custom_struct) == type(csnt.struct_custom_struct) # noqa: E721
932-
assert type(csnt_test.struct_custom_struct_typedef) == type(csnt.struct_custom_struct_typedef) # noqa: E721
933-
assert type(csnt_test) == type(csnt)
931+
assert isinstance(csnt_test.struct_custom_struct, type(csnt.struct_custom_struct))
932+
assert isinstance(csnt_test.struct_custom_struct_typedef, type(csnt.struct_custom_struct_typedef))
933+
assert isinstance(csnt_test, type(csnt))
934934
request_object = self._assert_call(library_func, response_object)
935935
request_object.assert_called_once()
936936
call = request_object.call_args_list[0]
@@ -943,9 +943,9 @@ def test_get_custom_type_typedef(self):
943943
assert sent_csnt.struct_custom_struct.struct_double == grpc_csnt.struct_custom_struct.struct_double
944944
assert sent_csnt.struct_custom_struct_typedef.struct_int == grpc_csnt.struct_custom_struct_typedef.struct_int
945945
assert sent_csnt.struct_custom_struct_typedef.struct_double == grpc_csnt.struct_custom_struct_typedef.struct_double
946-
assert type(sent_csnt.struct_custom_struct) == type(grpc_csnt.struct_custom_struct) # noqa: E721
947-
assert type(sent_csnt.struct_custom_struct_typedef) == type(grpc_csnt.struct_custom_struct_typedef) # noqa: E721
948-
assert type(sent_csnt) == type(grpc_csnt)
946+
assert isinstance(sent_csnt.struct_custom_struct, type(grpc_csnt.struct_custom_struct))
947+
assert isinstance(sent_csnt.struct_custom_struct_typedef, type(grpc_csnt.struct_custom_struct_typedef))
948+
assert isinstance(sent_csnt, type(grpc_csnt))
949949

950950
def test_get_cal_date_time(self):
951951
library_func = 'GetCalDateAndTime'

generated/nifake/nifake/unit_tests/test_session.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def test_close(self):
7676

7777
def test_session_context_manager(self):
7878
with nifake.Session('dev1') as session:
79-
assert type(session) == nifake.Session
79+
assert isinstance(session, nifake.Session)
8080
self.patched_library_interpreter.init_with_options.assert_called_once_with('dev1', False, False, '')
8181
assert session._interpreter._vi == SESSION_NUM_FOR_TEST
8282
self.patched_library_interpreter.close.assert_called_once_with()
@@ -114,7 +114,7 @@ def test_session_context_manager_init_with_error(self):
114114
self.patched_library_interpreter.init_with_options.side_effect = nifake.errors.DriverError(test_error_code, test_error_desc)
115115
try:
116116
with nifake.Session('dev1') as session:
117-
assert type(session) == nifake.Session
117+
assert isinstance(session, nifake.Session)
118118
assert False
119119
except nifake.Error as e:
120120
assert e.code == test_error_code
@@ -126,7 +126,7 @@ def test_session_context_manager_close_with_error(self):
126126
self.patched_library_interpreter.close.side_effect = nifake.errors.DriverError(test_error_code, test_error_desc)
127127
try:
128128
with nifake.Session('dev1') as session:
129-
assert type(session) == nifake.Session
129+
assert isinstance(session, nifake.Session)
130130
assert False
131131
except nifake.Error as e:
132132
assert e.code == test_error_code

generated/nimodinst/nimodinst/unit_tests/test_modinst.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_close(self):
7474

7575
def test_context_manager(self):
7676
with nimodinst.Session('') as session:
77-
assert type(session) == nimodinst.Session
77+
assert isinstance(session, nimodinst.Session)
7878
self.patched_library.niModInst_OpenInstalledDevicesSession.assert_called_once_with(_matchers.ViStringMatcher(''), _matchers.ViSessionPointerMatcher(), _matchers.ViInt32PointerMatcher())
7979
self.patched_library.niModInst_CloseInstalledDevicesSession.assert_called_once_with(_matchers.ViSessionMatcher(SESSION_NUM_FOR_TEST))
8080

src/nifake/unit_tests/test_grpc.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ def test_get_custom_type(self):
881881
cs = interpreter.get_custom_type()
882882
assert cs.struct_int == expected_cs.struct_int
883883
assert cs.struct_double == expected_cs.struct_double
884-
assert type(cs) == type(expected_cs)
884+
assert isinstance(cs, type(expected_cs))
885885
self._assert_call(library_func, response_object).assert_called_once_with(vi=GRPC_SESSION_OBJECT_FOR_TEST)
886886

887887
def test_set_custom_type_array(self):
@@ -906,7 +906,7 @@ def test_get_custom_type_array(self):
906906
for actual, expected in zip(cs_test, cs):
907907
assert actual.struct_int == expected.struct_int
908908
assert actual.struct_double == expected.struct_double
909-
assert type(actual) == type(expected)
909+
assert isinstance(actual, type(expected))
910910
self._assert_call(library_func, response_object).assert_called_once_with(
911911
vi=GRPC_SESSION_OBJECT_FOR_TEST, number_of_elements=len(cs)
912912
)
@@ -928,9 +928,9 @@ def test_get_custom_type_typedef(self):
928928
assert csnt_test.struct_custom_struct.struct_double == csnt.struct_custom_struct.struct_double
929929
assert csnt_test.struct_custom_struct_typedef.struct_int == csnt.struct_custom_struct_typedef.struct_int
930930
assert csnt_test.struct_custom_struct_typedef.struct_double == csnt.struct_custom_struct_typedef.struct_double
931-
assert type(csnt_test.struct_custom_struct) == type(csnt.struct_custom_struct) # noqa: E721
932-
assert type(csnt_test.struct_custom_struct_typedef) == type(csnt.struct_custom_struct_typedef) # noqa: E721
933-
assert type(csnt_test) == type(csnt)
931+
assert isinstance(csnt_test.struct_custom_struct, type(csnt.struct_custom_struct))
932+
assert isinstance(csnt_test.struct_custom_struct_typedef, type(csnt.struct_custom_struct_typedef))
933+
assert isinstance(csnt_test, type(csnt))
934934
request_object = self._assert_call(library_func, response_object)
935935
request_object.assert_called_once()
936936
call = request_object.call_args_list[0]
@@ -943,9 +943,9 @@ def test_get_custom_type_typedef(self):
943943
assert sent_csnt.struct_custom_struct.struct_double == grpc_csnt.struct_custom_struct.struct_double
944944
assert sent_csnt.struct_custom_struct_typedef.struct_int == grpc_csnt.struct_custom_struct_typedef.struct_int
945945
assert sent_csnt.struct_custom_struct_typedef.struct_double == grpc_csnt.struct_custom_struct_typedef.struct_double
946-
assert type(sent_csnt.struct_custom_struct) == type(grpc_csnt.struct_custom_struct) # noqa: E721
947-
assert type(sent_csnt.struct_custom_struct_typedef) == type(grpc_csnt.struct_custom_struct_typedef) # noqa: E721
948-
assert type(sent_csnt) == type(grpc_csnt)
946+
assert isinstance(sent_csnt.struct_custom_struct, type(grpc_csnt.struct_custom_struct))
947+
assert isinstance(sent_csnt.struct_custom_struct_typedef, type(grpc_csnt.struct_custom_struct_typedef))
948+
assert isinstance(sent_csnt, type(grpc_csnt))
949949

950950
def test_get_cal_date_time(self):
951951
library_func = 'GetCalDateAndTime'

src/nifake/unit_tests/test_session.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def test_close(self):
7676

7777
def test_session_context_manager(self):
7878
with nifake.Session('dev1') as session:
79-
assert type(session) == nifake.Session
79+
assert isinstance(session, nifake.Session)
8080
self.patched_library_interpreter.init_with_options.assert_called_once_with('dev1', False, False, '')
8181
assert session._interpreter._vi == SESSION_NUM_FOR_TEST
8282
self.patched_library_interpreter.close.assert_called_once_with()
@@ -114,7 +114,7 @@ def test_session_context_manager_init_with_error(self):
114114
self.patched_library_interpreter.init_with_options.side_effect = nifake.errors.DriverError(test_error_code, test_error_desc)
115115
try:
116116
with nifake.Session('dev1') as session:
117-
assert type(session) == nifake.Session
117+
assert isinstance(session, nifake.Session)
118118
assert False
119119
except nifake.Error as e:
120120
assert e.code == test_error_code
@@ -126,7 +126,7 @@ def test_session_context_manager_close_with_error(self):
126126
self.patched_library_interpreter.close.side_effect = nifake.errors.DriverError(test_error_code, test_error_desc)
127127
try:
128128
with nifake.Session('dev1') as session:
129-
assert type(session) == nifake.Session
129+
assert isinstance(session, nifake.Session)
130130
assert False
131131
except nifake.Error as e:
132132
assert e.code == test_error_code

src/nimodinst/unit_tests/test_modinst.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_close(self):
7474

7575
def test_context_manager(self):
7676
with nimodinst.Session('') as session:
77-
assert type(session) == nimodinst.Session
77+
assert isinstance(session, nimodinst.Session)
7878
self.patched_library.niModInst_OpenInstalledDevicesSession.assert_called_once_with(_matchers.ViStringMatcher(''), _matchers.ViSessionPointerMatcher(), _matchers.ViInt32PointerMatcher())
7979
self.patched_library.niModInst_CloseInstalledDevicesSession.assert_called_once_with(_matchers.ViSessionMatcher(SESSION_NUM_FOR_TEST))
8080

src/nitclk/system_tests/test_system_nitclk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def multiple_niscope_sessions():
1818

1919

2020
def test_nitclk_integration(single_niscope_session):
21-
assert type(single_niscope_session.tclk) == nitclk.SessionReference
21+
assert isinstance(single_niscope_session.tclk, nitclk.SessionReference)
2222

2323

2424
def test_nitclk_vi_string(single_niscope_session):

0 commit comments

Comments
 (0)