Ejemplo n.º 1
0
def test_failure():
    try:
        with soft_assertions():
            assert_that('foo').is_length(4)
            assert_that('foo').is_empty()
            assert_that('foo').is_false()
            assert_that('foo').is_digit()
            assert_that('123').is_alpha()
            assert_that('foo').is_upper()
            assert_that('FOO').is_lower()
            assert_that('foo').is_equal_to('bar')
            assert_that('foo').is_not_equal_to('foo')
            assert_that('foo').is_equal_to_ignoring_case('BAR')
            assert_that({'a': 1}).has_a(2)
            assert_that({'a': 1}).has_foo(1)
        fail('should have raised error')
    except AssertionError as e:
        out = str(e)
        assert_that(out).contains('Expected <foo> to be of length <4>, but was <3>.')
        assert_that(out).contains('Expected <foo> to be empty string, but was not.')
        assert_that(out).contains('Expected <False>, but was not.')
        assert_that(out).contains('Expected <foo> to contain only digits, but did not.')
        assert_that(out).contains('Expected <123> to contain only alphabetic chars, but did not.')
        assert_that(out).contains('Expected <foo> to contain only uppercase chars, but did not.')
        assert_that(out).contains('Expected <FOO> to contain only lowercase chars, but did not.')
        assert_that(out).contains('Expected <foo> to be equal to <bar>, but was not.')
        assert_that(out).contains('Expected <foo> to be not equal to <foo>, but was.')
        assert_that(out).contains('Expected <foo> to be case-insensitive equal to <BAR>, but was not.')
        assert_that(out).contains('Expected <1> to be equal to <2> on key <a>, but was not.')
        assert_that(out).contains('Expected key <foo>, but val has no key <foo>.')
Ejemplo n.º 2
0
 def test_soft_assertions(self):
     try:
         with soft_assertions():
             assert_that('foo').is_length(4)
             assert_that('foo').is_empty()
             assert_that('foo').is_false()
             assert_that('foo').is_digit()
             assert_that('123').is_alpha()
             assert_that('foo').is_upper()
             assert_that('FOO').is_lower()
             assert_that('foo').is_equal_to('bar')
             assert_that('foo').is_not_equal_to('foo')
             assert_that('foo').is_equal_to_ignoring_case('BAR')
         fail('should have raised error')
     except AssertionError as e:
         assert_that(str(e)).contains('1. Expected <foo> to be of length <4>, but was <3>.')
         assert_that(str(e)).contains('2. Expected <foo> to be empty string, but was not.')
         assert_that(str(e)).contains('3. Expected <False>, but was not.')
         assert_that(str(e)).contains('4. Expected <foo> to contain only digits, but did not.')
         assert_that(str(e)).contains('5. Expected <123> to contain only alphabetic chars, but did not.')
         assert_that(str(e)).contains('6. Expected <foo> to contain only uppercase chars, but did not.')
         assert_that(str(e)).contains('7. Expected <FOO> to contain only lowercase chars, but did not.')
         assert_that(str(e)).contains('8. Expected <foo> to be equal to <bar>, but was not.')
         assert_that(str(e)).contains('9. Expected <foo> to be not equal to <foo>, but was.')
         assert_that(str(e)).contains('10. Expected <foo> to be case-insensitive equal to <BAR>, but was not.')
Ejemplo n.º 3
0
def test_fail_with_msg():
    try:
        with soft_assertions():
            fail('foobar')
        fail('should have raised error')
    except AssertionError as e:
        out = str(e)
        assert_that(out).is_equal_to('Fail: foobar!')
def test_soft_fail_with_msg():
    try:
        with soft_assertions():
            soft_fail('foobar')
        fail('should have raised error')
    except AssertionError as e:
        out = str(e)
        assert_that(out).contains('Fail: foobar!')
        assert_that(out).does_not_contain('should have raised error')
Ejemplo n.º 5
0
def test_expected_exception_failure():
    try:
        with soft_assertions():
            assert_that(func_err).raises(RuntimeError).when_called_with('foo').is_equal_to('bar')
            assert_that(func_ok).raises(RuntimeError).when_called_with('baz')
        fail('should have raised error')
    except AssertionError as e:
        out = str(e)
        assert_that(out).contains('Expected <err> to be equal to <bar>, but was not.')
        assert_that(out).contains("Expected <func_ok> to raise <RuntimeError> when called with ('baz').")
