Skip to content

Conversation

injaleea
Copy link
Contributor

@injaleea injaleea commented Sep 8, 2017

[X] This contribution adheres to CONTRIBUTING.md.

What does this Pull Request accomplish?

Added fake method for read_write_integer attribute
Added unit test for set get integer attribute
unit test for close with error

Why should this Pull Request be merged?

More unit test coverage for fake

What testing has been done?

Passed on dev machine


def test_get_vi_int32_attribute(self):
self.patched_library.niFake_GetAttributeViInt32.side_effect = self.side_effects_helper.niFake_GetAttributeViInt32
int = 3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like naming variables the same as the type. Can you call this something different?

assert(attr_int == int)
from mock import call
calls = [call(SESSION_NUM_FOR_TEST, b"", 1000004, ANY)]
self.patched_library.niFake_GetAttributeViInt32.assert_has_calls(calls)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this test use mock.call to check the call, while the next test uses assert_called_once_with()?

session1 = nifake.Session('dev1')
session.close()
session1.close()
assert True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

self.patched_library.niFake_GetError.side_effect = self.side_effects_helper.niFake_GetError
self.side_effects_helper['GetError']['errorCode'] = test_error_code
self.side_effects_helper['GetError']['description'] = test_error_desc
session = nifake.Session('dev1')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need two sessions in this test?

session.read_write_integer = int
self.patched_library.niFake_SetAttributeViInt32.assert_called_once_with(SESSION_NUM_FOR_TEST, b'', attribute_id, 1)

def test_error_on_close(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the things close() should do, is log on failure (cannot / we decided not to raise).

This should have been fixed #198 but we missed it.

test_number = 1
with nifake.Session('dev1') as session:
session.read_write_integer = test_number
self.patched_library.niFake_SetAttributeViInt32.assert_called_once_with(SESSION_NUM_FOR_TEST, b'', attribute_id, 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come you didn't use test_number here?

test_error_desc = 'Test'
self.patched_library.niFake_close.side_effect = self.side_effects_helper.niFake_close
self.side_effects_helper['close']['return'] = test_error_code
self.side_effects_helper['close']['vi'] = SESSION_NUM_FOR_TEST
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this supposed to accomplish? niFake_Close() takes the ViSession as an input. You should be checking that with assert_called_once_with...

self.side_effects_helper['GetError']['errorCode'] = test_error_code
self.side_effects_helper['GetError']['description'] = test_error_desc
session = nifake.Session('dev1')
session.close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When close() errors, we don't raise an exception. But we do or at least should log a warning (don't remember if that's implemented yet). Can you check that in the test as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#254 is what I was referring to.

assert self.patched_errors.handle_error.call_count == 2
self.patched_errors.handle_error.assert_called_with(session, self.patched_library.niFake_GetCalDateAndTime.return_value)
'''

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When there are changes to a test file, either system tests or unit tests, there should be a corresponding change in the generated files.

When you don't have the changed generated file as part of your change, it ends up being an unrelated change in a different pull request.

@marcoskirsch marcoskirsch merged commit 104fd8d into master Sep 17, 2017
@marcoskirsch marcoskirsch deleted the injaleea-dev-2 branch September 17, 2017 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants