File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import time
2+
3+ from selenium import webdriver
4+ from selenium .webdriver .chrome .options import Options
5+ import pytest
6+
7+ RUN_CODE_TEMPLATE = """
8+ var output = "";
9+ save_output = function(text) {{
10+ output += text
11+ }};
12+ var vm = window.rp.vmStore.init('test_vm');
13+ vm.setStdout(save_output);
14+ vm.exec('{}');
15+ vm.destroy();
16+ return output;
17+ """
18+
19+ @pytest .fixture (scope = "module" )
20+ def driver (request ):
21+ options = Options ()
22+ options .headless = True
23+ options .add_argument ('--disable-gpu' )
24+ driver = webdriver .Chrome (options = options )
25+ driver .get ("http://localhost:8080" )
26+ assert "RustPython" in driver .title
27+ time .sleep (5 )
28+ yield driver
29+ driver .close ()
30+
31+
32+ @pytest .mark .parametrize ("script, output" ,
33+ [
34+ ("print(5)" , "5" ),
35+ ("a=5;b=4;print(a+b)" , "9" )
36+ ]
37+ )
38+ def test_demo (driver , script , output ):
39+ script = RUN_CODE_TEMPLATE .format (script )
40+ assert driver .execute_script (script ).strip () == output
You can’t perform that action at this time.
0 commit comments