Ejemplo n.º 6
0
def test_double_soft_fail():
    try:
        with soft_assertions():
            soft_fail()
            soft_fail('foobar')
        fail('should have raised error')
    except AssertionError as e:
        out = str(e)
        assert_that(out).contains('Fail!')
        assert_that(out).contains('Fail: foobar!')
        assert_that(out).does_not_contain('should have raised error')
Ejemplo n.º 7
0
    def test_describe_of_image_already_available(self, client, mocker):
        mocker.patch(
            "pcluster.aws.ec2.Ec2Client.describe_image_by_id_tag",
            return_value=_create_image_info("image1"),
        )
        mocker.patch("pcluster.aws.cfn.CfnClient.describe_stack_resource",
                     return_value=None)
        mocker.patch(
            "pcluster.api.controllers.image_operations_controller._presigned_config_url",
            return_value="https://parallelcluster.aws.com/bucket/key",
        )

        expected_response = {
            "creationTime": to_iso_timestr(datetime(2021, 4, 12)),
            "ec2AmiInfo": {
                "amiId":
                "image1",
                "amiName":
                "image1",
                "architecture":
                "x86_64",
                "state":
                Ec2AmiState.AVAILABLE,
                "description":
                "description",
                "tags": [
                    {
                        "key": "parallelcluster:image_id",
                        "value": "image1"
                    },
                    {
                        "key": "parallelcluster:version",
                        "value": "3.0.0"
                    },
                    {
                        "key": "parallelcluster:build_config",
                        "value": "s3://bucket/key"
                    },
                ],
            },
            "imageBuildStatus": ImageBuildStatus.BUILD_COMPLETE,
            "imageConfiguration": {
                "url": "https://parallelcluster.aws.com/bucket/key"
            },
            "imageId": "image1",
            "region": "us-east-1",
            "version": "3.0.0",
        }

        response = self._send_test_request(client, "image1")

        with soft_assertions():
            assert_that(response.status_code).is_equal_to(200)
            assert_that(response.get_json()).is_equal_to(expected_response)
Ejemplo n.º 8
0
    def test_ingest_path_dict(self, mock_params: List[Dict[str, Any]]):
        for param in mock_params:
            spb = SignatureParameterBuilder(params=param)

            with soft_assertions():
                members = [
                    spb.name, spb.required, spb.param_in, spb.param_type
                ]
                for member in members:
                    assert_that(member).is_not_none()
                    assert_that(spb.param_format).is_none()
                    assert_that(spb.name).does_not_contain("-")
Ejemplo n.º 9
0
def test_success():
    with soft_assertions():
        assert_that('foo').is_length(3)
        assert_that('foo').is_not_empty()
        assert_that('foo').is_true()
        assert_that('foo').is_alpha()
        assert_that('123').is_digit()
        assert_that('foo').is_lower()
        assert_that('FOO').is_upper()
        assert_that('foo').is_equal_to('foo')
        assert_that('foo').is_not_equal_to('bar')
        assert_that('foo').is_equal_to_ignoring_case('FOO')
def test_get_a_single_post(service_obj):
    # requesting a random post no in each test run
    requested_post_id = random.randint(1, 100)
    res = service_obj.get_post_with_id(requested_post_id)

    with soft_assertions():
        assert_that(
            res.status_code).described_as('Response code').is_equal_to(200)
        assert_that(
            res.json()).described_as('Response').contains_only(*post_keys)
        assert_that(res.json()).described_as('Id in response').has_id(
            requested_post_id)
Ejemplo n.º 11
0
def step_impl(context):
    context.identifier = context.project_request.project.identifier
    with soft_assertions():
        assert context.project_request.status_code == Constants.StatusCode.CREATED.value
        project_request = ApiRequests.get_project_by_id(context.project_request.project.id)
        project = project_request.project
        assert_that(project).has_id(context.project_request.project.id)
        assert_that(project).has_name(context.project_request.project.name)
        assert_that(project).has_identifier(context.project_request.project.identifier)
        assert_that(project).has_description(context.project_request.project.description)
        assert_that(project).has_is_public(context.project_request.project.is_public)
        assert_that(project).has_home_page(context.project_request.project.home_page)
