Here are the examples of the python api unittest.mock.PropertyMock taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
11 Examples
4
Example 1
Project: floto Source File: test_domains.py
def test_register_domain_args(self, domains, mocker):
mocker.patch('floto.api.Swf.client', new_callable=unittest.mock.PropertyMock,
return_value=Client_Mock())
Client_Mock.register_domain = unittest.mock.Mock()
domains._register_domain(name='domain_name', description='description',
retention_period='NONE')
expected_args = {'name':'domain_name',
'description':'description',
'workflowExecutionRetentionPeriodInDays':'NONE'}
domains.swf.client.register_domain.assert_called_once_with(**expected_args)
3
Example 2
Project: floto Source File: test_domains.py
def test_register_domain_error(self, domains, mocker):
error_response = {'Error':{'Code':'MyFault'}}
client_error = botocore.exceptions.ClientError(error_response=error_response,
operation_name="op_name")
mocker.patch('floto.api.Swf.client', new_callable=unittest.mock.PropertyMock,
return_value=Client_Mock())
Client_Mock.register_domain = unittest.mock.Mock(side_effect=client_error)
with pytest.raises(botocore.exceptions.ClientError):
domains._register_domain(name='domain_name', description='description', retention_period='NONE')
3
Example 3
Project: tai5-uan5_gian5-gi2_phing5-tai5 Source File: test指令顯示全部sheet狀態試驗.py
@patch('gspread.authorize')
def test_sheet內底無工作表(self, authorizeMocka):
規个sheet資料 = authorizeMocka.return_value.open_by_url.return_value
type(規个sheet資料).sheet1 = PropertyMock(return_value=None)
with io.StringIO() as 輸出:
call_command('顯示全部sheet狀態', stdout=輸出)
self.assertIn('sheet內底無工作表', 輸出.getvalue())
3
Example 4
Project: brython Source File: testhelpers.py
def test_propertymock_returnvalue(self):
m = MagicMock()
p = PropertyMock()
type(m).foo = p
returned = m.foo
p.assert_called_once_with()
self.assertIsInstance(returned, MagicMock)
self.assertNotIsInstance(returned, PropertyMock)
3
Example 5
Project: feedhq Source File: test_fetching.py
@patch("requests.get")
def test_socket_timeout(self, get):
m = get.return_value
type(m).content = PropertyMock(side_effect=socket.timeout)
FeedFactory.create()
f = UniqueFeed.objects.get()
self.assertFalse(f.muted)
data = job_details(f.url, connection=get_redis_connection())
self.assertEqual(data['error'], f.TIMEOUT)
0
Example 6
Project: DockCI Source File: test_job_model.py
@pytest.mark.parametrize(
'model_state,in_service,in_state,in_msg,exp_state,exp_msg', [
(
None, 'github', 'running', None, 'pending',
'The DockCI job is in progress',
),
(
None, 'github', 'broken', None, 'error',
'The DockCI job failed to complete due to an error',
),
(
'running', 'github', None, None, 'pending',
'The DockCI job is in progress',
),
(
None, 'github', 'running', 'is testing things', 'pending',
'The DockCI job is testing things',
),
(
'running', 'github', None, 'is testing things', 'pending',
'The DockCI job is testing things',
),
(
None, 'gitlab', 'fail', None, 'failed',
'The DockCI job completed with failing tests',
),
(
'fail', 'gitlab', None, None, 'failed',
'The DockCI job completed with failing tests',
),
])
def test_basic_sets(self,
mocker,
model_state,
in_service,
in_state,
in_msg,
exp_state,
exp_msg,
):
""" Test some basic input/output combinations """
job = Job()
mocker.patch('dockci.models.job.Job.state', new_callable=PropertyMock(return_value=model_state))
out_state, out_msg = job.state_data_for(in_service, in_state, in_msg)
assert out_state == exp_state
assert out_msg == exp_msg
0
Example 7
Project: sakia Source File: test_main_window.py
def setUp(self):
self.setUpQuamash()
QLocale.setDefault(QLocale("en_GB"))
self.identity = Mock(spec='sakia.core.registry.Identity')
self.identity.pubkey = "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk"
self.identity.uid = "A"
self.app = MagicMock(autospec='sakia.core.Application')
self.account_joe = Mock(spec='sakia.core.Account')
self.account_joe.contacts_changed = Mock()
self.account_joe.contacts_changed.disconnect = Mock()
self.account_joe.contacts_changed.connect = Mock()
self.account_doe = Mock(spec='sakia.core.Account')
self.account_doe.contacts_changed = Mock()
self.account_doe.contacts_changed.disconnect = Mock()
self.account_doe.contacts_changed.connect = Mock()
def change_current_account(account_name):
type(self.app).current_account = PropertyMock(return_value=self.account_doe)
self.app.get_account = Mock(side_effect=lambda name: self.app.accounts[name])
self.app.change_current_account = Mock(side_effect=change_current_account)
type(self.app).current_account = PropertyMock(return_value=self.account_joe)
self.app.accounts = {'joe':self.account_joe,
'doe': self.account_doe}
self.homescreen = MagicMock(autospec='sakia.gui.homescreen.Homescreen')
self.community_view = MagicMock(autospec='sakia.gui.community_view.CommunityView')
self.password_asker = MagicMock(autospec='sakia.gui.password_asker.PasswordAsker')
self.node_manager = MagicMock(autospec='sakia.gui.node_manager.NodeManager')
0
Example 8
Project: sakia Source File: test_main_window.py
def test_change_account_from_none(self):
widget = Mock(spec='PyQt5.QtWidgets.QMainWindow', create=True)
widget.installEventFilter = Mock()
ui = Mock(spec='sakia.gen_resources.mainwindow_uic.Ui_MainWindow', create=True)
ui.setupUi = Mock()
label_icon = Mock()
label_status = Mock()
label_time = Mock()
combo_referentials = Mock()
combo_referentials.currentIndexChanged = {int: Mock()}
type(self.app).current_account = PropertyMock(return_value=None)
mainwindow = MainWindow(self.app, None, self.homescreen, self.community_view, self.node_manager,
widget, ui, label_icon,
label_status, label_time, combo_referentials, self.password_asker)
mainwindow.refresh = Mock()
mainwindow.action_change_account("doe")
self.app.change_current_account.assert_called_once_with(self.account_doe)
mainwindow.change_account()
self.community_view.change_account.assert_called_once_with(self.account_doe, self.password_asker)
self.password_asker.change_account.assert_called_once_with(self.account_doe)
self.account_joe.contacts_changed.disconnect.assert_not_called()
self.account_doe.contacts_changed.connect.assert_called_once_with(mainwindow.refresh_contacts)
mainwindow.refresh.assert_called_once_with()
0
Example 9
Project: home-assistant Source File: test_mfi.py
def test_uom_uninitialized(self):
"""Test that the UOM defaults if not initialized."""
type(self.port).tag = mock.PropertyMock(side_effect=ValueError)
self.assertEqual('State', self.sensor.unit_of_measurement)
0
Example 10
Project: home-assistant Source File: test_mfi.py
def test_state_uninitialized(self):
"""Test the state of uninitialized sensors."""
type(self.port).tag = mock.PropertyMock(side_effect=ValueError)
self.assertEqual(mfi.STATE_OFF, self.sensor.state)
0
Example 11
Project: home-assistant Source File: test_main.py
@patch('sys.exit')
def test_validate_python(mock_exit):
"""Test validate Python version method."""
with patch('sys.version_info',
new_callable=PropertyMock(return_value=(2, 7, 8))):
main.validate_python()
assert mock_exit.called is True
mock_exit.reset_mock()
with patch('sys.version_info',
new_callable=PropertyMock(return_value=(3, 2, 0))):
main.validate_python()
assert mock_exit.called is True
mock_exit.reset_mock()
with patch('sys.version_info',
new_callable=PropertyMock(return_value=(3, 4, 1))):
main.validate_python()
assert mock_exit.called is True
mock_exit.reset_mock()
with patch('sys.version_info',
new_callable=PropertyMock(return_value=(3, 4, 2))):
main.validate_python()
assert mock_exit.called is False
mock_exit.reset_mock()
with patch('sys.version_info',
new_callable=PropertyMock(return_value=(3, 5, 1))):
main.validate_python()
assert mock_exit.called is False