diff --git a/.github/actions/install/action.yml b/.github/actions/install/action.yml index 7ba4f3d3..a0ae0597 100644 --- a/.github/actions/install/action.yml +++ b/.github/actions/install/action.yml @@ -46,15 +46,7 @@ runs: env: _pip_install_url: ${{ github.server_url }}/${{ github.repository }}@${{ github.ref }} run: | - pip install --progress-bar off -r requirements-dev.txt - - - name: Install using pip (git+... URL) - if: inputs.variant == 'standard' - shell: bash -l {0} - env: - _pip_install_url: ${{ github.server_url }}/${{ github.repository }}@${{ github.ref }} - run: | - pip install --progress-bar off "git+$_pip_install_url" idaes-pse pytest + pip install --progress-bar off "idaes-ui[testing] @ git+$_pip_install_url" idaes-pse - name: Install extensions shell: bash -l {0} diff --git a/.github/workflows/core.yml b/.github/workflows/core.yml index 9cbcef2e..4e4b550b 100644 --- a/.github/workflows/core.yml +++ b/.github/workflows/core.yml @@ -66,7 +66,7 @@ jobs: - os: win64 runner-image: windows-2022 steps: - - uses: IDAES/idaes-ui/.github/actions/install@main + - uses: IDAES/idaes-ui/.github/actions/install@refs/pull/49/merge with: variant: ${{ matrix.install-variant }} python-version: ${{ matrix.python-version }} @@ -99,7 +99,7 @@ jobs: steps: #python starts here - name: Install python code - uses: IDAES/idaes-ui/.github/actions/install@main + uses: IDAES/idaes-ui/.github/actions/install@refs/pull/49/merge with: variant: ${{ matrix.install-variant }} python-version: ${{ matrix.python-version }} diff --git a/docs/tests/test_screenshots.py b/docs/tests/test_screenshots.py index 688d32a8..d45e95b5 100644 --- a/docs/tests/test_screenshots.py +++ b/docs/tests/test_screenshots.py @@ -16,8 +16,9 @@ # third-party -from playwright.sync_api import Page, expect import pytest +pytest.importorskip("playwright", reason="Playwright not installed") +from playwright.sync_api import Page, expect # package from idaes.models.flowsheets.demo_flowsheet import build_flowsheet diff --git a/idaes_ui/fv/app.py b/idaes_ui/fv/app.py deleted file mode 100644 index 387298e8..00000000 --- a/idaes_ui/fv/app.py +++ /dev/null @@ -1,104 +0,0 @@ -""" -Application server for IDAES UI -""" - -__author__ = "Dan Gunter" -__created__ = "2023-10-08" - -# stdlib -import sys -from pathlib import Path -from typing import Optional, Union, Dict, Tuple - -# from pathlib import Path - -# external packages -from fastapi import FastAPI, HTTPException - -# from fastapi.staticfiles import StaticFiles -# from fastapi.responses import FileResponse - -# package -from idaes_ui.fv.models import DiagnosticsData, DiagnosticsException, DiagnosticsError -from idaes_ui.fv.models.settings import AppSettings - -# from idaes_ui.fv.models.flowsheet import Flowsheet, merge_flowsheets - -# defined functions -from .fastAPI_functions.initial_params import InitialParams -from .fastAPI_functions.cors import enable_fastapi_cors -from idaes_ui.fv.fastAPI_functions.uvicorn import WebUvicorn - -# defined route -from .fastAPI_route.router import Router - - -class FlowsheetApp: - def __init__( - self, - flowsheet, - name, - port: Optional[int] = None, - save_time_interval: Optional[int] = 5, - save: Optional[Union[Path, str, bool]] = None, - save_dir: Optional[Path] = None, - load_from_saved: bool = True, - overwrite: bool = False, - test: bool = False, - browser: bool = True, - ): - # Initial self.... params - InitialParams( - main_class=self, - flowsheet=flowsheet, - name=name, - port=port, - save_time_interval=save_time_interval, - save=save, - save_dir=save_dir, - load_from_saved=load_from_saved, - overwrite=overwrite, - test=test, - ) - - # initial FastAPI - self.app = FastAPI( - docs_url="/api/v1/docs", - redoc="/api/v1/redoc", - title="IDAES UI API DOC", - description="IDAES UI API endpoint detail.", - ) - - # enable CORS let allowed port can talk to this server - enable_fastapi_cors(self.app) - - # get diagnostics json - self.diag_data = DiagnosticsData(flowsheet) - - # API router - Router( - fastAPIApp=self.app, - flowsheet=self.flowsheet, - flowsheet_name=self.flowsheet_name, - save_time_interval=self.save_time_interval, - save=self.save, - save_dir=self.save_dir, - load_from_saved=self.load_from_saved, - overwrite=self.overwrite, - ) - - # print message why browser not start - if self.test: - print("Test mode enabled with 'test = True', browser won't start!") - if not browser: - print( - "Browser mode disenabled with 'browser = False', browser won't start!" - ) - - # # Uvicorn serve fastAPI app - # # condition not test only not test case will start uvicorn - if not self.test and browser: - WebUvicorn(self.app, self.port, self.flowsheet_name) - - def get_fast_api_app(self): - return self.app diff --git a/idaes_ui/fv/model_server.py b/idaes_ui/fv/model_server.py index f6ac1467..0506d7d8 100644 --- a/idaes_ui/fv/model_server.py +++ b/idaes_ui/fv/model_server.py @@ -368,8 +368,6 @@ def _get_diagnostics(self, id_): } self._write_json(200, build_diagnostics_report) - # json.dumps(diag_data_config) - json.dumps(diagnostics_toolbox_report) # === PUT === def do_PUT(self): diff --git a/idaes_ui/fv/models/tests/test_diag.py b/idaes_ui/fv/models/tests/test_diag.py index 2ede5b9f..eb29d16c 100644 --- a/idaes_ui/fv/models/tests/test_diag.py +++ b/idaes_ui/fv/models/tests/test_diag.py @@ -2,11 +2,13 @@ Tests for the diagnostics models """ -import pytest import json + +import pytest +requests = pytest.importorskip("requests") + from ..diag import DiagnosticsData from . import flowsheet -import requests # get diagnostics data from remote diff --git a/idaes_ui/fv/tests/test_app.py b/idaes_ui/fv/tests/test_app.py deleted file mode 100644 index 8b4d44a0..00000000 --- a/idaes_ui/fv/tests/test_app.py +++ /dev/null @@ -1,102 +0,0 @@ -""" -Tests for the IDAES FV app, using FastAPI TestClient -""" -import pytest - -pytest.importorskip("fastapi", reason="fastapi not available") -from fastapi.testclient import TestClient -from ..app import FlowsheetApp -from idaes_ui.fv.tests.flowsheets import idaes_demo_flowsheet - -# fixtures - - -@pytest.fixture(scope="module") # build flowsheet only once -def fvapp(): - """Start the FastAPI app.""" - flowsheet = idaes_demo_flowsheet() - return FlowsheetApp(flowsheet).app - - -@pytest.fixture -def client(fvapp): - """FastAPI client for testing""" - return TestClient(fvapp) - -# Tests. -# Unit test naming: -# test_{route} => smoke test for http status for all operations -# test_{get/put/..}_{route} => test data - - -@pytest.mark.unit -def test_diagnostics(client): - response = client.get("/diagnostics/") - assert response.status_code == 200 - - -@pytest.mark.unit -def test_get_diagnostics(client): - response = client.get("/diagnostics/") - assert response.status_code == 200 - data = response.json() - assert set(data.keys()) == {"config", "issues", "statistics"} - - -@pytest.mark.unit -def test_settings(client): - response = client.get("/settings/") - assert response.status_code == 200 - response = client.put("/settings/", json=response.json()) - assert response.status_code == 200 - - -@pytest.mark.unit -def test_get_settings(client): - response = client.get("/settings/") - assert response.status_code == 200 - data = response.json() - assert len(data.keys()) > 0 - - -@pytest.mark.unit -def test_put_settings(client): - response = client.get("/settings/") - data1 = response.json() - data1["autosave_interval"] += 1 - response = client.put("/settings/", json=data1) - response = client.get("/settings/") - data2 = response.json() - assert data1 == data2 - - -@pytest.mark.unit -def test_fs(client): - response = client.get("/fs/") - assert response.status_code == 200 - response = client.put("/fs/", json=response.json()) - assert response.status_code == 200 - - -@pytest.mark.unit -def test_get_fs(client): - response = client.get("/fs/") - assert response.status_code == 200 - data = response.json() - print(data) - keys = set(data.keys()) - assert {"name", "model", "cells"}.issubset(keys) - - -@pytest.mark.unit -def test_put_fs(client): - response = client.get("/fs/") - assert response.status_code == 200 - data1 = response.json() - # modify position of 1st 'cell' - cells = data1["cells"] - cells[0]["position"]["x"] += 1 - # check that modification survived - response = client.put("/fs/", json=data1) - data2 = response.json() - assert data1 == data2 diff --git a/idaes_ui/fv/tests/test_fsvis.py b/idaes_ui/fv/tests/test_fsvis.py index 924ce7e7..258da968 100644 --- a/idaes_ui/fv/tests/test_fsvis.py +++ b/idaes_ui/fv/tests/test_fsvis.py @@ -20,11 +20,12 @@ import logging import os from pathlib import Path -import pytest import re -import requests import time +import pytest +requests = pytest.importorskip("requests") + from pyomo.environ import ConcreteModel from idaes.core import FlowsheetBlock from idaes.models.properties.activity_coeff_models.BTX_activity_coeff_VLE import ( diff --git a/pyproject.toml b/pyproject.toml index 5adbdcd8..84faa3b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,24 +37,31 @@ build-backend = "setuptools.build_meta" "Topic :: Software Development :: Libraries :: Python Modules", ] dependencies = [ + # IMPORTANT: idaes-pse should NOT be added to the default dependencies + # this causes, among other things, CI failures in IDAES/idaes-pse # Don't version setuptools, various bits complain "setuptools", - # For running tests - "idaes-pse @ git+https://github.com/IDAES/idaes-pse@main", - "pytest", - "playwright==1.42.0", - "pytest-playwright==0.4.4", - "requests==2.31.0", - "pydantic~=2.0", + "pydantic ~= 2.0", + + # for compatibility with IDAES unit formatting + # following IDAES/idaes-pse#1438 is released + "pint < 0.24", + + # fastapi is not used at the moment; uncomment once fastapi is needed again + # "fastapi", + # "uvicorn", ] keywords = ["IDAES", "energy systems", "chemical engineering", "process modeling"] [project.optional-dependencies] -dev = [ - # For adding copyright headers (see addheader.yml and the readme) - "addheader >= 0.3.0", - # Dev versions of idaes/idaes-ui in requirements-dev.txt +testing = [ + "pytest", + "pytest-icdiff >= 0.7", # readable dict diffs for test_flowsheet and others + "playwright==1.42.0", + "pytest-playwright==0.4.4", + "requests==2.31.0", + # "httpx", # fastapi testing ] # For packaging pkg = [ diff --git a/requirements-dev.txt b/requirements-dev.txt index 80badb5d..2be1bb59 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,11 +1,5 @@ ---editable .[dev] +--editable .[testing] + +# For adding copyright headers (see addheader.yml and the readme) +addheader >= 0.3.0 idaes-pse @ git+https://github.com/IDAES/idaes-pse@main -pydantic~=2.0 -fastapi -uvicorn -pytest-icdiff >= 0.7 # readable dict diffs for test_flowsheet and others -httpx # fastapi testing -# for testing w/playwright -playwright==1.42.0 -pytest-playwright==0.4.4 -requests==2.31.0