Ejemplo n.º 12
0
def test_success():
    with soft_assertions():
        assert_that('foo').is_length(3)
        assert_that('foo').is_not_empty()
        assert_that('foo').is_true()
        assert_that('foo').is_alpha()
        assert_that('123').is_digit()
        assert_that('foo').is_lower()
        assert_that('FOO').is_upper()
        assert_that('foo').is_equal_to('foo')
        assert_that('foo').is_not_equal_to('bar')
        assert_that('foo').is_equal_to_ignoring_case('FOO')
    def test_that_other_errors_are_converted(self, client, mocker):
        image = _create_image_info("image1")
        mocker.patch("pcluster.aws.ec2.Ec2Client.describe_image_by_id_tag",
                     return_value=image)
        mocker.patch("pcluster.models.imagebuilder.ImageBuilder.delete",
                     side_effect=Exception("test error"))
        expected_error = {"message": "test error"}
        response = self._send_test_request(client, "image1")

        with soft_assertions():
            assert_that(response.status_code).is_equal_to(500)
            assert_that(response.get_json()).is_equal_to(expected_error)
Ejemplo n.º 14
0
def test_gsfCopyRecords_success(gsf_test_data_03_06):
    """
    Open the test GSF file, read a record, then copy the contents to
    a new gsfRecords structure.
    """
    # Arrange
    file_handle = c_int(0)
    data_id = c_gsfDataID()
    source_records = c_gsfRecords()
    target_records = c_gsfRecords()

    # Act
    return_value = gsfpy.bindings.gsfOpen(
        os.fsencode(str(gsf_test_data_03_06.path)),
        FileMode.GSF_READONLY,
        byref(file_handle),
    )
    assert_that(return_value).is_zero()

    bytes_read = gsfpy.bindings.gsfRead(
        file_handle,
        RecordType.GSF_RECORD_COMMENT,
        byref(data_id),
        byref(source_records),
    )
    assert_that(bytes_read).is_equal_to(156)

    return_value = gsfpy.bindings.gsfCopyRecords(
        pointer(target_records), pointer(source_records)
    )
    assert_that(return_value).is_zero()

    return_value = gsfpy.bindings.gsfClose(file_handle)
    assert_that(return_value).is_zero()

    # Assert
    with soft_assertions():
        assert_that(target_records.comment.comment_time.tv_sec).is_equal_to(
            source_records.comment.comment_time.tv_sec
        )
        assert_that(target_records.comment.comment_time.tv_nsec).is_equal_to(
            source_records.comment.comment_time.tv_nsec
        )
        assert_that(target_records.comment.comment_length).is_equal_to(
            source_records.comment.comment_length
        )
        assert_that(addressof(target_records.comment.comment)).is_not_equal_to(
            addressof(source_records.comment.comment)
        )
        assert_that(string_at(target_records.comment.comment)).is_equal_to(
            string_at(source_records.comment.comment)
        )
 def test_unknown_status_on_unstable_stack(self, mocker, client, scheduler,
                                           stack_status):
     """When stack is in unstable status, the status should be UNKNOWN."""
     mocker.patch(
         "pcluster.aws.cfn.CfnClient.describe_stack",
         return_value=cfn_describe_stack_mock_response(
             scheduler, stack_status),
     )
     response = self._send_test_request(client)
     with soft_assertions():
         assert_that(response.status_code).is_equal_to(200)
         expected_response = {"status": "UNKNOWN"}
         assert_that(response.get_json()).is_equal_to(expected_response)
Ejemplo n.º 16
0
def check_projects(response):
    r_json = response.json()
    projects = r_json.get('projects')
    with soft_assertions():
        assert_that(len(projects)).is_less_than_or_equal_to(25)
        for project in projects:
            assert_that(project.get('id')).described_as('id').is_not_none().is_type_of(int)
            assert_that(project.get('name')).described_as('name').is_not_none().is_type_of(str)
            assert_that(project.get('identifier')).described_as('identifier').is_not_none().is_type_of(str)
            if project.get('description', False):
                assert_that(project.get('description')).described_as('description').is_not_none().is_type_of(str)
            assert_that(project.get('status')).described_as('status').is_not_none().is_type_of(int)
            assert_that(project.get('is_public')).described_as('is_public').is_not_none().is_type_of(bool)
 def test_bad_request_on_unstable_stack(self, mocker, client, stack_status,
                                        scheduler, request_body,
                                        expected_response):
     mocker.patch(
         "pcluster.aws.cfn.CfnClient.describe_stack",
         return_value=cfn_describe_stack_mock_response(
             scheduler, stack_status),
     )
     config_mock = mocker.patch("pcluster.models.cluster.Cluster.config")
     config_mock.scheduling.scheduler = scheduler
     response = self._send_test_request(client, request_body=request_body)
     with soft_assertions():
         assert_that(response.status_code).is_equal_to(400)
         assert_that(response.get_json()).is_equal_to(expected_response)
 def test_stack_not_exist_request(self, mocker, client):
     mocker.patch(
         "pcluster.aws.cfn.CfnClient.describe_stack",
         side_effect=StackNotFoundError(function_name="describestack",
                                        stack_name="stack_name"),
     )
     response = self._send_test_request(client)
     with soft_assertions():
         assert_that(response.status_code).is_equal_to(404)
         assert_that(response.get_json()).is_equal_to({
             "message":
             "Cluster 'clustername' does not exist or belongs to an "
             "incompatible ParallelCluster major version."
         })
