Skip to content

Commit

Permalink
Merge pull request #12 from ansys-internal/create_unit_tests
Browse files Browse the repository at this point in the history
Create unit tests
  • Loading branch information
Samuelopez-ansys authored Jan 31, 2024
2 parents cb1f02d + 37512a6 commit 0cd5218
Show file tree
Hide file tree
Showing 69 changed files with 1,337 additions and 799 deletions.
34 changes: 17 additions & 17 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
name: "Code style"
runs-on: ubuntu-latest
steps:
- uses: ansys/actions/code-style@v4
- uses: ansys/actions/code-style@v5
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
use-python-cache: false
Expand All @@ -39,7 +39,7 @@ jobs:
name: "Documentation style"
runs-on: ubuntu-latest
steps:
- uses: ansys/actions/doc-style@v4
- uses: ansys/actions/doc-style@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -48,7 +48,7 @@ jobs:
runs-on: ubuntu-latest
needs: doc-style
steps:
- uses: ansys/actions/doc-build@v4
- uses: ansys/actions/doc-build@v5
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
check-links: false
Expand All @@ -63,7 +63,7 @@ jobs:
runs-on: ${{ matrix.os }}
needs: [ code-style ]
steps:
- uses: ansys/actions/build-wheelhouse@v4
- uses: ansys/actions/build-wheelhouse@v5
with:
library-name: ${{ env.LIBRARY_NAME }}
operating-system: ${{ matrix.os }}
Expand All @@ -81,7 +81,7 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -103,13 +103,13 @@ jobs:
timeout-minutes: 5
run: |
.\.venv\Scripts\Activate.ps1
pytest -v -m aedt_common --cov
pytest -v -m backend\tests_common_api --cov
- name: AEDT Test
timeout-minutes: 5
run: |
.\.venv\Scripts\Activate.ps1
pytest -v -m aedt --cov --cov-append
# - name: AEDT Test
# timeout-minutes: 5
# run: |
# .\.venv\Scripts\Activate.ps1
# pytest -v -m aedt --cov --cov-append

