Skip to content

Commit

Permalink
Add a test for loadExampleScript
Browse files Browse the repository at this point in the history
  • Loading branch information
TaiSakuma committed May 9, 2024
1 parent d4da8d3 commit 382623e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions nextlinegraphql/plugins/ctrl/graphql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
MUTATE_RESET = (sub / 'Reset.gql').read_text()
MUTATE_SEND_PDB_COMMAND = (sub / 'SendPdbCommand.gql').read_text()
MUTATE_RUN_AND_CONTINUE = (sub / 'RunAndContinue.gql').read_text()
MUTATE_LOAD_EXAMPLE_SCRIPT = (sub / 'LoadExampleScript.gql').read_text()

sub = pwd / 'queries'
QUERY_STATE = (sub / 'State.gql').read_text()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mutation LoadExampleScript {
loadExampleScript
}
28 changes: 28 additions & 0 deletions tests/plugins/ctrl/schema/mutations/test_load_example_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from pathlib import Path

from nextline import Nextline
from strawberry import Schema

from nextlinegraphql.plugins.ctrl import example_script as example_script_module
from nextlinegraphql.plugins.ctrl.graphql import MUTATE_LOAD_EXAMPLE_SCRIPT
from nextlinegraphql.plugins.ctrl.schema import Mutation, Query, Subscription

EXAMPLE_SCRIPT_PATH = Path(example_script_module.__file__).parent / 'script.py'
example_script = EXAMPLE_SCRIPT_PATH.read_text()

INITIAL_SCRIPT = '''
import time
time.sleep(0.001)
'''.strip()


async def test_query() -> None:
nextline = Nextline(INITIAL_SCRIPT)
async with nextline:
context = {'nextline': nextline}
schema = Schema(query=Query, mutation=Mutation, subscription=Subscription)
result = await schema.execute(MUTATE_LOAD_EXAMPLE_SCRIPT, context_value=context)
assert not result.errors
assert result.data
assert result.data['loadExampleScript'] is True
assert nextline.statement == example_script

0 comments on commit 382623e

Please sign in to comment.