Ejemplo n.º 19
0
def assert_result(case_name, *args):
    # 判断是否传入step_name
    if len(args) > 0:
        case_data = get_case_data(case_name, args[0])
    else:
        case_data = get_case_data(case_name)
    actual_result = case_data['actual_result']
    expected_result = case_data['expected_result']
    # 判断是否需要断言
    if len(expected_result) == 0:
        pass
    else:
        with soft_assertions():
            assert_that(actual_result).contains_entry(expected_result)
Ejemplo n.º 20
0
def test_expected_exception_failure():
    try:
        with soft_assertions():
            assert_that(func_err).raises(RuntimeError).when_called_with(
                'foo').is_equal_to('bar')
            assert_that(func_ok).raises(RuntimeError).when_called_with('baz')
        fail('should have raised error')
    except AssertionError as e:
        out = str(e)
        assert_that(out).contains(
            'Expected <err> to be equal to <bar>, but was not.')
        assert_that(out).contains(
            "Expected <func_ok> to raise <RuntimeError> when called with ('baz')."
        )
Ejemplo n.º 21
0
def test_nested():
    try:
        with soft_assertions():
            assert_that('a').is_equal_to('A')
            with soft_assertions():
                assert_that('b').is_equal_to('B')
                with soft_assertions():
                    assert_that('c').is_equal_to('C')
                assert_that('b').is_equal_to('B2')
            assert_that('a').is_equal_to('A2')
        fail('should have raised error')
    except AssertionError as e:
        out = str(e)
        assert_that(out).contains(
            '1. Expected <a> to be equal to <A>, but was not.')
        assert_that(out).contains(
            '2. Expected <b> to be equal to <B>, but was not.')
        assert_that(out).contains(
            '3. Expected <c> to be equal to <C>, but was not.')
        assert_that(out).contains(
            '4. Expected <b> to be equal to <B2>, but was not.')
        assert_that(out).contains(
            '5. Expected <a> to be equal to <A2>, but was not.')
Ejemplo n.º 22
0
def test_config_object_initialization(config, expected_result,
                                      expected_error_message):
    if expected_error_message:
        with pytest.raises(BadRequest, match=expected_error_message):
            _ = ImageBuilder(config=config).config
    elif config is None:
        result = ImageBuilder(config=config).config
        assert_that(result).is_none()
    else:
        result = ImageBuilder(config=config).config
        with soft_assertions():
            assert_that(result.build.instance_type).is_equal_to(
                expected_result.build.instance_type)
            assert_that(result.build.parent_image).is_equal_to(
                expected_result.build.parent_image)
Ejemplo n.º 23
0
    def test_read_swagger(self, download_test_swagger):
        parsed_swagger = read_swagger(
            package=config, signature_parser_builder=SignatureParameterBuilder)

        with soft_assertions():
            for sp in parsed_swagger:
                assert_that(sp).is_not_empty()
                assert_that(sp).is_type_of(ParsedSwagger)
                assert_that(sp.path).is_not_none()
                assert_that(sp.signature).is_type_of(str)
                assert_that(sp.signature).is_not_none()

                if sp.sort:
                    assert_that(sp.sort).is_type_of(tuple)
                    assert_that(sp.sort).is_not_empty()
