Commit d54dc7ca authored by Romain Casati's avatar Romain Casati
Browse files

Testing put_file and put_module.

parent 2de167d8
......@@ -26,5 +26,44 @@ def test_errors(selenium):
assert 'result' not in data['result'] and data['stdout'] == ""
def test_put_file(selenium):
selenium.run_js("""
window.toBytesArray = function(string) {
string = unescape(encodeURIComponent(string));
const arr = [];
for (var i = 0; i < string.length; i++) {
arr.push(string.charCodeAt(i));
}
return Uint8ClampedArray.from(arr);
}""")
content = 'hello\n world! ¥£€$¢₡₢₣₤₥₦₧₨₩₪₫₭₮₯₹'
selenium.driver.execute_script("Basthon.putFile('foo.txt', toBytesArray(arguments[0]))", content)
data = selenium.run_basthon("""
with open('foo.txt') as f:
print(f.read(), end='', flush=True)""")['stdout']
assert data == content
def test_put_module(selenium):
pass
content = "foo = 42"
selenium.driver.execute_async_script("""
const done = arguments[arguments.length - 1];
const content = toBytesArray(arguments[0]);
Basthon.putModule('bar.py', content).then(done);""", content)
result = selenium.run_basthon("""
import bar
print(bar.foo, end='', flush=True)""")['stdout']
assert result == "42"
# with a second module
content = "bar = 24"
selenium.driver.execute_async_script("""
const done = arguments[arguments.length - 1];
const content = toBytesArray(arguments[0]);
Basthon.putModule('foo.py', content).then(done);""", content)
result = selenium.run_basthon("""
import foo
foo.bar""")['result']['result']['text/plain']
assert result == "24"
Supports Markdown
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