Repository: pyscript/pyscript
File: pyscriptjs/tests/integration/test_plugins.py (Python)

Code before:
        console.log(f'beforePyScriptExec called')
        console.log(f'before_src:{src}')

    def afterPyScriptExec(self, interpreter, src, pyScriptTag, result):
        console.log(f'afterPyScriptExec called')
        console.log(f'after_src:{src}')

    def onUserError(self, config):
        console.log('onUserError called')


plugin = TestLogger()
"""

# Source of script that defines a plugin with only beforePyScriptExec and
# afterPyScriptExec methods
PYSCRIPT_HOOKS_PLUGIN_CODE = """
from pyscript import Plugin
from js import console

class ExecTestLogger(Plugin):

    async def beforePyScriptExec(self, interpreter, src, pyScriptTag):
        console.log(f'beforePyScriptExec called')
        console.log(f'before_src:{src}')
        console.log(f'before_id:{pyScriptTag.id}')

    async def afterPyScriptExec(self, interpreter, src, pyScriptTag, result):
        console.log(f'afterPyScriptExec called')
        console.log(f'after_src:{src}')
        console.log(f'after_id:{pyScriptTag.id}')
        console.log(f'result:{result}')


plugin = ExecTestLogger()
"""

# Source of script that defines a plugin with only beforePyScriptExec and
# afterPyScriptExec methods
PYREPL_HOOKS_PLUGIN_CODE = """
from pyscript import Plugin
from js import console

console.warn("This is in pyrepl hooks file")

class PyReplTestLogger(Plugin):

    def beforePyReplExec(self, interpreter, src, outEl, pyReplTag):
        console.log(f'beforePyReplExec called')
        console.log(f'before_src:{src}')
        console.log(f'before_id:{pyReplTag.id}')

Review comment (suggestion):
`pyScriptTag` is a `pyodide.ffi.JsProxy` and I was unable to get the `id`.

I have removed this for now...since it wasn't testing something of any significant value I guess...
But of course, if there's a way to resolve this, we should re-add this stuff...

Code after:
        console.log(f'beforePyScriptExec called')
        console.log(f'before_src:{src}')

    def afterPyScriptExec(self, interpreter, src, pyScriptTag, result):
        console.log(f'afterPyScriptExec called')
        console.log(f'after_src:{src}')

    def onUserError(self, config):
        console.log('onUserError called')


plugin = TestLogger()
"""

# Source of script that defines a plugin with only beforePyScriptExec and
# afterPyScriptExec methods
PYSCRIPT_HOOKS_PLUGIN_CODE = """
from pyscript import Plugin
from js import console

class ExecTestLogger(Plugin):

    async def beforePyScriptExec(self, interpreter, src, pyScriptTag):
        console.log(f'beforePyScriptExec called')
        console.log(f'before_src:{src}')

    async def afterPyScriptExec(self, interpreter, src, pyScriptTag, result):
        console.log(f'afterPyScriptExec called')
        console.log(f'after_src:{src}')
        console.log(f'result:{result}')


plugin = ExecTestLogger()
"""

# Source of script that defines a plugin with only beforePyScriptExec and
# afterPyScriptExec methods
PYREPL_HOOKS_PLUGIN_CODE = """
from pyscript import Plugin
from js import console

console.warn("This is in pyrepl hooks file")

class PyReplTestLogger(Plugin):

    def beforePyReplExec(self, interpreter, src, outEl, pyReplTag):
        console.log(f'beforePyReplExec called')
        console.log(f'before_src:{src}')

    def afterPyReplExec(self, interpreter, src, outEl, pyReplTag, result):
        console.log(f'afterPyReplExec called')