Ejemplo n.º 24
0
def test_gsfInitializeMBParams_success(gsf_test_data_03_06):
    """
    Create a gsfMBParams structure and initialize all fields.
    """
    # Arrange
    mbparams = c_gsfMBParams()

    # Act
    gsfpy.bindings.gsfInitializeMBParams(byref(mbparams))

    # Assert two of the fields here to check they are set to the unknown
    # value.
    with soft_assertions():
        assert_that(mbparams.horizontal_datum).is_equal_to(-99)
        assert_that(mbparams.vessel_type).is_equal_to(-99)
 def test_successful_request(self, mocker, client, instances, params,
                             next_token):
     describe_instances_response = []
     for instance in instances:
         describe_instances_response.append(
             cfn_describe_instances_mock_response(**instance))
     expected_response = describe_cluster_instances_mock_response(instances)
     if next_token:
         expected_response["nextToken"] = next_token
     mocker.patch("pcluster.aws.ec2.Ec2Client.describe_instances",
                  return_value=(describe_instances_response, next_token))
     response = self._send_test_request(client, **params)
     with soft_assertions():
         assert_that(response.status_code).is_equal_to(200)
         assert_that(response.get_json()).is_equal_to(expected_response)
    def test_that_errors_are_converted(self, client, mocker, error,
                                       status_code):
        mocker.patch("pcluster.aws.ec2.Ec2Client.get_images",
                     side_effect=error(function_name="get_images",
                                       message="test error"))
        expected_error = {"message": "test error"}
        if error == BadRequestError:
            expected_error[
                "message"] = "Bad Request: " + expected_error["message"]
        response = self._send_test_request(
            client, ImageStatusFilteringOption.AVAILABLE)

        with soft_assertions():
            assert_that(response.status_code).is_equal_to(status_code)
            assert_that(response.get_json()).is_equal_to(expected_error)
    def test_dryrun(self, client, mocker, validation_errors, error_code,
                    expected_response):
        if validation_errors:
            mocker.patch(
                "pcluster.models.imagebuilder.ImageBuilder.validate_create_request",
                side_effect=validation_errors)
        else:
            mocker.patch(
                "pcluster.models.imagebuilder.ImageBuilder.validate_create_request",
                return_value=None)

        response = self._send_test_request(client, dryrun=True)

        with soft_assertions():
            assert_that(response.status_code).is_equal_to(error_code)
            assert_that(response.get_json()).is_equal_to(expected_response)
Ejemplo n.º 28
0
def test_failure_chain():
    try:
        with soft_assertions():
            assert_that('foo').is_length(4).is_empty().is_false().is_digit().is_upper()\
                .is_equal_to('bar').is_not_equal_to('foo').is_equal_to_ignoring_case('BAR')
        fail('should have raised error')
    except AssertionError as e:
        out = str(e)
        assert_that(out).contains('Expected <foo> to be of length <4>, but was <3>.')
        assert_that(out).contains('Expected <foo> to be empty string, but was not.')
        assert_that(out).contains('Expected <False>, but was not.')
        assert_that(out).contains('Expected <foo> to contain only digits, but did not.')
        assert_that(out).contains('Expected <foo> to contain only uppercase chars, but did not.')
        assert_that(out).contains('Expected <foo> to be equal to <bar>, but was not.')
        assert_that(out).contains('Expected <foo> to be not equal to <foo>, but was.')
        assert_that(out).contains('Expected <foo> to be case-insensitive equal to <BAR>, but was not.')
Ejemplo n.º 29
0
 def test_last_level_doesnt_reset_progress(self):
     game = start_game()
     game["Game"].load_level(5)
     game["Player"].move_to_object(game["Level"].exit, offset=-2)
     time.sleep(1.5)  # слишком быстро проходит и не видно результата :)
     game["LevelCompleteMenu"].avoid_close_me_menu()
     game["LevelCompleteMenu"].next_button.tap()
     time.sleep(1.5)  # см. выше
     game["Unity"].stop()
     game["Appium"].quit()
     time.sleep(3)
     new_game = start_game()
     with soft_assertions():
         assert_that(new_game["Level"].level_name).contains("Map5")
         new_game["Unity"].stop()
         new_game["Appium"].quit()
Ejemplo n.º 30
0
def test_fail_with_soft_failing_asserts():
    try:
        with soft_assertions():
            assert_that('foo').is_length(4)
            assert_that('foo').is_empty()
            fail('foobar')
            assert_that('foo').is_not_equal_to('foo')
            assert_that('foo').is_equal_to_ignoring_case('BAR')
        fail('should have raised error')
    except AssertionError as e:
        out = str(e)
        assert_that(out).is_equal_to('Fail: foobar!')
        assert_that(out).does_not_contain('Expected <foo> to be of length <4>, but was <3>.')
        assert_that(out).does_not_contain('Expected <foo> to be empty string, but was not.')
        assert_that(out).does_not_contain('Expected <foo> to be not equal to <foo>, but was.')
        assert_that(out).does_not_contain('Expected <foo> to be case-insensitive equal to <BAR>, but was not.')
