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

CI fixes and improvements #331

Merged
merged 24 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
17 changes: 11 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Run basic tests for this app on the latest aiidalab-docker image.
# Run basic tests for this app

name: continuous-integration

Expand All @@ -13,16 +13,21 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: '3.10'
cache: pip
cache-dependency-path: |
.pre-commit-config.yaml
**/setup.cfg
**/pyproject.toml
**/requirements*.txt

- name: Install dependencies
run: |
python -m pip install pre-commit==2.11.1
run: python -m pip install pre-commit~=2.20
danielhollas marked this conversation as resolved.
Show resolved Hide resolved

- name: Run pre-commit
run: pre-commit run --all-files || ( git status --short ; git diff ; exit 1 )
35 changes: 19 additions & 16 deletions .github/workflows/di.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,27 @@ jobs:
matrix:
tag: [latest]
browser: [Chrome, Firefox]
python-version: ['3.8', '3.10']
danielhollas marked this conversation as resolved.
Show resolved Hide resolved
firefox: ['96.0']
danielhollas marked this conversation as resolved.
Show resolved Hide resolved
fail-fast: false

runs-on: ubuntu-latest
timeout-minutes: 60

steps:
- name: Check out app
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Cache Python dependencies
uses: actions/cache@v1
- name: Set up Python
uses: actions/setup-python@v4
with:
path: ~/.cache/pip
key: pip-${{ matrix.python-version }}-tests-${{ hashFiles('**/setup.json') }}
restore-keys: pip-${{ matrix.python-version }}-tests

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
python-version: '3.10'
cache: pip
cache-dependency-path: |
**/setup.cfg
**/pyproject.toml
**/requirements*.txt

- name: Install dependencies for test
run: |
pip install -U -r requirements_test.txt
run: pip install -U -r requirements_test.txt

- name: Set jupyter token env
run: echo "JUPYTER_TOKEN=$(openssl rand -hex 32)" >> $GITHUB_ENV
Expand All @@ -52,7 +47,7 @@ jobs:
- name: Install Firefox
uses: browser-actions/setup-firefox@latest
with:
firefox-version: ${{ matrix.firefox }}
firefox-version: latest
danielhollas marked this conversation as resolved.
Show resolved Hide resolved
if: matrix.browser == 'Firefox'

- name: Install geckodriver
Expand All @@ -65,3 +60,11 @@ jobs:
run: pytest --driver ${{ matrix.browser }}
env:
TAG: ${{ matrix.tag }}

- name: Upload screenshots as artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: Screenshots-${{ matrix.tag }}-${{ matrix.browser }}
path: ~/screenshots/
if-no-files-found: error
11 changes: 3 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: check-json
- id: check-yaml
Expand All @@ -22,7 +22,7 @@ repos:
language_version: python3 # Should be a command that runs python3.6+

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
rev: 6.0.0
hooks:
- id: flake8
args: [--count, --show-source, --statistics]
Expand All @@ -35,17 +35,12 @@ repos:
- id: isort
args: [--profile, black, --filter-files]

- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.2.0
hooks:
- id: setup-cfg-fmt

- repo: https://github.com/sirosen/check-jsonschema
rev: 0.19.2
hooks:
- id: check-github-workflows

- repo: https://github.com/kynan/nbstripout
rev: 0.5.0
rev: 0.6.1
hooks:
- id: nbstripout
4 changes: 2 additions & 2 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pytest~=6.0
pytest~=6.2
danielhollas marked this conversation as resolved.
Show resolved Hide resolved
pytest-docker~=1.0
pytest-selenium~=4.0
webdriver-manager~=3.8
selenium==4.1.0
selenium~=4.7.0
9 changes: 4 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ python_requires = >=3.8
dev =
bumpver==2022.1119
pre-commit==2.11.1
test =
requirements-test.txt
test = file: requirements_test.txt
danielhollas marked this conversation as resolved.
Show resolved Hide resolved

[options.package_data]
aiidalab_qe.parameters = qeapp.yaml
Expand All @@ -51,9 +50,9 @@ categories =

[flake8]
ignore =
E501 # Line length handled by black.
W503 # Line break before binary operator, preferred formatting for black.
E203 # Whitespace before ':', preferred formatting for black.
E501
W503
E203

[bumpver]
current_version = "v22.12.0"
Expand Down
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path
from urllib.parse import urljoin

import pytest
Expand Down Expand Up @@ -62,6 +63,13 @@ def _selenium_driver(nb_path, wait_time=5.0):
return _selenium_driver


@pytest.fixture(scope="session")
def screenshot_dir():
sdir = Path.joinpath(Path.home(), "screenshots")
os.mkdir(sdir)
return sdir


@pytest.fixture
def firefox_options(firefox_options):
firefox_options.add_argument("--headless")
Expand Down
19 changes: 14 additions & 5 deletions tests/test_qe_app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import time
from pathlib import Path

import requests
from selenium.webdriver.common.by import By

Expand All @@ -8,21 +11,27 @@ def test_notebook_service_available(notebook_service):
assert response.status_code == 200


def test_qe_app_take_screenshot(selenium_driver):
def test_qe_app_take_screenshot(selenium_driver, screenshot_dir):
driver = selenium_driver("qe.ipynb", wait_time=30.0)
driver.set_window_size(1920, 985)
driver.get_screenshot_as_file("screenshots/qe-app.png")
driver.get_screenshot_as_file(str(Path.joinpath(screenshot_dir, "qe-app.png")))


def test_qe_app_select_silicon(selenium_driver):
def test_qe_app_select_silicon(selenium_driver, screenshot_dir):
driver = selenium_driver("qe.ipynb", wait_time=30.0)
driver.set_window_size(1920, 985)
driver.find_element(
By.XPATH, "//*[text()='From Examples']"
).click() # click `From Examples` tab for input structure
driver.find_element(By.XPATH, "//option[@value='Diamond']").click()
driver.get_screenshot_as_file("screenshots/qe-app-select-diamond-selected.png")
time.sleep(2)
driver.get_screenshot_as_file(
str(Path.joinpath(screenshot_dir, "qe-app-select-diamond-selected.png"))
)
confirm_button = driver.find_element(By.XPATH, "//button[text()='Confirm']")
confirm_button.location_once_scrolled_into_view # scroll into view
confirm_button.click()
driver.get_screenshot_as_file("screenshots/qe-app-select-diamond-confirmed.png")
time.sleep(2)
driver.get_screenshot_as_file(
str(Path.joinpath(screenshot_dir, "qe-app-select-diamond-confirmed.png"))
)