How to use ai2thor - 10 common examples

To help you get started, we’ve selected a few ai2thor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github allenai / ai2thor / tests / test_server.py View on Github external
def test_client_token_mismatch():
    request_queue = Queue(maxsize=1)
    response_queue = Queue(maxsize=1)

    response_queue.put_nowait(dict(action='RotateRight'))

    s = ai2thor.server.Server(request_queue, response_queue, '127.0.0.1')
    s.client_token = '123456'
    c = s.app.test_client()

    res = c.post(
        '/train', 
        buffered=True,
        content_type='multipart/form-data; boundary=OVCo05I3SVXLPeTvCgJjHl1EOleL4u9TDx5raRVt',
        input_stream=BytesIO(generate_form(metadata_simple, s.sequence_id + 1)))
    assert res.status_code == 403
github allenai / ai2thor / tests / test_server.py View on Github external
def test_train_numpy_action():
    request_queue = Queue(maxsize=1)
    response_queue = Queue(maxsize=1)

    response_queue.put_nowait(dict(
        action='Teleport', 
        rotation=dict(y=np.array([24])[0]),
        moveMagnitude=np.array([55.5])[0],
    ))

    s = ai2thor.server.Server(request_queue, response_queue, '127.0.0.1')
    c = s.app.test_client()
    res = c.post(
        '/train', 
        buffered=True,
        content_type='multipart/form-data; boundary=OVCo05I3SVXLPeTvCgJjHl1EOleL4u9TDx5raRVt',
        input_stream=BytesIO(generate_form(metadata_simple, s.sequence_id)))
    j = json.loads(res.get_data())
github allenai / ai2thor / tests / test_server.py View on Github external
def test_non_multipart():
    request_queue = Queue(maxsize=1)
    response_queue = Queue(maxsize=1)

    response_queue.put_nowait(dict(action='RotateRight'))

    s = ai2thor.server.Server(request_queue, response_queue, '127.0.0.1')
    c = s.app.test_client()
    s.client_token = '1234567'

    m = dict(agents=[metadata_simple], sequenceId=s.sequence_id)
    res = c.post(
        '/train', 
        data=dict(metadata=json.dumps(m), token=s.client_token))
    assert res.status_code == 200
github allenai / ai2thor / tests / test_server.py View on Github external
def test_sequence_id_mismatch():
    request_queue = Queue(maxsize=1)
    response_queue = Queue(maxsize=1)

    response_queue.put_nowait(dict(action='RotateRight'))

    s = ai2thor.server.Server(request_queue, response_queue, '127.0.0.1')
    c = s.app.test_client()

    res = c.post(
        '/train', 
        buffered=True,
        content_type='multipart/form-data; boundary=OVCo05I3SVXLPeTvCgJjHl1EOleL4u9TDx5raRVt',
        input_stream=BytesIO(generate_form(metadata_simple, s.sequence_id + 1)))
    assert res.status_code == 500
github allenai / ai2thor / tests / test_server.py View on Github external
def test_client_token_mismatch():
    request_queue = Queue(maxsize=1)
    response_queue = Queue(maxsize=1)

    response_queue.put_nowait(dict(action='RotateRight'))

    s = ai2thor.server.Server(request_queue, response_queue, '127.0.0.1')
    s.client_token = '123456'
    c = s.app.test_client()

    res = c.post(
        '/train', 
        buffered=True,
        content_type='multipart/form-data; boundary=OVCo05I3SVXLPeTvCgJjHl1EOleL4u9TDx5raRVt',
        input_stream=BytesIO(generate_form(metadata_simple, s.sequence_id + 1)))
    assert res.status_code == 403
github allenai / ai2thor / tests / test_server.py View on Github external
def test_multi_agent_train():
    request_queue = Queue(maxsize=1)
    response_queue = Queue(maxsize=1)

    response_queue.put_nowait(dict(action='RotateRight'))

    s = ai2thor.server.Server(request_queue, response_queue, '127.0.0.1')
    c = s.app.test_client()
    res = c.post(
        '/train', 
        buffered=True,
        content_type='multipart/form-data; boundary=OVCo05I3SVXLPeTvCgJjHl1EOleL4u9TDx5raRVt',
        input_stream=BytesIO(generate_multi_agent_form(metadata_simple, s.sequence_id)))
    assert res.status_code == 200
github allenai / ai2thor / tests / test_server.py View on Github external
def test_non_multipart():
    request_queue = Queue(maxsize=1)
    response_queue = Queue(maxsize=1)

    response_queue.put_nowait(dict(action='RotateRight'))

    s = ai2thor.server.Server(request_queue, response_queue, '127.0.0.1')
    c = s.app.test_client()
    s.client_token = '1234567'

    m = dict(agents=[metadata_simple], sequenceId=s.sequence_id)
    res = c.post(
        '/train', 
        data=dict(metadata=json.dumps(m), token=s.client_token))
    assert res.status_code == 200
github allenai / ai2thor / tests / test_server.py View on Github external
def test_train_numpy_action():
    request_queue = Queue(maxsize=1)
    response_queue = Queue(maxsize=1)

    response_queue.put_nowait(dict(
        action='Teleport', 
        rotation=dict(y=np.array([24])[0]),
        moveMagnitude=np.array([55.5])[0],
    ))

    s = ai2thor.server.Server(request_queue, response_queue, '127.0.0.1')
    c = s.app.test_client()
    res = c.post(
        '/train', 
        buffered=True,
        content_type='multipart/form-data; boundary=OVCo05I3SVXLPeTvCgJjHl1EOleL4u9TDx5raRVt',
        input_stream=BytesIO(generate_form(metadata_simple, s.sequence_id)))
    j = json.loads(res.get_data())
    assert j == {'action': 'Teleport', 'rotation': {'y': 24}, 'sequenceId': 1, 'moveMagnitude': 55.5}
github allenai / ai2thor / tests / test_server.py View on Github external
def test_multi_agent_train():
    request_queue = Queue(maxsize=1)
    response_queue = Queue(maxsize=1)

    response_queue.put_nowait(dict(action='RotateRight'))

    s = ai2thor.server.Server(request_queue, response_queue, '127.0.0.1')
    c = s.app.test_client()
    res = c.post(
        '/train', 
        buffered=True,
        content_type='multipart/form-data; boundary=OVCo05I3SVXLPeTvCgJjHl1EOleL4u9TDx5raRVt',
        input_stream=BytesIO(generate_multi_agent_form(metadata_simple, s.sequence_id)))
    assert res.status_code == 200
github allenai / ai2thor / tests / test_server.py View on Github external
def test_non_multipart():
    request_queue = Queue(maxsize=1)
    response_queue = Queue(maxsize=1)

    response_queue.put_nowait(dict(action='RotateRight'))

    s = ai2thor.server.Server(request_queue, response_queue, '127.0.0.1')
    c = s.app.test_client()
    s.client_token = '1234567'

    m = dict(agents=[metadata_simple], sequenceId=s.sequence_id)
    res = c.post(
        '/train', 
        data=dict(metadata=json.dumps(m), token=s.client_token))
    assert res.status_code == 200