Ejemplo n.º 31
0
def test_gsfSetDefaultScaleFactor_success(gsf_test_data_03_06):
    """
    Set estimated scale factors for a gsfSwathBathyPing structure.
    """
    # Arrange
    file_handle = c_int(0)
    records = c_gsfRecords()
    data_id = c_gsfDataID()

    # Act
    return_value = gsfpy.bindings.gsfOpen(
        os.fsencode(str(gsf_test_data_03_06.path)),
        FileMode.GSF_READONLY,
        byref(file_handle),
    )
    assert_that(return_value).is_zero()

    bytes_read = gsfpy.bindings.gsfRead(
        file_handle,
        RecordType.GSF_RECORD_SWATH_BATHYMETRY_PING,
        byref(data_id),
        byref(records),
    )
    assert_that(bytes_read).is_equal_to(6116)

    # Set multibeam ping scale factors to be empty
    records.mb_ping.scaleFactors = c_gsfScaleFactors()

    return_value = gsfpy.bindings.gsfSetDefaultScaleFactor(byref(records.mb_ping))
    assert_that(return_value).is_zero()

    return_value = gsfpy.bindings.gsfClose(file_handle)
    assert_that(return_value).is_zero()

    # Assert
    with soft_assertions():
        index = 2
        assert_that(
            records.mb_ping.scaleFactors.scaleTable[index].compressionFlag
        ).is_equal_to(0x00)
        assert_that(
            records.mb_ping.scaleFactors.scaleTable[index].multiplier
        ).is_equal_to(25)
        assert_that(records.mb_ping.scaleFactors.scaleTable[index].offset).is_equal_to(
            0
        )
    def test_delete_image_with_no_available_image_or_stack_throws_not_found_exception(
            self, mocker, client):
        mocker.patch(
            "pcluster.aws.ec2.Ec2Client.describe_image_by_id_tag",
            side_effect=ImageNotFoundError("describe_image_by_id_tag"),
        )
        mocker.patch("pcluster.aws.cfn.CfnClient.describe_stack",
                     side_effect=StackNotFoundError("describe_stack",
                                                    "stack_name"))
        response = self._send_test_request(client, "nonExistentImage")

        with soft_assertions():
            assert_that(response.status_code).is_equal_to(404)
            assert_that(response.get_json()).is_equal_to({
                "message":
                "No image or stack associated with ParallelCluster image id: nonExistentImage."
            })
def test_soft_fail_with_soft_failing_asserts():
    try:
        with soft_assertions():
            assert_that('foo').is_length(4)
            assert_that('foo').is_empty()
            soft_fail('foobar')
            assert_that('foo').is_not_equal_to('foo')
            assert_that('foo').is_equal_to_ignoring_case('BAR')
        fail('should have raised error')
    except AssertionError as e:
        out = str(e)
        assert_that(out).contains('Expected <foo> to be of length <4>, but was <3>.')
        assert_that(out).contains('Expected <foo> to be empty string, but was not.')
        assert_that(out).contains('Fail: foobar!')
        assert_that(out).contains('Expected <foo> to be not equal to <foo>, but was.')
        assert_that(out).contains('Expected <foo> to be case-insensitive equal to <BAR>, but was not.')
        assert_that(out).does_not_contain('should have raised error')
