Python unittest.mock.PropertyMock() Examples
The following are 30
code examples of unittest.mock.PropertyMock().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
unittest.mock
, or try the search function
.
Example #1
Source File: test_interest.py From biweeklybudget with GNU Affero General Public License v3.0 | 6 votes |
def test_find_payments_total_too_low(self): cls = LowestInterestRateFirstMethod(Decimal('3.00')) s1 = Mock(spec_set=CCStatement) type(s1).minimum_payment = PropertyMock(return_value=Decimal('2.00')) type(s1).principal = PropertyMock(return_value=Decimal('10.00')) s2 = Mock(spec_set=CCStatement) type(s2).minimum_payment = PropertyMock(return_value=Decimal('5.00')) type(s2).principal = PropertyMock(return_value=Decimal('25.00')) s3 = Mock(spec_set=CCStatement) type(s3).minimum_payment = PropertyMock(return_value=Decimal('2.00')) type(s3).principal = PropertyMock(return_value=Decimal('1234.56')) s4 = Mock(spec_set=CCStatement) type(s4).minimum_payment = PropertyMock(return_value=Decimal('7.00')) type(s4).principal = PropertyMock(return_value=Decimal('3.00')) with pytest.raises(TypeError): cls.find_payments([s1, s2, s3, s4])
Example #2
Source File: test_sink_processor.py From winton-kafka-streams with Apache License 2.0 | 6 votes |
def test_sinkProcessorProcess(): with mock.patch('winton_kafka_streams.processor.ProcessorContext.timestamp', new_callable=mock.PropertyMock) as mock_timestamp: mock_timestamp.return_value = _expected_timestamp mock_task = mock.Mock() mock_task.application_id = 'test_id' mock_task_id = TaskId('test_group', 0) processor_context = wks_processor.ProcessorContext(mock_task_id, mock_task, None, None, {}) processor_context.record_collector = mock.MagicMock() sink = wks_processor.SinkProcessor('topic1') sink.initialise('test-sink', processor_context) assert sink.name == 'test-sink' test_key, test_value = 'test-key', 'test-value' sink.process(test_key, test_value) assert processor_context.record_collector.called_with(test_key, test_value, _expected_timestamp)
Example #3
Source File: conftest.py From torf with GNU General Public License v3.0 | 6 votes |
def forced_piece_size(pytestconfig): @contextlib.contextmanager def _forced_piece_size(piece_size): orig_piece_size_min = torf.Torrent.piece_size_min torf.Torrent.piece_size_min = piece_size with mock.patch('torf.Torrent.piece_size', new_callable=mock.PropertyMock) as mock_piece_size: def piece_size_setter(prop, torrent, value): torrent.metainfo['info']['piece length'] = piece_size mock_piece_size.return_value = piece_size mock_piece_size.__set__ = piece_size_setter yield piece_size torf.Torrent.piece_size_min = orig_piece_size_min return _forced_piece_size # https://stackoverflow.com/a/45690594
Example #4
Source File: test_models.py From resolwe with Apache License 2.0 | 6 votes |
def test_list(self, os_mock, path_mock): data = self.create_data(path_mock, self.contributor, self.process) stat_mock = MagicMock() type(stat_mock).st_size = PropertyMock(side_effect=[34, 42000, 42]) path_mock.return_value = MagicMock( is_file=lambda: True, stat=lambda: stat_mock, __fspath__=lambda: "my_mocked_file_name", ) data.output = { "file_list": [ {"file": "test_01.tmp",}, {"file": "test_02.tmp", "refs": ["ref_file1.tmp"]}, ] } hydrate_size(data) self.assertEqual(data.output["file_list"][0]["size"], 34) self.assertEqual(data.output["file_list"][0]["total_size"], 34) self.assertEqual(data.output["file_list"][1]["size"], 42000) self.assertEqual(data.output["file_list"][1]["total_size"], 42042) self.assertEqual(data.size, 34 + 42042)
Example #5
Source File: test_unischema.py From petastorm with Apache License 2.0 | 6 votes |
def _mock_parquet_dataset(partitions, arrow_schema): """Creates a pyarrow.ParquetDataset mock capable of returning: parquet_dataset.pieces[0].get_metadata(parquet_dataset.fs.open).schema.to_arrow_schema() == schema parquet_dataset.partitions = partitions :param partitions: expected to be a list of pa.parquet.PartitionSet :param arrow_schema: an instance of pa.arrow_schema to be assumed by the mock parquet dataset object. :return: """ piece_mock = mock.Mock() piece_mock.get_metadata().schema.to_arrow_schema.return_value = arrow_schema dataset_mock = mock.Mock() type(dataset_mock).pieces = mock.PropertyMock(return_value=[piece_mock]) type(dataset_mock).partitions = partitions return dataset_mock
Example #6
Source File: docker.py From fastlane with MIT License | 6 votes |
def new( name, container_id=None, state=None, status="created", stdout=None, stderr=None ): if container_id is None: container_id = f"fastlane-job-{str(uuid4())}" container_mock = MagicMock(attrs={}, status=status, id=container_id) name = PropertyMock(return_value=name) type(container_mock).name = name if state is not None: container_mock.attrs["State"] = state container_mock.logs.side_effect = ContainerFixture.get_logs(container_mock) container_mock.stdout = stdout container_mock.stderr = stderr container_mock.image = MagicMock(attrs={"RepoTags": ["ubuntu:latest"]}) return container_mock
Example #7
Source File: decorators.py From opencraft with GNU Affero General Public License v3.0 | 6 votes |
def patch_git_checkout(func): """ Patch git checkout process in order to allow mocking up the checkout process and the working directory """ @wraps(func) def _wrap(*args, **kwargs): """ Calls the given function with extra parameters for git checkout mocking """ with mock.patch('git.refs.head.Head.checkout') as checkout: with mock.patch('git.Git.working_dir', new_callable=mock.PropertyMock) as wd: return func(git_checkout=checkout, git_working_dir=wd, *args, **kwargs) return _wrap
Example #8
Source File: test_inputs.py From pymeasure with MIT License | 6 votes |
def test_leftclick_should_update_parameter(self, qtbot, default_value): # set up BooleanInput bool_param = BooleanParameter('potato', default=default_value) with mock.patch('test_inputs.BooleanParameter.value', new_callable=mock.PropertyMock, return_value=default_value) as p: bool_input = BooleanInput(bool_param) qtbot.addWidget(bool_input) bool_input.show() # TODO: fix: fails to toggle on Windows #qtbot.mouseClick(bool_input, QtCore.Qt.LeftButton) bool_input.setValue(not default_value) assert bool_input.value() == (not default_value) bool_input.parameter # lazy update p.assert_called_once_with(not default_value)
Example #9
Source File: test_mssql_to_hive.py From airflow with Apache License 2.0 | 6 votes |
def test_execute_empty_description_field(self, mock_hive_hook, mock_mssql_hook, mock_tmp_file, mock_csv): type(mock_tmp_file).name = PropertyMock(return_value='tmp_file') mock_tmp_file.return_value.__enter__ = Mock(return_value=mock_tmp_file) mock_mssql_hook_get_conn = mock_mssql_hook.return_value.get_conn.return_value.__enter__ mock_mssql_hook_cursor = mock_mssql_hook_get_conn.return_value.cursor.return_value.__enter__ mock_mssql_hook_cursor.return_value.description = [('', '')] mssql_to_hive_transfer = MsSqlToHiveOperator(**self.kwargs) mssql_to_hive_transfer.execute(context={}) field_dict = OrderedDict() col_count = 0 for field in mock_mssql_hook_cursor.return_value.description: col_count += 1 col_position = "Column{position}".format(position=col_count) field_dict[col_position] = mssql_to_hive_transfer.type_map(field[1]) mock_hive_hook.return_value.load_file.assert_called_once_with( mock_tmp_file.name, mssql_to_hive_transfer.hive_table, field_dict=field_dict, create=mssql_to_hive_transfer.create, partition=mssql_to_hive_transfer.partition, delimiter=mssql_to_hive_transfer.delimiter, recreate=mssql_to_hive_transfer.recreate, tblproperties=mssql_to_hive_transfer.tblproperties)
Example #10
Source File: test_azure_services.py From koku with GNU Affero General Public License v3.0 | 6 votes |
def test_get_cost_export_for_key(self): """Test that a cost export is retrieved by a key.""" today = self.current_date_time yesterday = today - relativedelta(days=1) test_matrix = [ {"key": "{}_{}_day_{}".format(self.container_name, "blob", today.day), "expected_date": today.date()}, { "key": "{}_{}_day_{}".format(self.container_name, "blob", yesterday.day), "expected_date": yesterday.date(), }, ] for test in test_matrix: key = test.get("key") expected_modified_date = test.get("expected_date") mock_blob = Mock(last_modified=Mock(date=Mock(return_value=expected_modified_date))) name_attr = PropertyMock(return_value=key) type(mock_blob).name = name_attr # kludge to set name attribute on Mock svc = self.get_mock_client(blob_list=[mock_blob]) cost_export = svc.get_cost_export_for_key(key, self.container_name) self.assertIsNotNone(cost_export) self.assertEquals(cost_export.name, key) self.assertEquals(cost_export.last_modified.date(), expected_modified_date)
Example #11
Source File: test_log_endpoint.py From airflow with Apache License 2.0 | 6 votes |
def test_get_logs_for_handler_without_read_method(self, mock_log_reader): type(mock_log_reader.return_value).supports_read = PropertyMock(return_value=False) key = self.app.config["SECRET_KEY"] serializer = URLSafeSerializer(key) token = serializer.dumps({"download_logs": False}) headers = {'Content-Type': 'application/jso'} # check guessing response = self.client.get( f"api/v1/dags/{self.DAG_ID}/dagRuns/TEST_DAG_RUN_ID/" f"taskInstances/{self.TASK_ID}/logs/1?token={token}", headers=headers ) self.assertEqual(400, response.status_code) self.assertIn( 'Task log handler does not support read logs.', response.data.decode('utf-8'))
Example #12
Source File: test_views.py From airflow with Apache License 2.0 | 6 votes |
def test_get_logs_for_handler_without_read_method(self, mock_log_reader): type(mock_log_reader.return_value).supports_read = PropertyMock(return_value=False) url_template = "get_logs_with_metadata?dag_id={}&" \ "task_id={}&execution_date={}&" \ "try_number={}&metadata={}&format=json" try_number = 1 url = url_template.format(self.DAG_ID, self.TASK_ID, quote_plus(self.DEFAULT_DATE.isoformat()), try_number, json.dumps({})) response = self.client.get(url) self.assertEqual(200, response.status_code) self.assertIn('message', response.json) self.assertIn('metadata', response.json) self.assertIn( 'Task log handler does not support read logs.', response.json['message'])
Example #13
Source File: TestDiscoveredPrintersModel.py From Cura with GNU Lesser General Public License v3.0 | 6 votes |
def test_discoveredPrinters(discovered_printer_model): mocked_device = MagicMock() cluster_size = PropertyMock(return_value = 1) type(mocked_device).clusterSize = cluster_size mocked_callback = MagicMock() discovered_printer_model.addDiscoveredPrinter("ip", "key", "name", mocked_callback, "machine_type", mocked_device) device = discovered_printer_model.discoveredPrinters[0] discovered_printer_model.createMachineFromDiscoveredPrinter(device) mocked_callback.assert_called_with("key") assert len(discovered_printer_model.discoveredPrinters) == 1 discovered_printer_model.discoveredPrintersChanged = MagicMock() # Test if removing it works discovered_printer_model.removeDiscoveredPrinter("ip") assert len(discovered_printer_model.discoveredPrinters) == 0 assert discovered_printer_model.discoveredPrintersChanged.emit.call_count == 1 # Removing it again shouldn't cause another signal emit discovered_printer_model.removeDiscoveredPrinter("ip") assert discovered_printer_model.discoveredPrintersChanged.emit.call_count == 1
Example #14
Source File: test_azure_services.py From koku with GNU Affero General Public License v3.0 | 6 votes |
def test_describe_cost_management_exports_wrong_account(self): """Test that cost management exports are not returned from incorrect account.""" resource_id = ( f"/subscriptions/{FAKE.uuid4()}/resourceGroups/" f"{self.resource_group_name}/providers/Microsoft.Storage/" f"storageAccounts/{self.storage_account_name}" ) mock_export = Mock( delivery_info=Mock( destination=Mock( container=self.container_name, root_folder_path=self.export_directory, resource_id=resource_id ) ) ) name_attr = PropertyMock(return_value=f"{self.container_name}_blob") type(mock_export).name = name_attr # kludge to set name attribute on Mock svc = self.get_mock_client(cost_exports=[mock_export]) exports = svc.describe_cost_management_exports() self.assertEquals(exports, [])
Example #15
Source File: test_azure_services.py From koku with GNU Affero General Public License v3.0 | 6 votes |
def test_download_cost_report_exception(self, mock_factory): """Test that function handles a raised exception.""" key = FAKE.word() mock_blob = Mock(last_modified=Mock(date=Mock(return_value=datetime.now()))) name_attr = PropertyMock(return_value=key) type(mock_blob).name = name_attr # kludge to set name attribute on Mock mock_factory.return_value = Mock( spec=AzureClientFactory, cloud_storage_account=Mock( return_value=Mock( spec=BlobServiceClient, get_blob_client=Mock(side_effect=AdalError("test error")), get_container_client=Mock( return_value=Mock(spec=ContainerClient, list_blobs=Mock(return_value=[mock_blob])) ), ) ), ) with self.assertRaises(AzureServiceError): service = AzureService( self.tenant_id, self.client_id, self.client_secret, self.resource_group_name, self.storage_account_name ) service.download_cost_export(key=key, container_name=FAKE.word())
Example #16
Source File: test_driver_updater.py From octavia with Apache License 2.0 | 6 votes |
def test_check_for_lb_vip_deallocate(self, mock_get_net_drvr): mock_repo = mock.MagicMock() mock_lb = mock.MagicMock() mock_vip = mock.MagicMock() mock_octavia_owned = mock.PropertyMock(side_effect=[True, False]) type(mock_vip).octavia_owned = mock_octavia_owned mock_lb.vip = mock_vip mock_repo.get.return_value = mock_lb mock_net_drvr = mock.MagicMock() mock_get_net_drvr.return_value = mock_net_drvr self.driver_updater._check_for_lb_vip_deallocate(mock_repo, 'bogus_id') mock_net_drvr.deallocate_vip.assert_called_once_with(mock_vip) mock_net_drvr.reset_mock() self.driver_updater._check_for_lb_vip_deallocate(mock_repo, 'bogus_id') mock_net_drvr.deallocate_vip.assert_not_called()
Example #17
Source File: test_hostops.py From compute-hyperv with Apache License 2.0 | 6 votes |
def _test_migrate_vm(self, mock_get_by_uuid, mock_wait_for_instance_pending_task, instance_uuid=None, vm_state='active'): self._hostops._vmutils.get_instance_uuid.return_value = instance_uuid instance = mock_get_by_uuid.return_value type(instance).vm_state = mock.PropertyMock( side_effect=[vm_state]) self._hostops._migrate_vm(ctxt=mock.sentinel.CONTEXT, vm_name=mock.sentinel.VM_NAME, host=mock.sentinel.HOST) if not instance_uuid: self.assertFalse(self._hostops._api.live_migrate.called) return if vm_state == 'active': self._hostops._api.live_migrate.assert_called_once_with( mock.sentinel.CONTEXT, instance, block_migration=False, disk_over_commit=False, host_name=None) else: self._hostops._api.resize.assert_called_once_with( mock.sentinel.CONTEXT, instance, flavor_id=None, clean_shutdown=True) mock_wait_for_instance_pending_task.assert_called_once_with( mock.sentinel.CONTEXT, instance_uuid)
Example #18
Source File: test_interest.py From biweeklybudget with GNU Affero General Public License v3.0 | 6 votes |
def test_pay(self): b = Mock(spec_set=_BillingPeriod) b_next = Mock(spec_set=_BillingPeriod) type(b_next).payment_date = PropertyMock(return_value=date(2017, 1, 15)) type(b).next_period = PropertyMock(return_value=b_next) i = Mock(spec_set=_InterestCalculation) p = Mock(spec_set=_MinPaymentFormula) cls = CCStatement( i, Decimal('1.23'), p, b, end_balance=Decimal('1.50'), interest_amt=Decimal('0.27') ) mock_stmt = Mock(spec_set=CCStatement) with patch( 'biweeklybudget.interest.CCStatement.next_with_transactions', autospec=True ) as m: m.return_value = mock_stmt res = cls.pay(Decimal('98.76')) assert res == mock_stmt assert m.mock_calls == [ call(cls, {date(2017, 1, 15): Decimal('98.76')}) ]
Example #19
Source File: test_interest.py From biweeklybudget with GNU Affero General Public License v3.0 | 6 votes |
def test_next_with_transactions(self): b = Mock(spec_set=_BillingPeriod) b_next = Mock(spec_set=_BillingPeriod) type(b).next_period = PropertyMock(return_value=b_next) i = Mock(spec_set=_InterestCalculation) p = Mock(spec_set=_MinPaymentFormula) cls = CCStatement( i, Decimal('1.23'), p, b, end_balance=Decimal('1.50'), interest_amt=Decimal('0.27') ) mock_stmt = Mock(spec_set=CCStatement) with patch('biweeklybudget.interest.CCStatement', autospec=True) as m: m.return_value = mock_stmt res = cls.next_with_transactions({'foo': 'bar'}) assert res == mock_stmt assert m.mock_calls == [ call( i, Decimal('1.50'), p, b_next, transactions={'foo': 'bar'} ) ]
Example #20
Source File: test_barbican_legacy.py From octavia with Apache License 2.0 | 6 votes |
def test_get_cert_no_registration_raise_on_secret_access_failure(self): self.bc.containers.get.return_value = self.container with mock.patch('barbicanclient.v1.secrets.Secret.payload', new_callable=mock.PropertyMock) as mock_payload: mock_payload.side_effect = ValueError # Get the container data self.assertRaises( ValueError, self.cert_manager.get_cert, context=self.context, cert_ref=self.container_ref, check_only=True ) # 'get' should be called once with the container_ref self.bc.containers.get.assert_called_once_with( container_ref=self.container_ref )
Example #21
Source File: test_interest.py From biweeklybudget with GNU Affero General Public License v3.0 | 6 votes |
def test_find_payments(self): cls = LowestBalanceFirstMethod(Decimal('100.00')) s1 = Mock(spec_set=CCStatement) type(s1).minimum_payment = PropertyMock(return_value=Decimal('2.00')) type(s1).principal = PropertyMock(return_value=Decimal('10.00')) s2 = Mock(spec_set=CCStatement) type(s2).minimum_payment = PropertyMock(return_value=Decimal('5.00')) type(s2).principal = PropertyMock(return_value=Decimal('25.00')) s3 = Mock(spec_set=CCStatement) type(s3).minimum_payment = PropertyMock(return_value=Decimal('2.00')) type(s3).principal = PropertyMock(return_value=Decimal('1234.56')) s4 = Mock(spec_set=CCStatement) type(s4).minimum_payment = PropertyMock(return_value=Decimal('7.00')) type(s4).principal = PropertyMock(return_value=Decimal('3.00')) assert cls.find_payments([s1, s2, s3, s4]) == [ Decimal('2.00'), Decimal('5.00'), Decimal('2.00'), Decimal('91.00') ]
Example #22
Source File: test_interest.py From biweeklybudget with GNU Affero General Public License v3.0 | 6 votes |
def test_find_payments_total_too_low(self): cls = LowestBalanceFirstMethod(Decimal('3.00')) s1 = Mock(spec_set=CCStatement) type(s1).minimum_payment = PropertyMock(return_value=Decimal('2.00')) type(s1).principal = PropertyMock(return_value=Decimal('10.00')) s2 = Mock(spec_set=CCStatement) type(s2).minimum_payment = PropertyMock(return_value=Decimal('5.00')) type(s2).principal = PropertyMock(return_value=Decimal('25.00')) s3 = Mock(spec_set=CCStatement) type(s3).minimum_payment = PropertyMock(return_value=Decimal('2.00')) type(s3).principal = PropertyMock(return_value=Decimal('1234.56')) s4 = Mock(spec_set=CCStatement) type(s4).minimum_payment = PropertyMock(return_value=Decimal('7.00')) type(s4).principal = PropertyMock(return_value=Decimal('3.00')) with pytest.raises(TypeError): cls.find_payments([s1, s2, s3, s4])
Example #23
Source File: test_interest.py From biweeklybudget with GNU Affero General Public License v3.0 | 6 votes |
def test_find_payments(self): cls = HighestBalanceFirstMethod(Decimal('100.00')) s1 = Mock(spec_set=CCStatement) type(s1).minimum_payment = PropertyMock(return_value=Decimal('2.00')) type(s1).principal = PropertyMock(return_value=Decimal('10.00')) s2 = Mock(spec_set=CCStatement) type(s2).minimum_payment = PropertyMock(return_value=Decimal('5.00')) type(s2).principal = PropertyMock(return_value=Decimal('25.00')) s3 = Mock(spec_set=CCStatement) type(s3).minimum_payment = PropertyMock(return_value=Decimal('2.00')) type(s3).principal = PropertyMock(return_value=Decimal('1234.56')) s4 = Mock(spec_set=CCStatement) type(s4).minimum_payment = PropertyMock(return_value=Decimal('7.00')) type(s4).principal = PropertyMock(return_value=Decimal('3.00')) assert cls.find_payments([s1, s2, s3, s4]) == [ Decimal('2.00'), Decimal('5.00'), Decimal('86.00'), Decimal('7.00') ]
Example #24
Source File: test_interest.py From biweeklybudget with GNU Affero General Public License v3.0 | 6 votes |
def test_find_payments(self): cls = HighestInterestRateFirstMethod(Decimal('100.00')) s1 = Mock(spec_set=CCStatement) type(s1).minimum_payment = PropertyMock(return_value=Decimal('2.00')) type(s1).apr = PropertyMock(return_value=Decimal('0.0100')) type(s1).principal = PropertyMock(return_value=Decimal('10.00')) s2 = Mock(spec_set=CCStatement) type(s2).minimum_payment = PropertyMock(return_value=Decimal('5.00')) type(s2).apr = PropertyMock(return_value=Decimal('0.0200')) type(s2).principal = PropertyMock(return_value=Decimal('25.00')) s3 = Mock(spec_set=CCStatement) type(s3).minimum_payment = PropertyMock(return_value=Decimal('2.00')) type(s3).apr = PropertyMock(return_value=Decimal('0.0800')) type(s3).principal = PropertyMock(return_value=Decimal('1234.56')) s4 = Mock(spec_set=CCStatement) type(s4).minimum_payment = PropertyMock(return_value=Decimal('7.00')) type(s4).apr = PropertyMock(return_value=Decimal('0.0300')) type(s4).principal = PropertyMock(return_value=Decimal('3.00')) assert cls.find_payments([s1, s2, s3, s4]) == [ Decimal('2.00'), Decimal('5.00'), Decimal('86.00'), Decimal('7.00') ]
Example #25
Source File: test_interest.py From biweeklybudget with GNU Affero General Public License v3.0 | 6 votes |
def test_find_payments_total_too_low(self): cls = HighestInterestRateFirstMethod(Decimal('3.00')) s1 = Mock(spec_set=CCStatement) type(s1).minimum_payment = PropertyMock(return_value=Decimal('2.00')) type(s1).principal = PropertyMock(return_value=Decimal('10.00')) s2 = Mock(spec_set=CCStatement) type(s2).minimum_payment = PropertyMock(return_value=Decimal('5.00')) type(s2).principal = PropertyMock(return_value=Decimal('25.00')) s3 = Mock(spec_set=CCStatement) type(s3).minimum_payment = PropertyMock(return_value=Decimal('2.00')) type(s3).principal = PropertyMock(return_value=Decimal('1234.56')) s4 = Mock(spec_set=CCStatement) type(s4).minimum_payment = PropertyMock(return_value=Decimal('7.00')) type(s4).principal = PropertyMock(return_value=Decimal('3.00')) with pytest.raises(TypeError): cls.find_payments([s1, s2, s3, s4])
Example #26
Source File: test_interest.py From biweeklybudget with GNU Affero General Public License v3.0 | 6 votes |
def test_find_payments(self): cls = LowestInterestRateFirstMethod(Decimal('100.00')) s1 = Mock(spec_set=CCStatement) type(s1).minimum_payment = PropertyMock(return_value=Decimal('2.00')) type(s1).apr = PropertyMock(return_value=Decimal('0.0100')) type(s1).principal = PropertyMock(return_value=Decimal('10.00')) s2 = Mock(spec_set=CCStatement) type(s2).minimum_payment = PropertyMock(return_value=Decimal('5.00')) type(s2).apr = PropertyMock(return_value=Decimal('0.0200')) type(s2).principal = PropertyMock(return_value=Decimal('25.00')) s3 = Mock(spec_set=CCStatement) type(s3).minimum_payment = PropertyMock(return_value=Decimal('2.00')) type(s3).apr = PropertyMock(return_value=Decimal('0.0800')) type(s3).principal = PropertyMock(return_value=Decimal('1234.56')) s4 = Mock(spec_set=CCStatement) type(s4).minimum_payment = PropertyMock(return_value=Decimal('7.00')) type(s4).apr = PropertyMock(return_value=Decimal('0.0300')) type(s4).principal = PropertyMock(return_value=Decimal('3.00')) assert cls.find_payments([s1, s2, s3, s4]) == [ Decimal('86.00'), Decimal('5.00'), Decimal('2.00'), Decimal('7.00') ]
Example #27
Source File: test_hive_to_samba.py From airflow with Apache License 2.0 | 6 votes |
def test_execute(self, mock_tmp_file, mock_hive_hook, mock_samba_hook): type(mock_tmp_file).name = PropertyMock(return_value='tmp_file') mock_tmp_file.return_value.__enter__ = Mock(return_value=mock_tmp_file) context = {} HiveToSambaOperator(**self.kwargs).execute(context) mock_hive_hook.assert_called_once_with( hiveserver2_conn_id=self.kwargs['hiveserver2_conn_id']) mock_hive_hook.return_value.to_csv.assert_called_once_with( hql=self.kwargs['hql'], csv_filepath=mock_tmp_file.name, hive_conf=context_to_airflow_vars(context)) mock_samba_hook.assert_called_once_with( samba_conn_id=self.kwargs['samba_conn_id']) mock_samba_hook.return_value.push_from_local.assert_called_once_with( self.kwargs['destination_filepath'], mock_tmp_file.name)
Example #28
Source File: test_inputs.py From pymeasure with MIT License | 5 votes |
def test_setValue_should_update_param(self, qtbot): float_param = FloatParameter('potato', minimum=-1000, maximum=1000, default=10.0) sci_input = ScientificInput(float_param) qtbot.addWidget(sci_input) with mock.patch('test_inputs.FloatParameter.value', new_callable=mock.PropertyMock, return_value=10.0) as p: # test sci_input.setValue(5.0) sci_input.parameter # lazy update p.assert_called_once_with(5.0)
Example #29
Source File: test_late_swap.py From pydfs-lineup-optimizer with MIT License | 5 votes |
def test_late_swap_optimize_with_all_active_players(self): with patch('pydfs_lineup_optimizer.player.Player.is_game_started', new_callable=PropertyMock) as \ mock_is_game_started: mock_is_game_started.return_value = True lineup = next(self.lineup_optimizer.optimize_lineups([self.lineup])) for player, new_lineup_player in zip(self.lineup, lineup): self.assertEqual(player, new_lineup_player)
Example #30
Source File: test_cfg.py From angr with BSD 2-Clause "Simplified" License | 5 votes |
def disable_successors_of_a_node_delegate_the_logic_to_the_CFGNode_successor(self): with mock.patch.object(CFGVisitor, 'reset'): with mock.patch.object(CFGNode, 'successors', new_callable=mock.PropertyMock) as mock_successors: addr, size, cfg = 1, None, None node = CFGNode(0x42, addr, size, cfg, block_id=1) cfg_visitor = CFGVisitor(None) _ = cfg_visitor.successors(node) mock_successors.assert_called_once_with()