- name: "Combine coverage files"
run: |
Expand All @@ -119,7 +119,7 @@ jobs:
- name: "Upload coverage results"
if: ${{ matrix.python-version == env.MAIN_PYTHON_VERSION }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
path: .cov/total-html
name: html-total-coverage
Expand All @@ -137,7 +137,7 @@ jobs:
runs-on: ubuntu-latest
needs: [ doc-build, tests_windows_aedt ]
steps:
- uses: ansys/actions/build-library@v4
- uses: ansys/actions/build-library@v5
with:
library-name: ${{ env.LIBRARY_NAME }}
python-version: ${{ env.MAIN_PYTHON_VERSION }}
Expand All @@ -150,7 +150,7 @@ jobs:
steps:

- name: "Release to the private PyPI"
uses: ansys/actions/release-pypi-private@v4
uses: ansys/actions/release-pypi-private@v5
with:
library-name: ${{ env.LIBRARY_NAME }}
twine-username: "__token__"
Expand All @@ -164,7 +164,7 @@ jobs:
# twine-token: ${{ secrets.PYPI_TOKEN }}

- name: "Release to GitHub"
uses: ansys/actions/release-github@v4
uses: ansys/actions/release-github@v5
with:
library-name: ${{ env.LIBRARY_NAME }}

Expand All @@ -174,7 +174,7 @@ jobs:
needs: build-library
if: github.event_name == 'push'
steps:
- uses: ansys/actions/doc-deploy-dev@v4
- uses: ansys/actions/doc-deploy-dev@v5
with:
cname: ${{ env.DOCUMENTATION_CNAME }}
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -185,7 +185,7 @@ jobs:
needs: release
if: github.event_name == 'push' && contains(github.ref, 'refs/tags')
steps:
- uses: ansys/actions/doc-deploy-stable@v4
- uses: ansys/actions/doc-deploy-stable@v5
with:
cname: ${{ env.DOCUMENTATION_CNAME }}
token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Suggest to add labels
uses: peter-evans/create-or-update-comment@v3
uses: peter-evans/create-or-update-comment@v4
# Execute only when no labels have been applied to the pull request
if: toJSON(github.event.pull_request.labels.*.name) == '{}'
with:
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
exclude: |
(?x)(
src/ansys/aedt/toolkits/common/ui/.* |
src/ansys/aedt/toolkits/common/ui/utils/ui_templates/.* |
tests/input_data/.* |
examples/input_files/.*
examples/.*
)
repos:
Expand Down
4 changes: 2 additions & 2 deletions doc/source/Contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ to create issues to report bugs and request new features.

View documentation
-------------------
Documentation for the latest stable release is hosted at `Motor Segmentation Toolkit documentation <https://aedt.motor.toolkit.docs.pyansys.com/version/stable/>`_.
Documentation for the latest stable release is hosted at `Common PyAEDT Toolkit documentation <https://aedt.common.toolkit.docs.pyansys.com/version/stable/>`_.

In the upper right corner of the documentation’s title bar, there is an option for switching from viewing
the documentation for the latest stable release to viewing the documentation for the development version
Expand All @@ -37,7 +37,7 @@ Adhere to code style
--------------------
The Motor Segmentation Toolkit is compliant with `PyAnsys code style
<https://dev.docs.pyansys.com/coding-style/index.html>`_. It uses the tool
`pre-commit <https://pre-commit.com/>`_ to check the code style.
`pre-commit <https://pre-commit.com/>`_ to select the code style.

You can install and activate this tool with these commands:

Expand Down
4 changes: 2 additions & 2 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Motor Segmentation Toolkit documentation |version|
==================================================
Common PyAEDT Toolkit documentation |version|
=============================================

..
Simply reuse the root readme
Expand Down
8 changes: 5 additions & 3 deletions examples/backend/api_aedt_connect_session_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
sessions = toolkit.aedt_sessions()

# Find if it is COM or GRPC
if sessions[0][1] == -1:
first_key, first_value = next(iter(sessions.items()))

if first_value == -1:
use_grpc = False
selected_process = sessions[0][0]
selected_process = first_key
else:
use_grpc = True
selected_process = sessions[0][1]
selected_process = first_value

# Set properties
new_properties = {"selected_process": selected_process, "use_grpc": use_grpc}
Expand Down
15 changes: 10 additions & 5 deletions examples/toolkit/pyaedt_toolkit/backend/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ToolkitBackend(AEDTCommon):
def __init__(self):
"""Initialize the ``Toolkit`` class."""
AEDTCommon.__init__(self, properties)
self.properties = properties
self.multiplier = 1.0

def create_geometry(self):
Expand Down Expand Up @@ -58,15 +59,19 @@ def create_geometry(self):
self.connect_design()

if self.aedtapp:
multiplier = properties.multiplier
geometry = properties.geometry
multiplier = self.properties.multiplier
geometry = self.properties.geometry
self.multiplier = multiplier
prim = None
if geometry == "Box":
self.draw_box()
prim = self.draw_box()
elif geometry == "Sphere":
self.draw_sphere()
prim = self.draw_sphere()
if not prim:
logger.error("Primitive not created")
return False
self.release_aedt(False, False)
return True
return prim.name
logger.error("Design not connected")
return False

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
from api import ToolkitBackend
from ansys.aedt.toolkits.common.backend.multithreading_server import MultithreadingServer
from ansys.aedt.toolkits.common.backend.rest_api import app
from ansys.aedt.toolkits.common.backend.rest_api import jsonify
from ansys.aedt.toolkits.common.backend.rest_api import logger

toolkit_api = ToolkitBackend()
from ansys.aedt.toolkits.common.backend.rest_api import toolkit_api


@app.route("/create_geometry", methods=["POST"])
def create_geometry_call():
logger.info("[POST] /create_geometry (create a box or sphere in HFSS)")
def create_geometry():
logger.info("[POST] /create_geometry (create a box or sphere in HFSS).")

response = toolkit_api.create_geometry()
if response:
return jsonify("Geometry created"), 200
return response, 200
else:
return jsonify("Geometry not created"), 500

Expand Down
4 changes: 2 additions & 2 deletions examples/toolkit/pyaedt_toolkit/run_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import backend

# Define global variables or constants
BACKEND_FILE = os.path.join(backend.__path__[0], "rest_api.py")
FRONTEND_FILE = os.path.join(ui.__path__[0], "run.py")
BACKEND_FILE = os.path.join(backend.__path__[0], "run_backend.py")
FRONTEND_FILE = os.path.join(ui.__path__[0], "run_frontend.py")
IS_LINUX = os.name == "posix"
URL = properties.backend_url
PORT = properties.backend_port
Expand Down
8 changes: 6 additions & 2 deletions examples/toolkit/pyaedt_toolkit/ui/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ def create_geometry_toolkit(self, project_selected=None, design_selected=None, g
if project_selected == "No Project":
project_selected = generate_unique_project_name()
project_selected = self.get_project_name(project_selected)
be_properties["active_project"] = project_selected

for project in be_properties["project_list"]:
if self.get_project_name(project) == project_selected:
be_properties["active_project"] = project
if project_selected in list(be_properties["design_list"].keys()):
designs = be_properties["design_lis"][project_selected]
designs = be_properties["design_list"][project_selected]
for design in designs:
if design_selected == design:
be_properties["active_design"] = design
Expand All @@ -30,15 +31,18 @@ def create_geometry_toolkit(self, project_selected=None, design_selected=None, g
else:
project_selected = generate_unique_project_name()
project_selected = self.get_project_name(project_selected)
be_properties["active_project"] = project_selected

# Multiplier and geometry
be_properties["multiplier"] = float(multiplier)
be_properties["geometry"] = geometry
be_properties["active_project"] = project_selected

self.set_properties(be_properties)

response = requests.post(self.url + "/create_geometry")

self.properties.primitives_created.append(response.text)

if response.ok:
msg = "Geometry created."
logger.info(msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"copyright" : "By: slopez",
"year" : 2023,
"theme" : "ansys.json",
"high_resolution": false,
"high_resolution": true,
"add_left_menus" : [
{
"btn_icon": "icon_home.svg",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def __init__(self, app, selected_project, selected_design, geometry, multiplier)
self.multiplier = multiplier

def run(self):
self.app.ui.progress.progress = 50
import time

time.sleep(1)
success = self.app.create_geometry_toolkit(
self.selected_project, self.selected_design, self.geometry, self.multiplier
)
Expand Down Expand Up @@ -162,6 +166,9 @@ def geometry_button_clicked(self):
)
self.geometry_thread.finished_signal.connect(self.geometry_created_finished)

msg = "Creating geometry."
self.ui.logger.log(msg)

self.geometry_thread.start()

else:
Expand All @@ -180,4 +187,4 @@ def geometry_created_finished(self, success):
self.ui.logger.log(msg)
else:
msg = f"Failed backend call: {self.app.url}"
self.ui.logger.error(msg)
self.ui.logger.log(msg)
Loading

0 comments on commit 0cd5218

Please sign in to comment.