Ejemplo n.º 34
0
def test_gsfGetScaleFactor_success(gsf_test_data_03_06):
    """
    Read a GSF record and get the beam array field size, compression flag,
    multiplier and DC offset applied to it.
    """
    # Arrange
    file_handle = c_int(0)
    records = c_gsfRecords()
    data_id = c_gsfDataID()
    subrecord_id = (
        ScaledSwathBathySubRecord.GSF_SWATH_BATHY_SUBRECORD_MEAN_CAL_AMPLITUDE_ARRAY
    )

    c_flag = c_ubyte()
    multiplier = c_double()
    offset = c_double()

    # Act
    return_value = gsfpy.bindings.gsfOpen(
        os.fsencode(str(gsf_test_data_03_06.path)),
        FileMode.GSF_READONLY,
        byref(file_handle),
    )
    assert_that(return_value).is_zero()

    bytes_read = gsfpy.bindings.gsfRead(
        file_handle,
        RecordType.GSF_RECORD_SWATH_BATHYMETRY_PING,
        byref(data_id),
        byref(records),
    )
    assert_that(bytes_read).is_equal_to(6116)

    return_value = gsfpy.bindings.gsfGetScaleFactor(
        file_handle, subrecord_id, byref(c_flag), byref(multiplier), byref(offset)
    )
    assert_that(return_value).is_zero()

    return_value = gsfpy.bindings.gsfClose(file_handle)
    assert_that(return_value).is_zero()

    # Assert
    with soft_assertions():
        assert_that(c_flag.value).is_equal_to(0)
        assert_that(multiplier.value).is_equal_to(2)
        assert_that(offset.value).is_equal_to(0)
 def test_slurm_dynamo_table_not_exist(self, mocker, client):
     """When stack exists but the dynamodb table to store the status does not exist, the status should be UNKNOWN."""
     mocker.patch("pcluster.aws.cfn.CfnClient.describe_stack",
                  return_value=cfn_describe_stack_mock_response("slurm"))
     mocker.patch(
         "pcluster.aws.dynamo.DynamoResource.get_item",
         side_effect=AWSClientError(
             function_name="get_item",
             message="An error occurred (ResourceNotFoundException) when"
             " calling the GetItem operation: Requested resource not found",
         ),
     )
     response = self._send_test_request(client)
     with soft_assertions():
         assert_that(response.status_code).is_equal_to(200)
         expected_response = {"status": "UNKNOWN"}
         assert_that(response.get_json()).is_equal_to(expected_response)
    def test_delete_using_shared_image(self, client, mocker, instance_using,
                                       image_is_shared, expected_response):
        image = _create_image_info("image1")
        mocker.patch("pcluster.aws.ec2.Ec2Client.describe_image_by_id_tag",
                     return_value=image)
        instances = ["id1"] if instance_using else []
        mocker.patch("pcluster.aws.ec2.Ec2Client.get_instance_ids_by_ami_id",
                     return_value=instances)
        accounts = ["acct_1"] if image_is_shared else []
        mocker.patch("pcluster.aws.ec2.Ec2Client.get_image_shared_account_ids",
                     return_value=accounts)

        response = self._send_test_request(client, "image1", force=False)
        with soft_assertions():
            assert_that(response.status_code).is_equal_to(400)
            assert_that(response.get_json()).contains("message")
            assert_that(
                response.get_json()["message"]).matches(expected_response)
 def test_successful_request(self, mocker, client, stack_exists, force):
     if stack_exists:
         mocker.patch("pcluster.aws.cfn.CfnClient.describe_stack",
                      return_value=cfn_describe_stack_mock_response())
     else:
         mocker.patch(
             "pcluster.aws.cfn.CfnClient.describe_stack",
             side_effect=StackNotFoundError(function_name="describestack",
                                            stack_name="stack_name"),
         )
     instance_ids = ["fakeinstanceid1", "fakeinstanceid2"]
     mocker.patch("pcluster.aws.ec2.Ec2Client.list_instance_ids",
                  return_value=instance_ids)
     terminate_instance_mock = mocker.patch(
         "pcluster.aws.ec2.Ec2Client.terminate_instances")
     response = self._send_test_request(client, force=force)
     with soft_assertions():
         assert_that(response.status_code).is_equal_to(202)
         terminate_instance_mock.assert_called_with(tuple(instance_ids))
def test_list_of_dictionaries_does_not_duplicate_by_some_key_value():
    """

    1. create new dict with global keys by some key value which could repeat in list of dictionaries
    and append to this key a list of dictionaries, where this value figure
    2.  assert that dictionaries does not duplicate by some key's value

    """

    new_some_view = defaultdict(list)

    for some in SOMETHING:
        new_some_view[some['key']].append(some['id'])

    with soft_assertions():
        for key in new_some_view:
            assert_that(len(new_some_view[key])).described_as(
                f'key "{key}"" has duplicates "{new_some_view[key]}"'
            ).is_less_than_or_equal_to(1)
Ejemplo n.º 39
0
def test_expected_exception_success():
    with soft_assertions():
        assert_that(func_err).raises(RuntimeError).when_called_with('foo').is_equal_to('err')