def test_command_local_grade_with_extra_args(run_container, utils, common):
    args = argparse.Namespace()
    args.dir = '/tmp'
    args.imageId = 'myimageId'
    args.args = ['extra', 'args']
    common.mk_submission_volume_str.return_value = 'foo'
    docker_mock = MagicMock()
    docker_mock.create_container.return_value = {
        "Id": "myContainerInstanceId",
    }
    docker_mock.inspect_image.return_value = {
        "Config": {
            "Entrypoint": ["command"],
        }
    }
    utils.docker_client.return_value = docker_mock

    grade.command_grade_local(args)

    docker_mock.create_container.assert_called_with(
        image='myimageId',
        entrypoint=['command', 'extra', 'args'],
        user='******',
        host_config=docker.utils.create_host_config(
            binds=['foo', ],
            network_mode='none',
            mem_limit='1g',
            memswap_limit='1g',
        ),
    )
    run_container.assert_called_with(
        docker_mock,
        docker_mock.create_container.return_value,
        args)
Beispiel #2
0
def test_command_local_grade_simple(docker_utils, run_container, utils,
                                    common):
    args = argparse.Namespace()
    args.dir = '/tmp'
    args.imageId = 'myimageId'

    common.mk_submission_volume_str.return_value = 'foo'
    docker_mock = MagicMock()
    docker_mock.create_container.return_value = {
        "Id": "myContainerInstanceId",
    }
    utils.docker_client.return_value = docker_mock

    h_config = {'foo': 'bar'}  # just some unique value
    docker_utils.create_host_config.return_value = h_config

    grade.command_grade_local(args)

    docker_utils.create_host_config.assert_called_with(
        binds=[
            'foo',
        ],
        network_mode='none',
        mem_limit='1g',
        memswap_limit='1g',
    )
    docker_mock.create_container.assert_called_with(
        image='myimageId',
        user='******',
        host_config=h_config,
    )
    run_container.assert_called_with(docker_mock,
                                     docker_mock.create_container.return_value,
                                     args)
Beispiel #3
0
def test_command_local_grade_with_extra_args(run_container, utils, common):
    args = argparse.Namespace()
    args.dir = '/tmp'
    args.imageId = 'myimageId'
    args.args = ['extra', 'args']
    common.mk_submission_volume_str.return_value = 'foo'
    docker_mock = MagicMock()
    docker_mock.create_container.return_value = {
        "Id": "myContainerInstanceId",
    }
    docker_mock.inspect_image.return_value = {
        "Config": {
            "Entrypoint": ["command"],
        }
    }
    utils.docker_client.return_value = docker_mock

    grade.command_grade_local(args)

    docker_mock.create_container.assert_called_with(
        image='myimageId',
        entrypoint=['command', 'extra', 'args'],
        user='******',
        host_config=docker.utils.create_host_config(
            binds=[
                'foo',
            ],
            network_mode='none',
            mem_limit='1g',
            memswap_limit='1g',
        ),
    )
    run_container.assert_called_with(docker_mock,
                                     docker_mock.create_container.return_value,
                                     args)
def test_command_local_grade_simple(run_container, utils, common):
    args = argparse.Namespace()
    args.dir = '/tmp'
    args.containerId = 'myContainerId'
    common.mk_submission_volume_str.return_value = 'foo'
    docker_mock = MagicMock()
    docker_mock.create_container.return_value = {
        "Id": "myContainerInstanceId",
    }
    utils.docker_client.return_value = docker_mock

    grade.command_grade_local(args)

    docker_mock.create_container.assert_called_with(
        image='myContainerId',
        user='******',
        host_config=docker.utils.create_host_config(
            binds=['foo', ],
            network_mode='none',
            mem_limit='1g',
            memswap_limit='1g',
        ),
    )
    run_container.assert_called_with(
        docker_mock,
        docker_mock.create_container.return_value,
        args)