Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for new terminal and editor handling #32

Open
afshin opened this issue Sep 29, 2020 · 0 comments
Open

Add tests for new terminal and editor handling #32

afshin opened this issue Sep 29, 2020 · 0 comments

Comments

@afshin
Copy link
Member

afshin commented Sep 29, 2020

cf. #31

This is a test that was removed from jupyter_server that should be included in nbclassic:

"""Basic tests for the notebook handlers.
"""

import asyncio
import json
import pytest

async def test_terminal_create_with_cwd(
    fetch,
    ws_fetch,
    terminal_path,
    kill_all
):
    resp = await fetch(
        'api', 'terminals',
        method='POST',
        body=json.dumps({'cwd': str(terminal_path)}),
        allow_nonstandard_methods=True,
    )

    data = json.loads(resp.body.decode())
    term_name = data['name']

    ws = await ws_fetch(
        'terminals', 'websocket', term_name
    )
    await ws.write_message(json.dumps(['stdin', 'pwd\r']))

    messages = ""
    while True:
        try:
            response = await asyncio.wait_for(ws.read_message(), timeout=1.0)
        except asyncio.TimeoutError:
            return messages

        response = json.loads(response)
        if response[0] == "stdout":
            messages += response[1]

    ws.close()
    assert str(terminal_path) in messages
    await kill_all()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant