diff --git a/.ci/pull_adr_image.sh b/.ci/pull_adr_image.sh index db3a6e26..bea4b1f2 100644 --- a/.ci/pull_adr_image.sh +++ b/.ci/pull_adr_image.sh @@ -6,6 +6,3 @@ _IMAGE_NAME="ghcr.io/ansys-internal/nexus_dev" # Pull Ansys Dynamic Reporting image based on tag docker pull $_IMAGE_NAME - -# Remove all dangling images -docker image prune -f diff --git a/Makefile b/Makefile index eb197bcd..ac2b21f4 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ CODESPELL_DIRS ?= ./pydynamicreporting CODESPELL_SKIP ?= "*.pyc,*.xml,*.txt,*.gif,*.png,*.jpg,*.js,*.html,*.doctree,*.ttf,*.woff,*.woff2,*.eot,*.mp4,*.inv,*.pickle,*.ipynb,flycheck*,./.git/*,./.hypothesis/*,*.yml,./docs/build/*,./docs/images/*,./dist/*,*~,.hypothesis*,./docs/source/examples/*,*cover,*.dat,*.mac,\#*,PKG-INFO,*.mypy_cache/*,*.xml,*.aedt,*.svg" CODESPELL_IGNORE ?= "ignore_words.txt" +TEST_FILE ?= "tests\test_service.py" +INSTALL_PATH ?= "C:\Program Files\ANSYS Inc\v252" doctest: codespell @@ -30,6 +32,10 @@ test: pip install -e .[test] pytest -rvx --setup-show --cov=ansys.dynamicreporting.core --cov-report html:coverage-html --cov-report term --cov-report xml:coverage.xml +test-dev: + pip install -e .[test] + pytest -rvx --setup-show "$(TEST_FILE)" --use-local-launcher --install-path "$(INSTALL_PATH)" + smoketest: python tests/smoketest.py diff --git a/README.rst b/README.rst index 3e968330..983f64c1 100644 --- a/README.rst +++ b/README.rst @@ -93,12 +93,12 @@ run this code: The preceding code creates an "editable" installation that lets you develop and test PyDynamicReporting at the same time. -To build and create a production-like installation, first install -`chocolatey `_. Then: +To build and create a production-like installation on Windows (not required on other OSes), +first install `chocolatey `_. Then: .. code:: - choco install make # install make + choco install make # install make on Windows make clean # clean make build # build # this replaces the editable installation done previously. If you don't want to replace, @@ -128,6 +128,19 @@ Deploy and upload steps **must always** be ignored. If they are not ignored, before running GitHub Actions locally, add ``if: ${{ !env.ACT }}`` to the workflow step and commit this change if required. +Local tests +^^^^^^^^^^^ +To run tests on your local desktop (recommended), use the `make` target +`test-dev`. This target runs the tests in the same way as GitHub Actions but using +a local Ansys installation instead of Docker. You must specify the path to your Ansys +installation and the test file you are trying to run. + +.. code:: + + make test-dev TEST_FILE="tests/test_service.py" INSTALL_PATH="C:\Program Files\ANSYS Inc\v252" + +Note that any tests that require Docker will obviously fail. + Dependencies ------------ To use PyDynamicReporting, you must have a locally installed and licensed copy diff --git a/pyproject.toml b/pyproject.toml index cb48148f..fcecd418 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -71,11 +71,16 @@ ci = "https://github.com/ansys/pydynamicreporting/actions" [project.optional-dependencies] test = [ + "pytest>=8.3.3", + "pytest-cov>=6.0.0", + "psutil==6.0.0", +] +test-extra = [ "docker>=7.1.0", "psutil==6.0.0", "exceptiongroup==1.0.0", - "pytest==8.3.3", - "pytest-cov==6.0.0", + "pytest>=8.3.3", + "pytest-cov>=6.0.0", "pyvista==0.44.1", "vtk==9.4.0", "ansys-dpf-core==0.13.0", @@ -102,8 +107,8 @@ dev = [ "pillow==10.4.0", "psutil==6.0.0", "docker>=7.1.0", - "pytest==8.3.3", - "pytest-cov==6.0.0", + "pytest>=8.3.3", + "pytest-cov>=6.0.0", "Sphinx==8.0.2", "sphinx-copybutton==0.5.2", "sphinx-gallery==0.18.0", diff --git a/src/ansys/dynamicreporting/core/adr_service.py b/src/ansys/dynamicreporting/core/adr_service.py index 12705364..8409f437 100755 --- a/src/ansys/dynamicreporting/core/adr_service.py +++ b/src/ansys/dynamicreporting/core/adr_service.py @@ -599,14 +599,14 @@ def stop(self) -> None: # If coming from a docker image, clean that up try: if self._container: - self.logger.info("Told service Container to shutdown.\n") + self.logger.info("Shutting down container.\n") self._container.stop() self._container = None else: - self.logger.info("Told service to shutdown.\n") + self.logger.info("Shutting down service.\n") self.serverobj.stop_local_server() except Exception as e: - self.logger.error(f"Problem shutting down service.\n{str(e)}\n") + self.logger.error(f"Problem shutting down container/service.\n{str(e)}\n") pass if self._delete_db and self._db_directory: diff --git a/src/ansys/dynamicreporting/core/utils/report_remote_server.py b/src/ansys/dynamicreporting/core/utils/report_remote_server.py index 30a45862..8571b739 100755 --- a/src/ansys/dynamicreporting/core/utils/report_remote_server.py +++ b/src/ansys/dynamicreporting/core/utils/report_remote_server.py @@ -1189,7 +1189,7 @@ def delete_database(db_dir: str): if not validate_local_db(db_dir): # Validate the directory database before deleting it if print_allowed(): - print(f"Error: we are asked to delete the database but {db_dir} is not a database dir") + print(f"Error: Unable to delete the database: {db_dir} is not a database dir") else: try: # Check if there is a nexus.status file. If yes, it means there is a Nexus service running on that diff --git a/tests/conftest.py b/tests/conftest.py index 51934e87..e56a3b1e 100755 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,9 +1,8 @@ """Global fixtures go here.""" -import os + +from pathlib import Path from random import choice, random -import shutil from string import ascii_letters -import subprocess import pytest @@ -16,26 +15,7 @@ def pytest_addoption(parser): parser.addoption("--install-path", action="store", default="dev.json") -def cleanup_docker(request) -> None: - # Stop and remove 'nexus' containers. This needs to be deleted once we address the issue - # in the pynexus code by giving unique names to the containers - try: - subprocess.run(["docker", "stop", "nexus"]) - subprocess.run(["docker", "rm", "nexus"]) - except Exception: - # There might not be a running nexus container. That is fine, just continue - pass - try: - querydb_dir = os.path.join(os.path.join(request.fspath.dirname, "test_data"), "query_db") - os.remove(os.path.join(querydb_dir, "nexus.log")) - os.remove(os.path.join(querydb_dir, "nexus.status")) - shutil.rmtree(os.path.join(querydb_dir, "nginx")) - except Exception: - # There might not be these files / directories. In which case, nothing to do - pass - - -@pytest.fixture +@pytest.fixture(scope="module") def get_exec(pytestconfig: pytest.Config) -> str: exec_basis = "" use_local = pytestconfig.getoption("use_local_launcher") @@ -44,52 +24,72 @@ def get_exec(pytestconfig: pytest.Config) -> str: return exec_basis -@pytest.fixture -def adr_service_create(request, pytestconfig: pytest.Config) -> Service: +@pytest.fixture(scope="module") +def adr_service_create(pytestconfig: pytest.Config) -> Service: use_local = pytestconfig.getoption("use_local_launcher") - dir_name = "auto_delete_" + "".join(choice(ascii_letters) for x in range(5)) - db_dir = os.path.join(os.path.join(request.fspath.dirname, "test_data"), dir_name) - tmp_docker_dir = os.path.join(os.path.join(request.fspath.dirname, "test_data"), "tmp_docker") + + # Paths setup + base_dir = Path(__file__).parent / "test_data" + dir_name = "auto_delete_" + "".join(choice(ascii_letters) for _ in range(5)) + db_dir = base_dir / dir_name + tmp_docker_dir = base_dir / "tmp_docker" + if use_local: - tmp_service = Service( + adr_service = Service( ansys_installation=pytestconfig.getoption("install_path"), docker_image=DOCKER_DEV_REPO_URL, - db_directory=db_dir, + db_directory=str(db_dir), port=8000 + int(random() * 4000), ) else: - cleanup_docker(request) - tmp_service = Service( + adr_service = Service( ansys_installation="docker", docker_image=DOCKER_DEV_REPO_URL, - db_directory=db_dir, - data_directory=tmp_docker_dir, + db_directory=str(db_dir), + data_directory=str(tmp_docker_dir), port=8000 + int(random() * 4000), ) - return tmp_service + _ = adr_service.start( + create_db=True, + exit_on_close=True, + delete_db=True, + ) + + yield adr_service # Return to running the test session + + # Cleanup + adr_service.stop() -@pytest.fixture -def adr_service_query(request, pytestconfig: pytest.Config) -> Service: + +@pytest.fixture(scope="module") +def adr_service_query(pytestconfig: pytest.Config) -> Service: use_local = pytestconfig.getoption("use_local_launcher") - local_db = os.path.join("test_data", "query_db") - db_dir = os.path.join(request.fspath.dirname, local_db) - tmp_docker_dir = os.path.join( - os.path.join(request.fspath.dirname, "test_data"), "tmp_docker_query" - ) + + # Paths setup + base_dir = Path(__file__).parent / "test_data" + local_db = base_dir / "query_db" + tmp_docker_dir = base_dir / "tmp_docker_query" + if use_local: ansys_installation = pytestconfig.getoption("install_path") else: - cleanup_docker(request) ansys_installation = "docker" - tmp_service = Service( + + adr_service = Service( ansys_installation=ansys_installation, docker_image=DOCKER_DEV_REPO_URL, - db_directory=db_dir, - data_directory=tmp_docker_dir, + db_directory=str(local_db), + data_directory=str(tmp_docker_dir), port=8000 + int(random() * 4000), ) + if not use_local: - tmp_service._container.save_config() - tmp_service.start(create_db=False, exit_on_close=True, delete_db=False) - return tmp_service + adr_service._container.save_config() + + adr_service.start(create_db=False, exit_on_close=True, delete_db=False) + + yield adr_service # Return to running the test session + + # Cleanup + adr_service.stop() diff --git a/tests/test_download_html.py b/tests/test_download_html.py index e23dd1f4..5ddc51f3 100755 --- a/tests/test_download_html.py +++ b/tests/test_download_html.py @@ -9,7 +9,6 @@ def test_download_use_data(request, adr_service_query) -> bool: my_url += "/reports/report_display/?report_table_length=10&view=c4afe878-a4fe-11ed-a616-747827182a82&usemenus=on&dpi=96&pwidth=19.41&query=" a = rd.ReportDownloadHTML(url=my_url, directory=test_dir, debug=True) test_res = a._should_use_data_uri(size=5) - adr_service_query.stop() assert test_res @@ -22,7 +21,6 @@ def test_download_nourl(request, adr_service_query) -> bool: success = False except ValueError: success = True - adr_service_query.stop() assert success @@ -35,7 +33,6 @@ def test_download_nodir(request, adr_service_query) -> bool: success = False except ValueError: success = True - adr_service_query.stop() assert success @@ -49,7 +46,6 @@ def test_download_sqlite(request, adr_service_query) -> bool: success = False except Exception: success = True - adr_service_query.stop() assert success @@ -59,5 +55,4 @@ def test_download(request, adr_service_query) -> bool: my_url += "/reports/report_display/?report_table_length=10&view=c4afe878-a4fe-11ed-a616-747827182a82&usemenus=on&dpi=96&pwidth=19.41&query=" a = rd.ReportDownloadHTML(url=my_url, directory=test_dir, debug=True) test_res = a.download() - adr_service_query.stop() assert test_res is None diff --git a/tests/test_geofile_processing.py b/tests/test_geofile_processing.py index a8a3894b..578a6773 100755 --- a/tests/test_geofile_processing.py +++ b/tests/test_geofile_processing.py @@ -47,6 +47,12 @@ def test_file_is_3d_geometry(request) -> bool: assert scene is True and img is False +@pytest.mark.ado_test +def test_get_avz_directory(request) -> bool: + avz_dir = gp.get_avz_directory(return_file_paths(request)[1]) + assert isinstance(avz_dir, str) and avz_dir != "" + + @pytest.mark.ado_test def test_rebuild_3d_geom_avz(request) -> bool: _ = gp.rebuild_3d_geometry( diff --git a/tests/test_item.py b/tests/test_item.py index ba6903d5..8499aff0 100755 --- a/tests/test_item.py +++ b/tests/test_item.py @@ -8,111 +8,64 @@ @pytest.mark.ado_test def test_create_img(adr_service_create, request) -> bool: - _ = adr_service_create.start( - create_db=True, - exit_on_close=True, - delete_db=True, - ) filter_str = "A|i_type|cont|image" img_items = adr_service_create.query(query_type="Item", filter=filter_str) my_img = adr_service_create.create_item() my_img.item_image = join(join(request.fspath.dirname, "test_data"), "aa_00_0_alpha1.png") new_img_items = adr_service_create.query(query_type="Item", filter=filter_str) - adr_service_create.stop() assert len(new_img_items) == (len(img_items) + 1) @pytest.mark.ado_test def test_create_img_jpg(adr_service_create, request) -> bool: - _ = adr_service_create.start( - create_db=True, - exit_on_close=True, - delete_db=True, - ) filter_str = "A|i_type|cont|image" img_items = adr_service_create.query(query_type="Item", filter=filter_str) my_img = adr_service_create.create_item() my_img.item_image = join(join(request.fspath.dirname, "test_data"), "car_crash.jpg") new_img_items = adr_service_create.query(query_type="Item", filter=filter_str) - adr_service_create.stop() assert len(new_img_items) == (len(img_items) + 1) @pytest.mark.ado_test def test_create_img_tiff(adr_service_create, request) -> bool: - _ = adr_service_create.start( - create_db=True, - exit_on_close=True, - delete_db=True, - ) filter_str = "A|i_type|cont|image" img_items = adr_service_create.query(query_type="Item", filter=filter_str) my_img = adr_service_create.create_item() my_img.item_image = join(join(request.fspath.dirname, "test_data"), "displacement.tiff") new_img_items = adr_service_create.query(query_type="Item", filter=filter_str) - adr_service_create.stop() assert len(new_img_items) == (len(img_items) + 1) def test_create_scene(adr_service_create, request) -> bool: - _ = adr_service_create.start( - create_db=True, - exit_on_close=True, - delete_db=True, - ) my_scene = adr_service_create.create_item() my_scene.item_scene = join( join(join(request.fspath.dirname, "test_data"), "scenes"), "scene.avz" ) my_scene.width = 800 my_scene.height = 500 - adr_service_create.stop() assert type(my_scene) is Item def test_create_text(adr_service_create, request) -> bool: - _ = adr_service_create.start( - create_db=True, - exit_on_close=True, - delete_db=True, - ) my_text = adr_service_create.create_item(obj_name="testtext", source="testing") my_text.item_text = "

This is my first test of a text item

" my_text.item_text = "Now let us change the text just to make sure it works" - adr_service_create.stop() assert my_text.type == "text" def test_create_file(adr_service_create, request) -> bool: - _ = adr_service_create.start( - create_db=True, - exit_on_close=True, - delete_db=True, - ) my_file = adr_service_create.create_item(obj_name="testfile", source="testing") my_file.item_file = join(join(request.fspath.dirname, "test_data"), "dam_break.ens") - adr_service_create.stop() assert my_file.type == "file" def test_create_anim(adr_service_create, request) -> bool: - _ = adr_service_create.start( - create_db=True, - exit_on_close=True, - delete_db=True, - ) my_anim = adr_service_create.create_item(obj_name="testanim", source="testing") my_anim.item_animation = join(join(request.fspath.dirname, "test_data"), "dam_break.mp4") - adr_service_create.stop() assert my_anim.type == "animation" def test_create_tree(adr_service_create, request) -> bool: - _ = adr_service_create.start( - create_db=True, - exit_on_close=True, - delete_db=True, - ) leaves = [] for i in range(10): leaves.append({"key": "leaves", "name": f"Leaf {i}", "value": i}) @@ -141,23 +94,16 @@ def test_create_tree(adr_service_create, request) -> bool: ) my_tree = adr_service_create.create_item(obj_name="testtree", source="testing") my_tree.item_tree = tree - adr_service_create.stop() assert my_tree.type == "tree" def test_change_type(adr_service_create, request) -> bool: - _ = adr_service_create.start( - create_db=True, - exit_on_close=True, - delete_db=True, - ) filter_str = "A|i_type|cont|html" img_items = adr_service_create.query(query_type="Item", filter=filter_str) my_img = adr_service_create.create_item() my_img.item_image = join(join(request.fspath.dirname, "test_data"), "aa_00_0_alpha1.png") my_img.item_text = "This is not supposed to work" new_img_items = adr_service_create.query(query_type="Item", filter=filter_str) - adr_service_create.stop() assert len(new_img_items) == len(img_items) @@ -170,7 +116,6 @@ def test_vis_item(adr_service_query) -> bool: success = True except SyntaxError: success = False - adr_service_query.stop() assert success is True @@ -183,7 +128,6 @@ def test_iframe_item(adr_service_query) -> bool: success = True except SyntaxError: success = False - adr_service_query.stop() assert success is True @@ -196,7 +140,6 @@ def test_iframe_on_img_item(adr_service_query) -> bool: success = True except SyntaxError: success = False - adr_service_query.stop() assert success is True @@ -205,17 +148,11 @@ def test_get_url(adr_service_query) -> bool: filter_str = "A|i_type|cont|table" one_item = adr_service_query.query(query_type="Item", filter=filter_str) url = one_item[0].url - adr_service_query.stop() assert (url is not None) and ("http" in url) @pytest.mark.ado_test def test_create_table(adr_service_create) -> bool: - _ = adr_service_create.start( - create_db=True, - exit_on_close=True, - delete_db=True, - ) filter_str = "A|i_type|cont|table" table_items = adr_service_create.query(query_type="Item", filter=filter_str) my_table = adr_service_create.create_item() @@ -278,17 +215,11 @@ def test_create_table(adr_service_create) -> bool: my_table.row_tags = ["dp=0", "dp=2"] my_table.col_tags = ["a", "b", "c", "d", "e", "f"] new_table_items = adr_service_create.query(query_type="Item", filter=filter_str) - adr_service_create.stop() assert len(new_table_items) == (len(table_items) + 1) @pytest.mark.ado_test def test_create_histo(adr_service_create) -> bool: - _ = adr_service_create.start( - create_db=True, - exit_on_close=True, - delete_db=True, - ) filter_str = "A|i_type|cont|table" table_items = adr_service_create.query(query_type="Item", filter=filter_str) my_table = adr_service_create.create_item() @@ -298,17 +229,11 @@ def test_create_histo(adr_service_create) -> bool: my_table.histogram_normalized = 1 my_table.histogram_bin_size = 0.5 new_table_items = adr_service_create.query(query_type="Item", filter=filter_str) - adr_service_create.stop() assert len(new_table_items) == (len(table_items) + 1) @pytest.mark.ado_test def test_create_3d_scatter(adr_service_create) -> bool: - _ = adr_service_create.start( - create_db=True, - exit_on_close=True, - delete_db=True, - ) filter_str = "A|i_type|cont|table" table_items = adr_service_create.query(query_type="Item", filter=filter_str) my_table = adr_service_create.create_item() @@ -328,17 +253,11 @@ def test_create_3d_scatter(adr_service_create) -> bool: my_table.ztitle = "f(x,y)" my_table.line_marker_opacity = 0.7 new_table_items = adr_service_create.query(query_type="Item", filter=filter_str) - adr_service_create.stop() assert len(new_table_items) == (len(table_items) + 1) @pytest.mark.ado_test def test_create_3d_surface(adr_service_create) -> bool: - _ = adr_service_create.start( - create_db=True, - exit_on_close=True, - delete_db=True, - ) filter_str = "A|i_type|cont|table" table_items = adr_service_create.query(query_type="Item", filter=filter_str) my_table = adr_service_create.create_item() @@ -355,7 +274,6 @@ def test_create_3d_surface(adr_service_create) -> bool: my_table.plot = "3d surface" my_table.format = "floatdot0" new_table_items = adr_service_create.query(query_type="Item", filter=filter_str) - adr_service_create.stop() assert len(new_table_items) == (len(table_items) + 1) @@ -366,7 +284,6 @@ def test_set_tags(adr_service_query) -> bool: success = one_item[0].set_tags(tagstring="firsttag=one") except SyntaxError: success = False - adr_service_query.stop() assert success is True @@ -378,7 +295,6 @@ def test_get_tags(adr_service_query) -> bool: success = True except SyntaxError: success = False - adr_service_query.stop() assert success is True and len(tags) == 36 @@ -390,7 +306,6 @@ def test_add_tag(adr_service_query) -> bool: success = one_item[0].add_tag(tag="Tag", value="one") except SyntaxError: success = False - adr_service_query.stop() assert success is True @@ -401,7 +316,6 @@ def test_rem_tag(adr_service_query) -> bool: success = one_item[0].rem_tag(tag="tagtodelete") except SyntaxError: success = False - adr_service_query.stop() assert success is True diff --git a/tests/test_report.py b/tests/test_report.py index e0446b5e..56333e02 100755 --- a/tests/test_report.py +++ b/tests/test_report.py @@ -10,7 +10,6 @@ def test_geturl_report(adr_service_query) -> bool: my_report = adr_service_query.get_report(report_name="My Top Report") url = my_report.get_url() - adr_service_query.stop() assert "http:" in url @@ -18,7 +17,6 @@ def test_geturl_report(adr_service_query) -> bool: def test_geturl_report_with_filter(adr_service_query) -> bool: my_report = adr_service_query.get_report(report_name="My Top Report") url = my_report.get_url(filter='"A|b_type|cont|image;"') - adr_service_query.stop() assert "http:" in url @@ -31,7 +29,6 @@ def test_visualize_report(adr_service_query) -> bool: success = True except SyntaxError: success = False - adr_service_query.stop() assert success is True @@ -43,7 +40,6 @@ def test_iframe_report(adr_service_query) -> bool: success = True except SyntaxError: success = False - adr_service_query.stop() assert success is True @@ -117,7 +113,6 @@ def test_save_as_pdf(adr_service_query, request, get_exec) -> bool: success = my_report.export_pdf(file_name=pdf_file) except Exception: success = False - adr_service_query.stop() else: # If no local installation, then skip this test success = True assert success is True @@ -131,14 +126,12 @@ def test_save_as_html(adr_service_query) -> bool: success = my_report.export_html(directory_name="htmltest_again") except Exception: success = False - adr_service_query.stop() assert success is True def test_get_guid(adr_service_query) -> bool: my_report = adr_service_query.get_report(report_name="My Top Report") guid = my_report.get_guid() - adr_service_query.stop() assert len(guid) > 0 @@ -326,7 +319,6 @@ class ReportFetchComponent extends HTMLElement { # check script content script_check = clean_script == clean_expected_script - adr_service_query.stop() assert script_check @@ -354,5 +346,4 @@ def test_get_report_component(adr_service_query) -> bool: ) web_component_iframe_check = clean_web_component_iframe == clean_expected_web_component_iframe - adr_service_query.stop() assert web_component_prefix_check and web_component_iframe_check diff --git a/tests/test_report_objects.py b/tests/test_report_objects.py index 7ab294dc..faa6c433 100755 --- a/tests/test_report_objects.py +++ b/tests/test_report_objects.py @@ -1866,5 +1866,4 @@ def test_item_payload(adr_service_query) -> bool: succ = True except Exception: succ = False - adr_service_query.stop() assert succ diff --git a/tests/test_report_remote_server.py b/tests/test_report_remote_server.py index 8cad2da7..dbc08f04 100755 --- a/tests/test_report_remote_server.py +++ b/tests/test_report_remote_server.py @@ -13,8 +13,6 @@ from ansys.dynamicreporting.core.utils import report_remote_server as r from ansys.dynamicreporting.core.utils.exceptions import DBCreationFailedError -from .conftest import cleanup_docker - def test_copy_item(adr_service_query, request, get_exec) -> bool: db_dir = join(join(request.fspath.dirname, "test_data"), "newcopy") @@ -36,10 +34,7 @@ def test_copy_item(adr_service_query, request, get_exec) -> bool: succ = s.copy_items( source=adr_service_query.serverobj, obj_type="item", progress=False, progress_qt=False ) - adr_service_query.stop() tmp_adr.stop() - if get_exec == "": - cleanup_docker(request) assert succ @@ -54,7 +49,6 @@ def test_start_stop(request, get_exec) -> bool: port=port_r, ) else: - cleanup_docker(request) tmp_adr = Service( ansys_installation="docker", docker_image=DOCKER_DEV_REPO_URL, @@ -90,7 +84,6 @@ def test_validate_existing(adr_service_query) -> bool: succ = True try: _ = r.validate_local_db(db_dir=adr_service_query._db_directory, version_check=True) - r.stop_background_local_server(server_dirname=adr_service_query._db_directory) except Exception: succ = False assert succ @@ -106,7 +99,6 @@ def test_fail_newdb(request, get_exec) -> bool: port=port_r, ) else: - cleanup_docker(request) tmp_adr = Service( ansys_installation="docker", docker_image=DOCKER_DEV_REPO_URL, @@ -155,11 +147,6 @@ def test_none_url() -> bool: def test_server_token(adr_service_create) -> bool: - _ = adr_service_create.start( - create_db=True, - exit_on_close=True, - delete_db=True, - ) s = adr_service_create.serverobj token = s.generate_magic_token(max_age=10) succ = s._validate_magic_token(token=token) @@ -170,24 +157,16 @@ def test_server_token(adr_service_create) -> bool: s.set_password(p=s.get_password()) succ_four = s.get_server_name() == "ADR Database" succ_five = s.stop_server_allowed() - s.stop_local_server() - adr_service_create.stop() assert succ and succ_two and succ_three and succ_four and succ_five @pytest.mark.ado_test def test_server_guids(adr_service_create) -> bool: - _ = adr_service_create.start( - create_db=True, - exit_on_close=True, - delete_db=True, - ) s = adr_service_create.serverobj succ = s.get_user_groups() == ["nexus"] succ_two = s.get_object_guids() == [] s.get_object_from_guid(guid=str(uuid.uuid1())) succ_three = s.get_file(obj=None, fileobj=None) == requests.codes.service_unavailable - adr_service_create.stop() assert succ and succ_two and succ_three @@ -225,40 +204,6 @@ def test_url_query() -> bool: ) -def test_stop_local_server(adr_service_query, request) -> bool: - db_dir = join(join(request.fspath.dirname, "test_data"), "query_db") - success = False - try: - r.stop_background_local_server(server_dirname=db_dir) - success = True - except Exception: - success = False - assert success - - -def test_delete_db(adr_service_create, request) -> bool: - _ = adr_service_create.start( - create_db=True, - exit_on_close=True, - delete_db=False, - ) - db_dir = adr_service_create._db_directory - adr_service_create.stop() - succ = False - try: - r.delete_database(db_dir=db_dir) - succ = True - except Exception: - succ = False - succ_two = False - try: - r.delete_database(db_dir=join(request.fspath.dirname, "test_data")) - succ_two = True - except Exception: - succ_two = False - assert succ and succ_two - - def test_export_html(adr_service_query) -> bool: success = False try: @@ -268,7 +213,6 @@ def test_export_html(adr_service_query) -> bool: success = False s = adr_service_query.serverobj s.export_report_as_html(report_guid=my_report.report.guid, directory_name="htmltest") - adr_service_query.stop() assert success is True @@ -302,7 +246,6 @@ def test_export_pdf(adr_service_query, get_exec) -> bool: s.export_report_as_pdf(report_guid=my_report.report.guid, file_name="mytest") except OSError: success = True - adr_service_query.stop() assert success is True @@ -316,7 +259,6 @@ def test_export_pptx_error(adr_service_query) -> bool: s.export_report_as_pptx(report_guid=my_report.report.guid, file_name="mypresentation") except Exception: success = True - adr_service_query.stop() assert success is True @@ -331,8 +273,6 @@ def test_get_pptx(adr_service_query, request) -> bool: success = False else: success = True - adr_service_query.stop() - cleanup_docker(request) assert success is True @@ -358,26 +298,17 @@ def test_copy_template(adr_service_query, request, get_exec) -> bool: succ = s.copy_items( source=adr_service_query.serverobj, obj_type="template", progress=False, progress_qt=False ) - adr_service_query.stop() tmp_adr.stop() - if get_exec == "": - cleanup_docker(request) assert succ def test_groups(adr_service_create, request) -> bool: - _ = adr_service_create.start( - create_db=True, - exit_on_close=True, - delete_db=True, - ) s = adr_service_create.serverobj succ = s.get_auth() == (b"nexus", b"cei") succ_two = s.get_user_groups() == ["nexus"] s.cur_username = "" succ_three = s.get_user_groups() == [] s.cur_username = "nexus" - adr_service_create.stop() assert succ and succ_two and succ_three @@ -391,7 +322,6 @@ def test_acls_start(request, get_exec) -> bool: port=port_r, ) else: - cleanup_docker(request) tmp_adr = Service( ansys_installation="docker", docker_image=DOCKER_DEV_REPO_URL, diff --git a/tests/test_report_utils.py b/tests/test_report_utils.py index c34825a3..18184454 100755 --- a/tests/test_report_utils.py +++ b/tests/test_report_utils.py @@ -119,7 +119,6 @@ def test_from_local_8bit() -> bool: @pytest.mark.ado_test def test_run_web_request(adr_service_query) -> bool: resp = ru.run_web_request(method="GET", server=adr_service_query.serverobj, relative_url="") - adr_service_query.stop() assert resp.ok is True diff --git a/tests/test_serverless.py b/tests/test_serverless.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_service.py b/tests/test_service.py index 60ec1cf6..27544e5f 100755 --- a/tests/test_service.py +++ b/tests/test_service.py @@ -20,8 +20,6 @@ ) from ansys.dynamicreporting.core.utils import report_remote_server -from .conftest import cleanup_docker - @pytest.mark.ado_test def test_unit_nexus() -> bool: @@ -160,7 +158,6 @@ def test_no_directory() -> bool: def test_no_docker(request) -> bool: - success = True try: Service( ansys_installation="docker", @@ -173,35 +170,7 @@ def test_no_docker(request) -> bool: assert success is False -def test_start_empty_database(adr_service_create) -> bool: - session_guid = adr_service_create.start( - create_db=True, - exit_on_close=True, - delete_db=True, - ) - assert session_guid != "0" - - -def test_set_sessionguid(adr_service_create) -> bool: - _ = adr_service_create.start( - create_db=True, - exit_on_close=True, - delete_db=True, - ) - canset = True - try: - adr_service_create.session_guid = "ABCDE" - except AttributeError: - canset = False - assert canset is False - - def test_connect_to_connected(adr_service_create) -> bool: - adr_service_create.start( - create_db=True, - exit_on_close=True, - delete_db=True, - ) success = False try: _ = adr_service_create.start( @@ -219,7 +188,6 @@ def test_create_on_existing(request, get_exec) -> bool: if get_exec != "": tmp_adr = Service(ansys_installation=get_exec, db_directory=db_dir) else: - cleanup_docker(request) tmp_adr = Service( ansys_installation="docker", docker_image=DOCKER_DEV_REPO_URL, db_directory=db_dir ) @@ -232,34 +200,45 @@ def test_create_on_existing(request, get_exec) -> bool: @pytest.mark.ado_test -def test_stop_before_starting(adr_service_create) -> bool: - success = adr_service_create.stop() +def test_stop_before_starting(request, get_exec) -> bool: + db_dir = join(join(request.fspath.dirname, "test_data"), "query_db") + if get_exec != "": + tmp_adr = Service( + ansys_installation=get_exec, + db_directory=db_dir, + ) + else: + tmp_adr = Service( + ansys_installation="docker", + docker_image=DOCKER_DEV_REPO_URL, + db_directory=db_dir, + ) + success = tmp_adr.stop() assert success is None def test_get_sessionid(adr_service_create) -> bool: - session_id = adr_service_create.start(create_db=True, delete_db=True, exit_on_close=True) - assert session_id == adr_service_create.session_guid + assert ( + isinstance(adr_service_create.session_guid, str) + and len(adr_service_create.session_guid) > 0 + ) @pytest.mark.ado_test def test_query_sessions(adr_service_query) -> bool: len_queried = len(adr_service_query.query(query_type="Session")) - adr_service_query.stop() assert 3 == len_queried @pytest.mark.ado_test def test_query_dataset(adr_service_query) -> bool: len_queried = len(adr_service_query.query(query_type="Dataset")) - adr_service_query.stop() assert 4 == len_queried def test_query_table(adr_service_query) -> bool: all_items = adr_service_query.query(query_type="Item") only_table = [x for x in all_items if x.type == "table"] - adr_service_query.stop() assert 1 == len(only_table) @@ -268,7 +247,6 @@ def test_delete_item(adr_service_query) -> bool: only_text = adr_service_query.query(query_type="Item", filter="A|i_type|cont|html") adr_service_query.delete(only_text) newly_items = adr_service_query.query(query_type="Item", filter="A|i_type|cont|html") - adr_service_query.stop() assert len(newly_items) == 0 @@ -285,7 +263,6 @@ def test_delete_report(adr_service_query) -> bool: test_report = adr_service_query.get_report(test_report_name) adr_service_query.delete([test_report]) new_reports = adr_service_query.get_list_reports() - adr_service_query.stop() assert len(old_reports) == len(new_reports) @@ -296,7 +273,6 @@ def test_vis_report(adr_service_query) -> bool: success = True except SyntaxError: success = False - adr_service_query.stop() assert success is True @@ -308,14 +284,25 @@ def test_vis_report_filtered(adr_service_query) -> bool: success = True except SyntaxError: success = False - adr_service_query.stop() assert success is True -def test_vis_not_running(adr_service_create) -> bool: +def test_vis_not_running(request, get_exec) -> bool: success = False try: - adr_service_create.visualize_report() + db_dir = join(join(request.fspath.dirname, "test_data"), "query_db") + if get_exec != "": + tmp_adr = Service( + ansys_installation=get_exec, + db_directory=db_dir, + ) + else: + tmp_adr = Service( + ansys_installation="docker", + docker_image=DOCKER_DEV_REPO_URL, + db_directory=db_dir, + ) + tmp_adr.visualize_report() except ConnectionToServiceError: success = True assert success @@ -327,7 +314,6 @@ def test_vis_report_name(adr_service_query) -> bool: _ = adr_service_query.visualize_report(report_name="Not existing") except MissingReportError: success = True - adr_service_query.stop() assert success @@ -349,20 +335,17 @@ def test_connect_to_running(adr_service_query, request, get_exec) -> bool: ) tmp_adr.connect(url=adr_service_query.url, session=adr_service_query.session_guid) all_items_second = tmp_adr.query(query_type="Item") - adr_service_query.stop() tmp_adr.stop() assert len(all_items_second) == len(all_items) def test_get_report_name(adr_service_query) -> bool: my_report = adr_service_query.get_list_reports() - adr_service_query.stop() assert len(my_report) == 1 and type(my_report[0]) is str def test_get_report(adr_service_query) -> bool: my_report = adr_service_query.get_list_reports(r_type="report") - adr_service_query.stop() assert len(my_report) == 1 and type(my_report[0]) is Report @@ -392,7 +375,6 @@ def test_same_port(request, get_exec) -> bool: ansys_installation=get_exec, logfile=logfile, db_directory=db_dir_again, port=a._port ) else: - cleanup_docker(request) a = Service( ansys_installation="docker", docker_image=DOCKER_DEV_REPO_URL, db_directory=db_dir )