def test_hosting_py_version(docker_image, py_version, opt_ml, processor):
    resource_path = 'test/resources/py_version'
    utils.copy_resource(resource_path, opt_ml, 'code')

    input = json.dumps(_py_version_dict(py_version))

    with docker_utils.HostingContainer(image=docker_image,
                                       processor=processor,
                                       opt_ml=opt_ml,
                                       script_name='usermodule.py') as c:
        c.ping()
        # We send the json of the expect py versions in the request. The usermodule.py transform_fn will assert on the python versions,
        # and this request will fail and throw an exception if they are incorrect.
        c.invoke_endpoint(input)
def test_hosting(docker_image, opt_ml, processor):
    resource_path = 'test/resources/dummy_hosting'
    utils.copy_resource(resource_path, opt_ml, 'code')

    input = json.dumps({'some': 'json'})

    with docker_utils.HostingContainer(
            image=docker_image,
            processor=processor,
            opt_ml=opt_ml,
            script_name='dummy_hosting_module.py') as c:
        c.ping()
        output = c.invoke_endpoint(input)
        assert input == output
def test_default_model_fn(docker_image, opt_ml, processor):
    resource_path = 'test/resources/default_handlers'
    for path in ['code', 'model']:
        utils.copy_resource(resource_path, opt_ml, path)

    input = [[1, 2]]

    with docker_utils.HostingContainer(image=docker_image,
                                       processor=processor,
                                       opt_ml=opt_ml,
                                       script_name='empty_module.py') as c:
        c.ping()
        output = c.invoke_endpoint(input)
        assert '[[4.9999918937683105]]' == output
def test_gluon_hosting(docker_image, opt_ml, processor):
    resource_path = 'test/resources/gluon_hosting'
    for path in ['code', 'model']:
        utils.copy_resource(resource_path, opt_ml, path)

    with open('test/resources/mnist_images/04.json', 'r') as f:
        input = json.load(f)

    with docker_utils.HostingContainer(image=docker_image,
                                       processor=processor,
                                       opt_ml=opt_ml,
                                       script_name='gluon.py') as c:
        c.ping()
        output = c.invoke_endpoint(input)
        assert '[4.0]' == output