Skip to content

Commit

Permalink
Merge branch 'master' into fix_supercell_selection
Browse files Browse the repository at this point in the history
  • Loading branch information
yakutovicha authored Jan 9, 2023
2 parents f2d5f19 + da5f992 commit d4fccda
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 40 deletions.
5 changes: 4 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
---
ci:
autoupdate_schedule: quarterly

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
Expand Down Expand Up @@ -29,7 +32,7 @@ repos:
tryceratops]

- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.11.4
hooks:
- id: isort
args: [--profile, black, --filter-files]
Expand Down
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ def _selenium_driver(nb_path):
return _selenium_driver


@pytest.fixture
def final_screenshot(request, screenshot_dir, selenium):
"""Take screenshot at the end of the test.
Screenshot name is generated from the test function name
by stripping the 'test_' prefix
"""
screenshot_name = f"{request.function.__name__[5:]}.png"
screenshot_path = Path.joinpath(screenshot_dir, screenshot_name)
yield
selenium.get_screenshot_as_file(screenshot_path)


@pytest.fixture
def firefox_options(firefox_options):
firefox_options.add_argument("--headless")
Expand Down
49 changes: 10 additions & 39 deletions tests/test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,60 +11,42 @@ def test_notebook_service_available(notebook_service):
assert response.status_code == 200


def test_process_list(selenium_driver, screenshot_dir):
def test_process_list(selenium_driver, final_screenshot):
driver = selenium_driver("notebooks/process_list.ipynb")
driver.find_element(By.XPATH, '//button[text()="Update now"]')

# Save screenshot.
driver.get_screenshot_as_file(f"{screenshot_dir}/process-list.png")


def test_aiida_datatypes_viewers(selenium_driver, screenshot_dir):
def test_aiida_datatypes_viewers(selenium_driver, final_screenshot):
driver = selenium_driver("notebooks/aiida_datatypes_viewers.ipynb")
driver.set_window_size(1000, 2000)
driver.find_element(By.CLASS_NAME, "widget-label")
driver.find_element(By.XPATH, '//button[text()="Clear selection"]')
time.sleep(5)

# Save screenshot.
driver.get_screenshot_as_file(f"{screenshot_dir}/datatypes-viewer.png")


def test_eln_configure(selenium_driver, screenshot_dir):
def test_eln_configure(selenium_driver, final_screenshot):
driver = selenium_driver("notebooks/eln_configure.ipynb")
driver.find_element(By.XPATH, '//button[text()="Set as default"]')

# Save screenshot.
driver.get_screenshot_as_file(f"{screenshot_dir}/eln-configure.png")


def test_process(selenium_driver, screenshot_dir):
def test_process(selenium_driver, final_screenshot):
driver = selenium_driver("notebooks/process.ipynb")
driver.find_element(By.XPATH, '//label[@title="Select calculation:"]')

# Save screenshot.
driver.get_screenshot_as_file(f"{screenshot_dir}/process.png")


def test_wizard_apps(selenium_driver, screenshot_dir):
def test_wizard_apps(selenium_driver, final_screenshot):
driver = selenium_driver("notebooks/wizard_apps.ipynb")
driver.find_element(By.XPATH, '//label[@title="Delivery progress:"]')

# Save screenshot.
driver.get_screenshot_as_file(f"{screenshot_dir}/wizzard-apps.png")


def test_structures(selenium_driver, screenshot_dir):
def test_structures(selenium_driver, final_screenshot):
driver = selenium_driver("notebooks/structures.ipynb")
driver.set_window_size(1000, 900)
driver.find_element(By.XPATH, '//button[text()="Upload Structure (0)"]')
time.sleep(5)

# Save screenshot.
driver.get_screenshot_as_file(f"{screenshot_dir}/structures.png")


def test_structures_generate_from_smiles(selenium_driver, screenshot_dir):
def test_structures_generate_from_smiles(selenium_driver, final_screenshot):
driver = selenium_driver("notebooks/structures.ipynb")
driver.set_window_size(1000, 900)
# Switch to SMILES tab in StructureManagerWidget
Expand All @@ -83,14 +65,9 @@ def test_structures_generate_from_smiles(selenium_driver, screenshot_dir):
driver.find_element(By.XPATH, '//button[text()="Apply selection"]').click()
driver.find_element(By.XPATH, "//p[contains(text(),'Id: 1; Symbol: C;')]")

# Save screenshot.
driver.get_screenshot_as_file(
f"{screenshot_dir}/structures_generate_from_smiles_2.png"
)


def test_structure_from_examples_and_supercell_selection(
selenium_driver, screenshot_dir
selenium_driver, final_screenshot
):

driver = selenium_driver("notebooks/structures.ipynb")
Expand Down Expand Up @@ -132,19 +109,16 @@ def test_structure_from_examples_and_supercell_selection(
)


def test_eln_import(selenium_driver, screenshot_dir):
def test_eln_import(selenium_driver, final_screenshot):
driver = selenium_driver("notebooks/eln_import.ipynb")
# TODO: This find_element is not specific enough it seems,
# on the screenshot the page is still loading.
driver.find_element(By.ID, "tooltip")
time.sleep(5)

# Save screenshot.
driver.get_screenshot_as_file(f"{screenshot_dir}/eln-import.png")


def test_computational_resources_code_setup(
selenium_driver, aiidalab_exec, screenshot_dir
selenium_driver, aiidalab_exec, final_screenshot
):
"""Test the quicksetup of the code"""
# check the code pw-7.0 is not in code list
Expand Down Expand Up @@ -207,6 +181,3 @@ def test_computational_resources_code_setup(
# check the new code pw-7.0@daint-mc is in code list
output = aiidalab_exec("verdi code list").decode().strip()
assert "dos-7.0@daint-mc" in output

# Save screenshot.
driver.get_screenshot_as_file(f"{screenshot_dir}/computational-resources.png")

0 comments on commit d4fccda

Please sign in to comment.