Pytest tests (#17750)

* Convert core tests

* Convert component tests to use pytest assert

* Lint 🤷‍♂️

* Fix test

* Fix 3 typos in docs
This commit is contained in:
Paulus Schoutsen 2018-10-24 12:10:05 +02:00 committed by GitHub
parent 4222f7562b
commit 08fe7c3ece
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
223 changed files with 6747 additions and 7237 deletions

View file

@ -49,39 +49,35 @@ class TestCommandLine(unittest.TestCase):
filename = os.path.join(tempdirname, 'message.txt')
message = 'one, two, testing, testing'
with assert_setup_component(1) as handle_config:
self.assertTrue(setup_component(self.hass, notify.DOMAIN, {
assert setup_component(self.hass, notify.DOMAIN, {
'notify': {
'name': 'test',
'platform': 'command_line',
'command': 'echo $(cat) > {}'.format(filename)
}
}))
})
assert handle_config[notify.DOMAIN]
self.assertTrue(
self.hass.services.call('notify', 'test', {'message': message},
blocking=True)
)
assert self.hass.services.call(
'notify', 'test', {'message': message}, blocking=True)
with open(filename) as fil:
# the echo command adds a line break
self.assertEqual(fil.read(), "{}\n".format(message))
assert fil.read() == "{}\n".format(message)
@patch('homeassistant.components.notify.command_line._LOGGER.error')
def test_error_for_none_zero_exit_code(self, mock_error):
"""Test if an error is logged for non zero exit codes."""
with assert_setup_component(1) as handle_config:
self.assertTrue(setup_component(self.hass, notify.DOMAIN, {
assert setup_component(self.hass, notify.DOMAIN, {
'notify': {
'name': 'test',
'platform': 'command_line',
'command': 'echo $(cat); exit 1'
}
}))
})
assert handle_config[notify.DOMAIN]
self.assertTrue(
self.hass.services.call('notify', 'test', {'message': 'error'},
blocking=True)
)
self.assertEqual(1, mock_error.call_count)
assert self.hass.services.call('notify', 'test', {'message': 'error'},
blocking=True)
assert 1 == mock_error.call_count