Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ci prusse test #152

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ jobs:
strategy:
fail-fast: false
matrix:
CONDA_PY: ["36", "37", "38", "39"]
#python: ["3.6", "3.7", "3.8", "3.9"]
python: ["3.6"]

steps:
- uses: actions/checkout@v2
# We need to install Qt on the system otherwise tests in
# tests/test_qt_js_integration.py crash.
- name: Install Qt
uses: jurplel/install-qt-action@v2
- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
Expand All @@ -32,14 +29,15 @@ jobs:
channel-priority: true
- name: Install
env:
CONDA_PY: ${{ matrix.CONDA_PY }}
PYTHON_VERSION: ${{ matrix.python }}
run: |
conda config --system --set always_yes yes --set changeps1 no
conda install -c conda-forge conda-devenv
conda info -a
export TEST_QMXGRAPH=1
conda devenv -n qmxgraph
conda install -n qmxgraph coveralls pytest-cov
conda list -n qmxgraph
conda init bash
- name: Tests
shell: bash -l {0}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ resource_*.py
environment.yml
docs_environment.yml
esss_environment.yml
mxgraph/
2 changes: 1 addition & 1 deletion _base_environment.devenv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
- oop-ext
- pip
- pre-commit
- pyqt =5.12
- pyqt >=5.12

environment:
PYTHONPATH:
Expand Down
19 changes: 10 additions & 9 deletions environment.devenv.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% set TEST_QMXGRAPH = os.environ.get('TEST_QMXGRAPH', '0') != '0' %}
{% set PYTHON_VERSION = os.environ.get('PYTHON_VERSION', '3.6') %}
{% set PYTHON_VERSION = os.environ.get('TRAVIS_PYTHON_VERSION', PYTHON_VERSION) %}
{% set PYTHON_VERSION = os.environ['PYTHON_VERSION'] %}

name: qmxgraph

Expand All @@ -10,22 +9,24 @@ includes:
environment:
# Tip: Use `--driver <driver_name>` to change driver for a single run
{% if TEST_QMXGRAPH %}
PYTEST_ADDOPTS: --driver PhantomJS
PYTEST_ADDOPTS: --driver Chrome
{% endif %}

dependencies:
- python ={{ PYTHON_VERSION }}

{% if TEST_QMXGRAPH %}
- cherrypy
- hypothesis ==3.11.0
- hypothesis =3.11
- chromium
- python-chromedriver-binary
- pytest-mock
- pytest-qt
- pytest-rerunfailures
- pytest-selenium >=1,<2
- pytest-selenium
- pytest-timeout
{% if sys.platform != 'win32' %}
- pytest-xvfb
{% endif %}

- typing-extensions <4.2.0 # [PYTHON_VERSION=="3.6"]
# Pin importlib_resources due to #151.
- importlib_resources <5.10
- pytest-xvfb # [linux]
{% endif %}
1 change: 0 additions & 1 deletion scripts/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash
git clone --depth=1 --branch v3.7.5 https://github.com/jgraph/mxgraph.git
export PYTEST_ADDOPTS="--driver PhantomJS"
export MXGRAPHPATH=mxgraph
inv qrc
inv test
1 change: 1 addition & 0 deletions src/qmxgraph/waiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ def timed_out():
msg += f":\n{error_callback()}"
raise TimeoutError(msg)

time.sleep(1e-10)
QTest.qWait(wait_interval_ms)
2 changes: 1 addition & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def docs(ctx, python_version=None):
@invoke.task
def test(ctx):
print_message('test'.format(), color=Fore.BLUE, bright=True)
cmd = 'pytest --cov=qmxgraph --timeout=30 -v --durations=10'
cmd = 'pytest --cov=qmxgraph --timeout=60 -v --durations=10'

import subprocess

Expand Down
62 changes: 19 additions & 43 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import pytest


Expand All @@ -7,45 +9,16 @@ def pytest_configure(config):
# of pytest so they can't reliably be removed by a fixture.
config.cache.set('qmxgraph/ports', [])

import os

lock_file = _get_port_lock_filename(config.rootdir)
if os.path.isfile(lock_file):
os.remove(lock_file)

import socket

socket.setdefaulttimeout(15.0)


# Fixtures --------------------------------------------------------------------


@pytest.fixture
def phantomjs_driver(capabilities, driver_path, port):
"""
Overrides default `phantomjs_driver` driver from pytest-selenium.

Default implementation uses ephemeral ports just as our tests but
it doesn't provide any way to configure them, for this reason we basically
recreate the driver fixture using port fixture.
"""
kwargs = {}
if capabilities:
kwargs['desired_capabilities'] = capabilities
if driver_path is not None:
kwargs['executable_path'] = driver_path

kwargs['port'] = port.get()

from selenium.webdriver import PhantomJS

return PhantomJS(**kwargs)


@pytest.fixture
def driver_args():
return ['--debug=true']
def firefox_options(firefox_options):
firefox_options.headless = True
return firefox_options


@pytest.fixture(autouse=True)
Expand Down Expand Up @@ -320,24 +293,28 @@ def __init__(self, selenium, host):
_wait_graph_page_ready(host=host, selenium=selenium)

selenium.execute_script(
'callback = function(cellIds) {'
'window.callback = function(cellIds) {'
' if (!window.__added__) {'
' window.__added__ = [];'
' }'
' window.__added__.push.apply(window.__added__, cellIds);'
'}'
)
self.eval_js_function('api.registerCellsAddedHandler', qmxgraph.js.Variable('callback'))
self.eval_js_function(
'api.registerCellsAddedHandler', qmxgraph.js.Variable('window.callback')
)

selenium.execute_script(
'callback = function(cellId, newLabel, oldLabel) {'
'window.callback = function(cellId, newLabel, oldLabel) {'
' if (!window.__labels__) {'
' window.__labels__ = [];'
' }'
' window.__labels__.push({cellId: cellId, newLabel: newLabel, oldLabel: oldLabel});' # noqa
'}'
)
self.eval_js_function('api.registerLabelChangedHandler', qmxgraph.js.Variable('callback'))
self.eval_js_function(
'api.registerLabelChangedHandler', qmxgraph.js.Variable('window.callback')
)

def get_container(self):
"""
Expand Down Expand Up @@ -944,25 +921,24 @@ def _wait_graph_page_ready(host, selenium):
import socket
from selenium.common.exceptions import TimeoutException

timeout = 15
timeout = 30
timeout_exceptions = (TimeoutException, TimeoutError, socket.timeout)
selenium.set_page_load_timeout(1)
selenium.set_page_load_timeout(timeout)
refresh = True
try:
selenium.get(host.address)
refresh = False
except timeout_exceptions:
pass

tries = 3
if refresh:
for n in range(timeout):
for n in range(tries):
try:
selenium.refresh()
break
except timeout_exceptions:
pass
else:
raise TimeoutException("All page load tries resulted in timeout")
if n == tries - 1:
raise

from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
Expand Down
Loading