Commit d869ac5b authored by Roman Yurchak's avatar Roman Yurchak

Use multi-line code snippets in tests

parent 8c27b0b4
...@@ -4,6 +4,7 @@ Various common utilities for testing. ...@@ -4,6 +4,7 @@ Various common utilities for testing.
import atexit import atexit
import multiprocessing import multiprocessing
import textwrap
import os import os
import pathlib import pathlib
import queue import queue
...@@ -73,10 +74,16 @@ class SeleniumWrapper: ...@@ -73,10 +74,16 @@ class SeleniumWrapper:
self.driver.execute_script("window.logs = []") self.driver.execute_script("window.logs = []")
def run(self, code): def run(self, code):
if isinstance(code, str) and code.startswith('\n'):
# we have a multiline string, fix indentation
code = textwrap.dedent(code)
return self.run_js( return self.run_js(
'return pyodide.runPython({!r})'.format(code)) 'return pyodide.runPython({!r})'.format(code))
def run_js(self, code): def run_js(self, code):
if isinstance(code, str) and code.startswith('\n'):
# we have a multiline string, fix indentation
code = textwrap.dedent(code)
catch = f""" catch = f"""
Error.stackTraceLimit = Infinity; Error.stackTraceLimit = Infinity;
try {{ {code} }} try {{ {code} }}
......
This diff is collapsed.
def test_pytest(selenium): def test_pytest(selenium):
selenium.load_package('pytest') selenium.load_package(['pytest', 'numpy', 'nose'])
selenium.load_package('numpy')
selenium.load_package('nose') selenium.run(
selenium.run('from pathlib import Path') """
selenium.run('import os') from pathlib import Path
selenium.run('import numpy') import os
selenium.run('base_dir = Path(numpy.__file__).parent / "core" / "tests"') import numpy
selenium.run("import pytest;" import pytest
"pytest.main([base_dir / 'test_api.py'])")
base_dir = Path(numpy.__file__).parent / "core" / "tests"
""")
selenium.run("pytest.main([base_dir / 'test_api.py'])")
logs = '\n'.join(selenium.logs) logs = '\n'.join(selenium.logs)
assert 'INTERNALERROR' not in logs assert 'INTERNALERROR' not in logs
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment