|
|
|
@ -17,7 +17,7 @@
|
|
|
|
|
|
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
|
|
from gns3server.utils.asyncio.embed_shell import EmbedShell
|
|
|
|
|
#from gns3server.utils.asyncio.embed_shell import EmbedShell
|
|
|
|
|
|
|
|
|
|
#FIXME: this is broken with recent Python >= 3.6
|
|
|
|
|
# def test_embed_shell_help(async_run):
|
|
|
|
@ -39,44 +39,44 @@ from gns3server.utils.asyncio.embed_shell import EmbedShell
|
|
|
|
|
# assert async_run(app._parse_command('? hello')) == 'hello: The hello world function\n\nThe hello usage\n'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_embed_shell_execute(async_run):
|
|
|
|
|
class Application(EmbedShell):
|
|
|
|
|
|
|
|
|
|
async def hello(self):
|
|
|
|
|
"""
|
|
|
|
|
The hello world function
|
|
|
|
|
|
|
|
|
|
The hello usage
|
|
|
|
|
"""
|
|
|
|
|
return 'world'
|
|
|
|
|
reader = asyncio.StreamReader()
|
|
|
|
|
writer = asyncio.StreamReader()
|
|
|
|
|
app = Application(reader, writer)
|
|
|
|
|
assert async_run(app._parse_command('hello')) == 'world'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_embed_shell_welcome(async_run, loop):
|
|
|
|
|
reader = asyncio.StreamReader()
|
|
|
|
|
writer = asyncio.StreamReader()
|
|
|
|
|
app = EmbedShell(reader, writer, welcome_message="Hello")
|
|
|
|
|
task = loop.create_task(app.run())
|
|
|
|
|
assert async_run(writer.read(5)) == b"Hello"
|
|
|
|
|
task.cancel()
|
|
|
|
|
try:
|
|
|
|
|
loop.run_until_complete(task)
|
|
|
|
|
except asyncio.CancelledError:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_embed_shell_prompt(async_run, loop):
|
|
|
|
|
reader = asyncio.StreamReader()
|
|
|
|
|
writer = asyncio.StreamReader()
|
|
|
|
|
app = EmbedShell(reader, writer)
|
|
|
|
|
app.prompt = "gbash# "
|
|
|
|
|
task = loop.create_task(app.run())
|
|
|
|
|
assert async_run(writer.read(7)) == b"gbash# "
|
|
|
|
|
task.cancel()
|
|
|
|
|
try:
|
|
|
|
|
loop.run_until_complete(task)
|
|
|
|
|
except asyncio.CancelledError:
|
|
|
|
|
pass
|
|
|
|
|
# def test_embed_shell_execute(async_run):
|
|
|
|
|
# class Application(EmbedShell):
|
|
|
|
|
#
|
|
|
|
|
# async def hello(self):
|
|
|
|
|
# """
|
|
|
|
|
# The hello world function
|
|
|
|
|
#
|
|
|
|
|
# The hello usage
|
|
|
|
|
# """
|
|
|
|
|
# return 'world'
|
|
|
|
|
# reader = asyncio.StreamReader()
|
|
|
|
|
# writer = asyncio.StreamReader()
|
|
|
|
|
# app = Application(reader, writer)
|
|
|
|
|
# assert async_run(app._parse_command('hello')) == 'world'
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# def test_embed_shell_welcome(async_run, loop):
|
|
|
|
|
# reader = asyncio.StreamReader()
|
|
|
|
|
# writer = asyncio.StreamReader()
|
|
|
|
|
# app = EmbedShell(reader, writer, welcome_message="Hello")
|
|
|
|
|
# task = loop.create_task(app.run())
|
|
|
|
|
# assert async_run(writer.read(5)) == b"Hello"
|
|
|
|
|
# task.cancel()
|
|
|
|
|
# try:
|
|
|
|
|
# loop.run_until_complete(task)
|
|
|
|
|
# except asyncio.CancelledError:
|
|
|
|
|
# pass
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# def test_embed_shell_prompt(async_run, loop):
|
|
|
|
|
# reader = asyncio.StreamReader()
|
|
|
|
|
# writer = asyncio.StreamReader()
|
|
|
|
|
# app = EmbedShell(reader, writer)
|
|
|
|
|
# app.prompt = "gbash# "
|
|
|
|
|
# task = loop.create_task(app.run())
|
|
|
|
|
# assert async_run(writer.read(7)) == b"gbash# "
|
|
|
|
|
# task.cancel()
|
|
|
|
|
# try:
|
|
|
|
|
# loop.run_until_complete(task)
|
|
|
|
|
# except asyncio.CancelledError:
|
|
|
|
|
# pass
|
|
|
|
|