def test_train_with_stages(self):
        model = BasicModel({
            "stage": "second"
        })
        model._first_stage = MagicMock()
        model._second_stage = MagicMock()
        model._third_stage = MagicMock()
        model._save = MagicMock()
        model.stages = [
            ("first", model._first_stage),
            ("second", model._second_stage),
            ("third", model._third_stage)
        ]
        process = Mock(
            first=model._first_stage,
            second=model._second_stage,
            third=model._third_stage,
            save=model._save
        )
        model.train()

        process.assert_has_calls([
            call.second(),
            call.save(),
            call.third(),
            call.save()
        ])
        model._first_stage.assert_not_called()
Beispiel #2
0
    def test_decode_inputs_save_max_block_for_query(self):
        """Test saving max block parameter during all operation"""
        test_max_block = 1000
        test_contracts_from_elasticsearch = [{
            "_id": "contract" + str(i),
            "_source": {
                "abi": "contract",
                "address": "contract_address" + str(i)
            }
        } for i in range(3)]
        mockify(
            self.contracts, {
                "_iterate_contracts_with_abi":
                MagicMock(return_value=[test_contracts_from_elasticsearch]),
                "_get_max_block":
                MagicMock(side_effect=[test_max_block])
            }, ["decode_inputs"])
        process = Mock(iterate=self.contracts._iterate_contracts_with_abi,
                       decode=self.contracts._decode_inputs_for_contracts,
                       save=self.contracts._save_max_block)
        self.contracts.decode_inputs()

        self.contracts._get_max_block.assert_called_with(ANY)
        process.assert_has_calls([
            call.iterate(test_max_block),
            call.decode(ANY, test_max_block),
            call.save(ANY, test_max_block)
        ])
Beispiel #3
0
    def test_decode_inputs_save_inputs_decoded(self):
        """Test saving decoded inputs in process"""
        test_contracts = ["contract1", "contract2", "contract3"]
        test_contracts_from_elasticsearch = [{
            "_id": contract,
            "_source": {
                "abi": contract,
                "address": contract + "_address"
            }
        } for contract in test_contracts]
        mockify(
            self.contracts, {
                "_iterate_contracts_with_abi":
                MagicMock(return_value=[test_contracts_from_elasticsearch]),
                "_get_max_block":
                MagicMock()
            }, ["decode_inputs"])
        process = Mock(decode=self.contracts._decode_inputs_for_contracts,
                       save=self.contracts._save_max_block)

        self.contracts.decode_inputs()

        process.assert_has_calls([
            call.decode(test_contracts_from_elasticsearch, ANY),
            call.save(test_contracts, ANY)
        ])
Beispiel #4
0
    async def test_delete_expense(self, get_repository_mock,
                                  verify_if_exists_and_is_not_deleted_mock):
        #Arrange
        verify_if_exists_and_is_not_deleted_mock.return_value = True
        expense_mock = Mock()
        repository_mock = Mock()
        get_repository_mock.side_effect = [repository_mock]
        repository_mock.get_by_id = Mock(return_value=expense_mock)

        #Action
        await delete_expense('id')

        #Asserts
        repository_mock_calls = repository_mock.mock_calls
        self.assertEqual(len(repository_mock_calls), 2)
        repository_mock.assert_has_calls([
            call.get_by_id(Expense, 'id'),
            call.save(expense_mock),
        ])

        expense_mock_calls = expense_mock.mock_calls
        self.assertEqual(len(expense_mock_calls), 1)
        expense_mock.assert_has_calls([call.delete()])

        get_repository_mock_calls = get_repository_mock.mock_calls
        self.assertEqual(len(get_repository_mock_calls), 1)
        get_repository_mock.assert_has_calls([call()])
