diff options
author | Emma Foley <emma.l.foley@intel.com> | 2018-03-12 15:07:59 +0000 |
---|---|---|
committer | Emma Foley <emma.l.foley@intel.com> | 2018-06-13 18:37:41 +0000 |
commit | 55d59992c6695e2ba4093b1d76905f3263dfba3e (patch) | |
tree | e9aa2e5f71fb9fe99e02d7c6066997efc044ad0d | |
parent | a3399d07b83ce0e50d9c0144d00a7ba83a73390f (diff) |
assert[Greater,Equal] -> assert_{,not_}called
assertEqual(mock_xxx.call_count, 1) -> mock_xxx.assert_called_once
assertEqual(mock_xxx.call_count, 0) -> mock_xxx.assert_not_called
assertGreater(mock.call_count, 0) -> mock.assert_called()
assertGreaterEqual(mock.call_count, 1) -> mock.assert_called()
JIRA: YARDSTICK-1069
Change-Id: I890084d120c8e78304e169e2a0e5d30011a41525
Signed-off-by: Emma Foley <emma.l.foley@intel.com>
10 files changed, 52 insertions, 51 deletions
diff --git a/yardstick/tests/unit/benchmark/core/test_report.py b/yardstick/tests/unit/benchmark/core/test_report.py index a684ad750..524302f92 100644 --- a/yardstick/tests/unit/benchmark/core/test_report.py +++ b/yardstick/tests/unit/benchmark/core/test_report.py @@ -42,16 +42,16 @@ class ReportTestCase(unittest.TestCase): self.param.task_id = [FAKE_TASK_ID] self.rep = report.Report() - @mock.patch('yardstick.benchmark.core.report.Report._get_tasks') - @mock.patch('yardstick.benchmark.core.report.Report._get_fieldkeys') - @mock.patch('yardstick.benchmark.core.report.Report._validate') + @mock.patch.object(report.Report, '_get_tasks') + @mock.patch.object(report.Report, '_get_fieldkeys') + @mock.patch.object(report.Report, '_validate') def test_generate_success(self, mock_valid, mock_keys, mock_tasks): mock_tasks.return_value = FAKE_DB_TASK mock_keys.return_value = FAKE_DB_FIELDKEYS self.rep.generate(self.param) mock_valid.assert_called_once_with(FAKE_YAML_NAME, FAKE_TASK_ID) - self.assertEqual(1, mock_tasks.call_count) - self.assertEqual(1, mock_keys.call_count) + mock_tasks.assert_called_once_with() + mock_keys.assert_called_once_with() # pylint: disable=deprecated-method def test_invalid_yaml_name(self): diff --git a/yardstick/tests/unit/benchmark/runner/test_search.py b/yardstick/tests/unit/benchmark/runner/test_search.py index 4e5b4fe77..00a241c7c 100644 --- a/yardstick/tests/unit/benchmark/runner/test_search.py +++ b/yardstick/tests/unit/benchmark/runner/test_search.py @@ -38,7 +38,7 @@ class TestSearchRunnerHelper(unittest.TestCase): with helper.get_benchmark_instance(): helper() - self.assertEqual(method.call_count, 1) + method.assert_called_once() def test___call___error(self): cls = mock.MagicMock() @@ -199,4 +199,4 @@ class TestSearchRunner(unittest.TestCase): runner = SearchRunner({}) runner._run_benchmark(cls, 'my_method', scenario_cfg, {}) - self.assertEqual(mock_multi_process.Process.call_count, 1) + mock_multi_process.Process.assert_called_once() diff --git a/yardstick/tests/unit/network_services/helpers/test_dpdkbindnic_helper.py b/yardstick/tests/unit/network_services/helpers/test_dpdkbindnic_helper.py index 9d94e3d0b..e19311613 100644 --- a/yardstick/tests/unit/network_services/helpers/test_dpdkbindnic_helper.py +++ b/yardstick/tests/unit/network_services/helpers/test_dpdkbindnic_helper.py @@ -289,7 +289,7 @@ class TestDpdkNode(unittest.TestCase): dpdk_helper.force_dpdk_rebind = mock_helper_func = mock.Mock() dpdk_node._force_rebind() - self.assertEqual(mock_helper_func.call_count, 1) + mock_helper_func.assert_called_once() class TestDpdkBindHelper(unittest.TestCase): diff --git a/yardstick/tests/unit/network_services/test_yang_model.py b/yardstick/tests/unit/network_services/test_yang_model.py index a7eb36b8a..cbeb3a1f2 100644 --- a/yardstick/tests/unit/network_services/test_yang_model.py +++ b/yardstick/tests/unit/network_services/test_yang_model.py @@ -119,11 +119,11 @@ class YangModelTestCase(unittest.TestCase): y._rules = None self.assertIsNone(y.get_rules()) - self.assertEqual(read_mock.call_count, 1) - self.assertEqual(get_mock.call_count, 1) + read_mock.assert_called_once() + get_mock.assert_called_once() # True value should prevent calling read and get y._rules = 999 self.assertEqual(y.get_rules(), 999) - self.assertEqual(read_mock.call_count, 1) - self.assertEqual(get_mock.call_count, 1) + read_mock.assert_called_once() + get_mock.assert_called_once() diff --git a/yardstick/tests/unit/network_services/traffic_profile/test_prox_profile.py b/yardstick/tests/unit/network_services/traffic_profile/test_prox_profile.py index e466305ea..cf31cc27c 100644 --- a/yardstick/tests/unit/network_services/traffic_profile/test_prox_profile.py +++ b/yardstick/tests/unit/network_services/traffic_profile/test_prox_profile.py @@ -124,5 +124,5 @@ class TestProxProfile(unittest.TestCase): for _ in profile.bounds_iterator(mock_logger): pass - self.assertEqual(mock_logger.debug.call_count, 1) + mock_logger.debug.assert_called_once() self.assertEqual(mock_logger.info.call_count, 10) diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py index c74a6cf75..cdba303c7 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py @@ -208,13 +208,14 @@ class TestProxTestDataTuple(unittest.TestCase): my_mock_logger = mock.MagicMock() prox_test_data = ProxTestDataTuple(1, 2, 3, 4, 5, [6.1, 6.9, 6.4], 7, 8, 9) prox_test_data.log_data() - self.assertEqual(my_mock_logger.debug.call_count, 0) - self.assertEqual(mock_logger.debug.call_count, 0) + + my_mock_logger.debug.assert_not_called() + mock_logger.debug.assert_not_called() mock_logger.debug.reset_mock() prox_test_data.log_data(my_mock_logger) - self.assertEqual(my_mock_logger.debug.call_count, 0) - self.assertEqual(mock_logger.debug.call_count, 0) + my_mock_logger.assert_not_called() + mock_logger.debug.assert_not_called() class TestPacketDump(unittest.TestCase): @@ -306,7 +307,7 @@ class TestProxSocketHelper(unittest.TestCase): mock_sock = mock.MagicMock() prox = ProxSocketHelper(mock_sock) prox.connect('10.20.30.40', 23456) - self.assertEqual(mock_sock.connect.call_count, 1) + mock_sock.connect.assert_called_once() def test_get_sock(self): mock_sock = mock.MagicMock() @@ -616,7 +617,7 @@ class TestProxSocketHelper(unittest.TestCase): mock_socket = mock.MagicMock() prox = ProxSocketHelper(mock_socket) prox.dump_rx(3, 5, 8) - self.assertEqual(mock_socket.sendall.call_count, 1) + mock_socket.sendall.assert_called_once() def test_quit(self): mock_socket = mock.MagicMock() diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py index fa2d462ab..f5f4b3907 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py @@ -436,7 +436,7 @@ class TestProxApproxVnf(unittest.TestCase): prox_approx_vnf.resource_helper = resource_helper = mock.Mock() prox_approx_vnf._vnf_up_post() - self.assertEqual(resource_helper.up_post.call_count, 1) + resource_helper.up_post.assert_called_once() @mock.patch(SSH_HELPER) def test_vnf_execute_oserror(self, ssh, *args): diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py index b46ba657c..603f05b97 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py @@ -192,12 +192,12 @@ class TestVnfSshHelper(unittest.TestCase): self.assertFalse(ssh_helper.is_connected) cfg_file = ssh_helper.upload_config_file('my/prefix', 'my content') self.assertTrue(ssh_helper.is_connected) - self.assertEqual(mock_paramiko.SSHClient.call_count, 1) + mock_paramiko.SSHClient.assert_called_once() self.assertTrue(cfg_file.startswith('/tmp')) cfg_file = ssh_helper.upload_config_file('/my/prefix', 'my content') self.assertTrue(ssh_helper.is_connected) - self.assertEqual(mock_paramiko.SSHClient.call_count, 1) + mock_paramiko.SSHClient.assert_called_once() self.assertEqual(cfg_file, '/my/prefix') def test_join_bin_path(self): @@ -234,17 +234,17 @@ class TestVnfSshHelper(unittest.TestCase): self.assertFalse(ssh_helper.is_connected) ssh_helper.provision_tool() self.assertTrue(ssh_helper.is_connected) - self.assertEqual(mock_paramiko.SSHClient.call_count, 1) - self.assertEqual(mock_provision_tool.call_count, 1) + mock_paramiko.SSHClient.assert_called_once() + mock_provision_tool.assert_called_once() ssh_helper.provision_tool(tool_file='my_tool.sh') self.assertTrue(ssh_helper.is_connected) - self.assertEqual(mock_paramiko.SSHClient.call_count, 1) + mock_paramiko.SSHClient.assert_called_once() self.assertEqual(mock_provision_tool.call_count, 2) ssh_helper.provision_tool('tool_path', 'my_tool.sh') self.assertTrue(ssh_helper.is_connected) - self.assertEqual(mock_paramiko.SSHClient.call_count, 1) + mock_paramiko.SSHClient.assert_called_once() self.assertEqual(mock_provision_tool.call_count, 3) @@ -579,9 +579,9 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): result = dpdk_setup_helper.build_config() self.assertEqual(result, expected) self.assertGreaterEqual(ssh_helper.upload_config_file.call_count, 2) - self.assertGreaterEqual(mock_find.call_count, 1) - self.assertGreaterEqual(mock_multi_port_config.generate_config.call_count, 1) - self.assertGreaterEqual(mock_multi_port_config.generate_script.call_count, 1) + mock_find.assert_called() + mock_multi_port_config.generate_config.assert_called() + mock_multi_port_config.generate_script.assert_called() scenario_helper.vnf_cfg = {'file': 'fake_file'} dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) @@ -593,9 +593,9 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): mock_open_rf.assert_called_once() self.assertEqual(result, expected) self.assertGreaterEqual(ssh_helper.upload_config_file.call_count, 2) - self.assertGreaterEqual(mock_find.call_count, 1) - self.assertGreaterEqual(mock_multi_port_config.generate_config.call_count, 1) - self.assertGreaterEqual(mock_multi_port_config.generate_script.call_count, 1) + mock_find.assert_called() + mock_multi_port_config.generate_config.assert_called() + mock_multi_port_config.generate_script.assert_called() def test__build_pipeline_kwargs(self): vnfd_helper = VnfdHelper(self.VNFD_0) @@ -1013,7 +1013,7 @@ class TestClientResourceHelper(unittest.TestCase): client_resource_helper.client.get_stats.side_effect = mock_state_error self.assertEqual(client_resource_helper.get_stats(), {}) - self.assertEqual(client_resource_helper.client.get_stats.call_count, 1) + client_resource_helper.client.get_stats.assert_called_once() def test_generate_samples(self): vnfd_helper = VnfdHelper(self.VNFD_0) @@ -1164,7 +1164,7 @@ class TestClientResourceHelper(unittest.TestCase): client_resource_helper.client = mock.Mock() self.assertIsNone(client_resource_helper.clear_stats()) - self.assertEqual(client_resource_helper.client.clear_stats.call_count, 1) + client_resource_helper.client.clear_stats.assert_called_once() def test_clear_stats_of_ports(self): vnfd_helper = VnfdHelper(self.VNFD_0) @@ -1175,7 +1175,7 @@ class TestClientResourceHelper(unittest.TestCase): client_resource_helper.client = mock.Mock() self.assertIsNone(client_resource_helper.clear_stats([3, 4])) - self.assertEqual(client_resource_helper.client.clear_stats.call_count, 1) + client_resource_helper.client.clear_stats.assert_called_once() def test_start(self): vnfd_helper = VnfdHelper(self.VNFD_0) @@ -1186,7 +1186,7 @@ class TestClientResourceHelper(unittest.TestCase): client_resource_helper.client = mock.Mock() self.assertIsNone(client_resource_helper.start()) - self.assertEqual(client_resource_helper.client.start.call_count, 1) + client_resource_helper.client.start.assert_called_once() def test_start_ports(self): vnfd_helper = VnfdHelper(self.VNFD_0) @@ -1197,7 +1197,7 @@ class TestClientResourceHelper(unittest.TestCase): client_resource_helper.client = mock.Mock() self.assertIsNone(client_resource_helper.start([3, 4])) - self.assertEqual(client_resource_helper.client.start.call_count, 1) + client_resource_helper.client.start.assert_called_once() def test_collect_kpi_with_queue(self): vnfd_helper = VnfdHelper(self.VNFD_0) @@ -1405,7 +1405,7 @@ class TestSampleVNFDeployHelper(unittest.TestCase): self.assertIsNone(sample_vnf_deploy_helper.deploy_vnfs('name1')) sample_vnf_deploy_helper.DISABLE_DEPLOY = True self.assertEqual(ssh_helper.execute.call_count, 5) - self.assertEqual(ssh_helper.put.call_count, 1) + ssh_helper.put.assert_called_once() @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') @mock.patch('subprocess.check_output') @@ -1420,7 +1420,7 @@ class TestSampleVNFDeployHelper(unittest.TestCase): self.assertIsNone(sample_vnf_deploy_helper.deploy_vnfs('name1')) self.assertEqual(ssh_helper.execute.call_count, 5) - self.assertEqual(ssh_helper.put.call_count, 1) + ssh_helper.put.assert_called_once() @mock.patch('subprocess.check_output') def test_deploy_vnfs_early_success(self, *args): @@ -1433,8 +1433,8 @@ class TestSampleVNFDeployHelper(unittest.TestCase): sample_vnf_deploy_helper.DISABLE_DEPLOY = False self.assertIsNone(sample_vnf_deploy_helper.deploy_vnfs('name1')) - self.assertEqual(ssh_helper.execute.call_count, 1) - self.assertEqual(ssh_helper.put.call_count, 0) + ssh_helper.execute.assert_called_once() + ssh_helper.put.assert_not_called() class TestScenarioHelper(unittest.TestCase): diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py index 956c192aa..8cc118a31 100644 --- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py +++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py @@ -53,7 +53,7 @@ class TestIxiaResourceHelper(unittest.TestCase): ixia_resource_helper.client = mock_client ixia_resource_helper.stop_collect() - self.assertEqual(mock_client.ix_stop_traffic.call_count, 1) + mock_client.ix_stop_traffic.assert_called_once() def test_run_traffic(self): mock_tprofile = mock.Mock() diff --git a/yardstick/tests/unit/test_ssh.py b/yardstick/tests/unit/test_ssh.py index 080d27837..5cf1e50a0 100644 --- a/yardstick/tests/unit/test_ssh.py +++ b/yardstick/tests/unit/test_ssh.py @@ -193,10 +193,10 @@ class SSHTestCase(unittest.TestCase): with self.assertRaises(exceptions.SSHError) as raised: test_ssh._get_client() - self.assertEqual(mock_paramiko.SSHClient.call_count, 1) - self.assertEqual(mock_paramiko.AutoAddPolicy.call_count, 1) - self.assertEqual(fake_client.set_missing_host_key_policy.call_count, 1) - self.assertEqual(fake_client.connect.call_count, 1) + mock_paramiko.SSHClient.assert_called_once() + mock_paramiko.AutoAddPolicy.assert_called_once() + fake_client.set_missing_host_key_policy.assert_called_once() + fake_client.connect.assert_called_once() exc_str = str(raised.exception) self.assertIn('raised during connect', exc_str) self.assertIn('MyError', exc_str) @@ -510,7 +510,7 @@ class TestAutoConnectSSH(unittest.TestCase): auto_connect_ssh._get_client = mock__get_client = mock.Mock() auto_connect_ssh._connect() - self.assertEqual(mock__get_client.call_count, 1) + mock__get_client.assert_called_once() def test___init___negative(self): with self.assertRaises(TypeError): @@ -543,7 +543,7 @@ class TestAutoConnectSSH(unittest.TestCase): auto_connect_ssh.get_file_obj('remote/path', mock.Mock()) - self.assertEqual(mock_sftp.getfo.call_count, 1) + mock_sftp.getfo.assert_called_once() def test__make_dict(self): auto_connect_ssh = AutoConnectSSH('user1', 'host1') @@ -580,7 +580,7 @@ class TestAutoConnectSSH(unittest.TestCase): auto_connect_ssh.put('a', 'z') with mock_scp_client_type() as mock_scp_client: - self.assertEqual(mock_scp_client.put.call_count, 1) + mock_scp_client.put.assert_called_once() @mock.patch('yardstick.ssh.SCPClient') def test_get(self, mock_scp_client_type): @@ -589,7 +589,7 @@ class TestAutoConnectSSH(unittest.TestCase): auto_connect_ssh.get('a', 'z') with mock_scp_client_type() as mock_scp_client: - self.assertEqual(mock_scp_client.get.call_count, 1) + mock_scp_client.get.assert_called_once() def test_put_file(self): auto_connect_ssh = AutoConnectSSH('user1', 'host1') @@ -597,4 +597,4 @@ class TestAutoConnectSSH(unittest.TestCase): auto_connect_ssh._put_file_sftp = mock_put_sftp = mock.Mock() auto_connect_ssh.put_file('a', 'b') - self.assertEqual(mock_put_sftp.call_count, 1) + mock_put_sftp.assert_called_once() |