Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pyodide
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
pyodide
Commits
c5c87b41
Commit
c5c87b41
authored
Oct 02, 2018
by
Roman Yurchak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow testing packages under a different build path
parent
27d135e6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
17 deletions
+25
-17
test/conftest.py
test/conftest.py
+25
-17
No files found.
test/conftest.py
View file @
c5c87b41
...
@@ -13,14 +13,20 @@ import queue
...
@@ -13,14 +13,20 @@ import queue
import
sys
import
sys
import
shutil
import
shutil
TEST_PATH
=
pathlib
.
Path
(
__file__
).
parents
[
0
].
resolve
()
BUILD_PATH
=
TEST_PATH
/
'..'
/
'build'
try
:
try
:
import
pytest
import
pytest
except
ImportError
:
pytest
=
None
def
pytest_addoption
(
parser
):
group
=
parser
.
getgroup
(
"general"
)
group
.
addoption
(
'--build-dir'
,
action
=
"store"
,
default
=
BUILD_PATH
,
help
=
"Path to the build directory"
)
TEST_PATH
=
pathlib
.
Path
(
__file__
).
parents
[
0
].
resolve
()
except
ImportError
:
BUILD_PATH
=
TEST_PATH
/
'..'
/
'build'
pytest
=
None
class
PyodideInited
:
class
PyodideInited
:
...
@@ -49,16 +55,16 @@ def _display_driver_logs(browser, driver):
...
@@ -49,16 +55,16 @@ def _display_driver_logs(browser, driver):
class
SeleniumWrapper
:
class
SeleniumWrapper
:
def
__init__
(
self
,
server_port
,
server_hostname
=
'127.0.0.1'
,
def
__init__
(
self
,
build_dir
,
server_port
,
server_hostname
=
'127.0.0.1'
,
server_log
=
None
):
server_log
=
None
):
from
selenium.webdriver.support.wait
import
WebDriverWait
from
selenium.webdriver.support.wait
import
WebDriverWait
from
selenium.common.exceptions
import
TimeoutException
from
selenium.common.exceptions
import
TimeoutException
driver
=
self
.
get_driver
()
driver
=
self
.
get_driver
()
wait
=
WebDriverWait
(
driver
,
timeout
=
20
)
wait
=
WebDriverWait
(
driver
,
timeout
=
20
)
if
not
(
BUILD_PATH
/
'test.html'
).
exists
():
if
not
(
pathlib
.
Path
(
build_dir
)
/
'test.html'
).
exists
():
# selenium does not expose HTTP response codes
# selenium does not expose HTTP response codes
raise
ValueError
(
f"
{
(
BUILD_PATH
/
'test.html'
).
resolve
()
}
"
raise
ValueError
(
f"
{
(
build_dir
/
'test.html'
).
resolve
()
}
"
f"does not exist!"
)
f"does not exist!"
)
driver
.
get
(
f'http://
{
server_hostname
}
:
{
server_port
}
/test.html'
)
driver
.
get
(
f'http://
{
server_hostname
}
:
{
server_port
}
/test.html'
)
try
:
try
:
...
@@ -166,7 +172,8 @@ if pytest is not None:
...
@@ -166,7 +172,8 @@ if pytest is not None:
cls
=
FirefoxWrapper
cls
=
FirefoxWrapper
elif
request
.
param
==
'chrome'
:
elif
request
.
param
==
'chrome'
:
cls
=
ChromeWrapper
cls
=
ChromeWrapper
selenium
=
cls
(
server_port
=
server_port
,
selenium
=
cls
(
build_dir
=
request
.
config
.
option
.
build_dir
,
server_port
=
server_port
,
server_hostname
=
server_hostname
,
server_hostname
=
server_hostname
,
server_log
=
server_log
)
server_log
=
server_log
)
try
:
try
:
...
@@ -203,24 +210,25 @@ if pytest is not None:
...
@@ -203,24 +210,25 @@ if pytest is not None:
@
pytest
.
fixture
(
scope
=
'session'
)
@
pytest
.
fixture
(
scope
=
'session'
)
def
web_server_main
():
def
web_server_main
(
request
):
with
spawn_web_server
()
as
output
:
with
spawn_web_server
(
request
.
config
.
option
.
build_dir
)
as
output
:
yield
output
yield
output
@
pytest
.
fixture
(
scope
=
'session'
)
@
pytest
.
fixture
(
scope
=
'session'
)
def
web_server_secondary
():
def
web_server_secondary
(
request
):
with
spawn_web_server
()
as
output
:
with
spawn_web_server
(
request
.
config
.
option
.
build_dir
)
as
output
:
yield
output
yield
output
@
contextlib
.
contextmanager
@
contextlib
.
contextmanager
def
spawn_web_server
():
def
spawn_web_server
(
build_dir
):
tmp_dir
=
tempfile
.
mkdtemp
()
tmp_dir
=
tempfile
.
mkdtemp
()
log_path
=
pathlib
.
Path
(
tmp_dir
)
/
'http-server.log'
log_path
=
pathlib
.
Path
(
tmp_dir
)
/
'http-server.log'
q
=
multiprocessing
.
Queue
()
q
=
multiprocessing
.
Queue
()
p
=
multiprocessing
.
Process
(
target
=
run_web_server
,
args
=
(
q
,
log_path
))
p
=
multiprocessing
.
Process
(
target
=
run_web_server
,
args
=
(
q
,
log_path
,
build_dir
))
try
:
try
:
p
.
start
()
p
.
start
()
...
@@ -236,7 +244,7 @@ def spawn_web_server():
...
@@ -236,7 +244,7 @@ def spawn_web_server():
shutil
.
rmtree
(
tmp_dir
)
shutil
.
rmtree
(
tmp_dir
)
def
run_web_server
(
q
,
log_filepath
):
def
run_web_server
(
q
,
log_filepath
,
build_dir
):
"""Start the HTTP web server
"""Start the HTTP web server
Parameters
Parameters
...
@@ -249,7 +257,7 @@ def run_web_server(q, log_filepath):
...
@@ -249,7 +257,7 @@ def run_web_server(q, log_filepath):
import
http.server
import
http.server
import
socketserver
import
socketserver
os
.
chdir
(
BUILD_PATH
)
os
.
chdir
(
build_dir
)
log_fh
=
log_filepath
.
open
(
'w'
,
buffering
=
1
)
log_fh
=
log_filepath
.
open
(
'w'
,
buffering
=
1
)
sys
.
stdout
=
log_fh
sys
.
stdout
=
log_fh
...
@@ -303,7 +311,7 @@ def run_web_server(q, log_filepath):
...
@@ -303,7 +311,7 @@ def run_web_server(q, log_filepath):
if
(
__name__
==
'__main__'
if
(
__name__
==
'__main__'
and
multiprocessing
.
current_process
().
name
==
'MainProcess'
and
multiprocessing
.
current_process
().
name
==
'MainProcess'
and
not
hasattr
(
sys
,
"_pytest_session"
)):
and
not
hasattr
(
sys
,
"_pytest_session"
)):
with
spawn_web_server
():
with
spawn_web_server
(
BUILD_PATH
):
# run forever
# run forever
while
True
:
while
True
:
time
.
sleep
(
1
)
time
.
sleep
(
1
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment