diff --git a/nextlinegraphql/plugins/ctrl/graphql/__init__.py b/nextlinegraphql/plugins/ctrl/graphql/__init__.py index b32b536..78e32de 100644 --- a/nextlinegraphql/plugins/ctrl/graphql/__init__.py +++ b/nextlinegraphql/plugins/ctrl/graphql/__init__.py @@ -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() diff --git a/nextlinegraphql/plugins/ctrl/graphql/mutations/LoadExampleScript.gql b/nextlinegraphql/plugins/ctrl/graphql/mutations/LoadExampleScript.gql new file mode 100644 index 0000000..89ae454 --- /dev/null +++ b/nextlinegraphql/plugins/ctrl/graphql/mutations/LoadExampleScript.gql @@ -0,0 +1,3 @@ +mutation LoadExampleScript { + loadExampleScript +} diff --git a/tests/plugins/ctrl/schema/mutations/test_load_example_script.py b/tests/plugins/ctrl/schema/mutations/test_load_example_script.py new file mode 100644 index 0000000..90b15e4 --- /dev/null +++ b/tests/plugins/ctrl/schema/mutations/test_load_example_script.py @@ -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