Beispiel #5
0
    async def test_update_expense(
        self,
        get_repository_mock,
        expense_response_mock,
    ):
        #Arrange
        expense_mock = Mock()
        repository_mock = Mock()
        repository_mock.get_by_id = Mock(return_value=expense_mock)
        get_repository_mock.return_value = repository_mock
        expense_response_mock.from_domain.return_value = 'expense_response'

        #Action
        response = await update_expense('id', 'request')

        #Asserts
        self.assertEqual(response, 'expense_response')
        repository_mock_calls = repository_mock.mock_calls
        self.assertEqual(len(repository_mock_calls), 2)
        repository_mock.assert_has_calls([
            call.get_by_id(Expense, 'id'),
            call.save(expense_mock),
        ])
        expense_mock_calls = expense_mock.mock_calls
        self.assertEqual(len(expense_mock_calls), 1)
        expense_mock.assert_has_calls([call.update('request')])
        expense_response_mock_calls = expense_response_mock.mock_calls
        self.assertEqual(len(expense_response_mock_calls), 1)
        expense_response_mock.assert_has_calls(
            [call.from_domain(expense_mock)])
Beispiel #6
0
    async def test_create_expense_must_receive_a_request_and_return_a_response(
            self, get_repository_mock, expense_response_mock):
        #Arrange
        repository_mock = Mock()
        get_repository_mock.return_value = repository_mock
        request_mock = Mock()
        request_mock.to_domain.return_value = 'expense'
        expense_response_mock.from_domain.return_value = 'expense_response'

        #Action
        response = await create_expense(request_mock)

        #Asserts
        self.assertEqual(response, 'expense_response')
        repository_mock_calls = repository_mock.mock_calls
        self.assertEqual(len(repository_mock_calls), 1)
        repository_mock.assert_has_calls([
            call.save('expense'),
        ])

        request_mock_calls = request_mock.mock_calls
        self.assertEqual(len(request_mock_calls), 1)
        request_mock.assert_has_calls([call.to_domain()])

        expense_response_mock_calls = expense_response_mock.mock_calls
        self.assertEqual(len(expense_response_mock_calls), 1)
        expense_response_mock.assert_has_calls([call.from_domain('expense')])
def should_report_invalid_json(
        validation_results_factory_mock: MagicMock) -> None:
    # Given
    metadata_url = any_s3_url()
    url_reader = MockJSONURLReader({metadata_url: StringIO(initial_value="{")})
    validator = STACDatasetValidator(url_reader,
                                     validation_results_factory_mock)

    # When
    with raises(JSONDecodeError):
        validator.validate(metadata_url)

    # Then
    assert validation_results_factory_mock.mock_calls == [
        call.save(
            metadata_url,
            Check.JSON_PARSE,
            ValidationResult.FAILED,
            details={
                "message":
                "Expecting property name enclosed in double quotes:"
                " line 1 column 2 (char 1)"
            },
        ),
    ]
Beispiel #8
0
def test_option_all_performs_all_analysis(lizard_analysis_mocks):
    """Test that all analysis is performed when the --all option is provided."""

    # arrange
    args = parse_arguments(["/bla/input", "--all"])
    lizard_analysis_mocks.create_report_directory_mock.return_value = "test_reports"

    calls = [
        call.save(os.path.join("test_reports", "function_size_profile.csv")),
        call.save(os.path.join("test_reports", "complexity_profile.csv")),
        call.save(os.path.join("test_reports", "parameters_profile.csv")),
    ]

    # act
    args.func(args)

    # assert
    lizard_analysis_mocks.create_report_directory_mock.assert_called_once()
    lizard_analysis_mocks.measure_function_metrics_mock.assert_called_once()
    lizard_analysis_mocks.determine_profiles_mock.assert_called_once()

    lizard_analysis_mocks.save_profile_mock.has_calls(calls)
    assert lizard_analysis_mocks.show_profile_mock.call_count == 3
    assert lizard_analysis_mocks.print_profile_mock.call_count == 3
 def test_update_existing_entry_before_postprocessors(self):
     entity = MagicMock()
     entity.id = 1
     entity_service = self.run_with_entity(entity)
     self.assertEqual(entity_service.mock_calls, [call.save(entity)])
 def test_save_new_entry_before_postprocessors(self):
     entity = MagicMock()
     entity.id = None
     entity_service = self.run_with_entity(entity)
     self.assertEqual(entity_service.mock_calls,
                      [call.save(ANY), call.save(ANY)])
    def it_adds_a_save_method(utilities, mixed_instance):
        mixed_instance.save()

        expect(utilities.mock_calls) == [call.save(mixed_instance)]
Beispiel #12
0
    def it_adds_a_save_method(utilities, mixed_instance):
        mixed_instance.save()

        expect(utilities.mock_calls) == [
            call.save(mixed_instance)
        ]