Skip to content

Commit

Permalink
test: including _commands in coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
germa89 committed Oct 21, 2024
1 parent c7ada76 commit 86d1990
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 57 deletions.
1 change: 0 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ignore:
- "src/ansys/mapdl/core/_commands"
- "src/ansys/mapdl/core/jupyter.py"
- "src/ansys/mapdl/core/mapdl_console.py"
- "src/ansys/mapdl/core/mapdl_inprocess.py"
Expand Down
114 changes: 58 additions & 56 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# SOFTWARE.

import inspect
from unittest.mock import patch

import numpy as np
import pytest
Expand All @@ -39,6 +38,9 @@
from ansys.mapdl.core.examples import verif_files
from conftest import has_dependency, requires

# from unittest.mock import patch


if has_dependency("pandas"):
import pandas as pd

Expand Down Expand Up @@ -1075,58 +1077,58 @@ def fake_wrap(*args, **kwags):

MAPDL_cmds = [each for each in dir(Commands) if not each.startswith("_")]

@pytest.mark.parametrize("cmd", MAPDL_cmds)
@patch("ansys.mapdl.core.mapdl_grpc.MapdlGrpc._send_command", fake_wrap)
# Skip post processing the plot in PLESOL commands like.
@patch("ansys.mapdl.core.mapdl_core.PLOT_COMMANDS", [])
# skip retrieving value
@patch("ansys.mapdl.core.mapdl_grpc.MapdlGrpc.scalar_param", fake_wrap)
# Skip output the entity id after geometry manipulation
@patch("ansys.mapdl.core._commands.parse.parse_a", fake_wrap)
@patch("ansys.mapdl.core._commands.parse.parse_e", fake_wrap)
@patch("ansys.mapdl.core._commands.parse.parse_et", fake_wrap)
@patch("ansys.mapdl.core._commands.parse.parse_k", fake_wrap)
@patch("ansys.mapdl.core._commands.parse.parse_knode", fake_wrap)
@patch("ansys.mapdl.core._commands.parse.parse_kdist", fake_wrap)
@patch("ansys.mapdl.core._commands.parse.parse_kl", fake_wrap)
@patch("ansys.mapdl.core._commands.parse.parse_kpoint", fake_wrap)
@patch("ansys.mapdl.core._commands.parse.parse_line_no", fake_wrap)
@patch("ansys.mapdl.core._commands.parse.parse_line_nos", fake_wrap)
@patch("ansys.mapdl.core._commands.parse.parse_n", fake_wrap)
@patch("ansys.mapdl.core._commands.parse.parse_ndist", fake_wrap)
@patch("ansys.mapdl.core._commands.parse.parse_output_areas", fake_wrap)
@patch("ansys.mapdl.core._commands.parse.parse_output_volume_area", fake_wrap)
@patch("ansys.mapdl.core._commands.parse.parse_v", fake_wrap)
def test_command(self, mapdl, cmd):
func = getattr(mapdl, cmd)

# Avoid wraps
while hasattr(func, "__wrapped__"):
func = func.__wrapped__

if cmd in self.SKIP:
pytest.skip("This function is overwritten in a subclass.")

parm = inspect.signature(func).parameters
assert "kwargs" in parm, "'kwargs' argument is missing in function signature."

args = [f"arg{i}" for i in range(len(parm) - 1)] # 3 = self, cmd, kwargs

if list(parm)[0].lower() == "self":
args = args[:-1]
post = func(mapdl, *args)
else:
post = func(*args)

for arg in args:
assert arg in post

# assert ",".join(args) in post.replace(",,", ",").replace(" ", "")
cmd_ = cmd.upper()
if cmd_.startswith("SLASH"):
cmd_ = cmd_.replace("SLASH_", "/").replace("SLASH", "/")

if cmd_.startswith("STAR"):
cmd_ = cmd_.replace("STAR", "*")

assert cmd_ in post.upper()
# @pytest.mark.parametrize("cmd", MAPDL_cmds)
# @patch("ansys.mapdl.core.mapdl_grpc.MapdlGrpc._send_command", fake_wrap)
# # Skip post processing the plot in PLESOL commands like.
# @patch("ansys.mapdl.core.mapdl_core.PLOT_COMMANDS", [])
# # skip retrieving value
# @patch("ansys.mapdl.core.mapdl_grpc.MapdlGrpc.scalar_param", fake_wrap)
# # Skip output the entity id after geometry manipulation
# @patch("ansys.mapdl.core._commands.parse.parse_a", fake_wrap)
# @patch("ansys.mapdl.core._commands.parse.parse_e", fake_wrap)
# @patch("ansys.mapdl.core._commands.parse.parse_et", fake_wrap)
# @patch("ansys.mapdl.core._commands.parse.parse_k", fake_wrap)
# @patch("ansys.mapdl.core._commands.parse.parse_knode", fake_wrap)
# @patch("ansys.mapdl.core._commands.parse.parse_kdist", fake_wrap)
# @patch("ansys.mapdl.core._commands.parse.parse_kl", fake_wrap)
# @patch("ansys.mapdl.core._commands.parse.parse_kpoint", fake_wrap)
# @patch("ansys.mapdl.core._commands.parse.parse_line_no", fake_wrap)
# @patch("ansys.mapdl.core._commands.parse.parse_line_nos", fake_wrap)
# @patch("ansys.mapdl.core._commands.parse.parse_n", fake_wrap)
# @patch("ansys.mapdl.core._commands.parse.parse_ndist", fake_wrap)
# @patch("ansys.mapdl.core._commands.parse.parse_output_areas", fake_wrap)
# @patch("ansys.mapdl.core._commands.parse.parse_output_volume_area", fake_wrap)
# @patch("ansys.mapdl.core._commands.parse.parse_v", fake_wrap)
# def test_command(self, mapdl, cmd):
# func = getattr(mapdl, cmd)

# # Avoid wraps
# while hasattr(func, "__wrapped__"):
# func = func.__wrapped__

# if cmd in self.SKIP:
# pytest.skip("This function is overwritten in a subclass.")

# parm = inspect.signature(func).parameters
# assert "kwargs" in parm, "'kwargs' argument is missing in function signature."

# args = [f"arg{i}" for i in range(len(parm) - 1)] # 3 = self, cmd, kwargs

# if list(parm)[0].lower() == "self":
# args = args[:-1]
# post = func(mapdl, *args)
# else:
# post = func(*args)

# for arg in args:
# assert arg in post

# # assert ",".join(args) in post.replace(",,", ",").replace(" ", "")
# cmd_ = cmd.upper()
# if cmd_.startswith("SLASH"):
# cmd_ = cmd_.replace("SLASH_", "/").replace("SLASH", "/")

# if cmd_.startswith("STAR"):
# cmd_ = cmd_.replace("STAR", "*")

# assert cmd_ in post.upper()

0 comments on commit 86d1990

Please sign in to comment.