Skip to content

Commit

Permalink
tests: making sure the full and rst files exists before running the t…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
germa89 committed Jan 15, 2025
1 parent 8cf4cf8 commit 6edbcb5
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions tests/test_xpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,54 @@ def check_supports_extract(mapdl):


class Test_xpl:
full_file = None

@staticmethod
@pytest.fixture(scope="class")
def cube_solve(mapdl):
def create_cube(self, mapdl):
from conftest import clear

clear(mapdl)

# set up the full file
mapdl.block(0, 1, 0, 1, 0, 1)
mapdl.et(1, 186)
mapdl.esize(0.5)
mapdl.vmesh("all")

# Define a material (nominal steel in SI)
mapdl.mp("EX", 1, 210e9) # Elastic modulus in Pa (kg/(m*s**2))
mapdl.mp("DENS", 1, 7800) # Density in kg/m3
mapdl.mp("NUXY", 1, 0.3) # Poisson's Ratio

mapdl.esize(0.5)
mapdl.vmesh("all")

# Delete files
self.full_file = mapdl.jobname + ".full"
if "full.file" in mapdl.list_files():
mapdl.slashdelete("full.file")

if mapdl.result_file in mapdl.list_files():
mapdl.slashdelete(mapdl.result_file)

if mapdl.result_file in mapdl.list_files():
mapdl.slashdelete(mapdl.result_file)

# solve first 10 non-trivial modes
mapdl.modal_analysis(nmode=10, freqb=1)
mapdl.save("cube_solve_xpl")

@staticmethod
@pytest.fixture(scope="class")
def cube_solve(self, mapdl):
self.create_cube(mapdl)

@pytest.fixture(scope="function")
def xpl(mapdl, cube_solve):
def xpl(self, mapdl, cube_solve):
mapdl.prep7()
mapdl.resume("cube_solve_xpl")

xpl = mapdl.xpl
xpl.open("file.full")
if not self.full_file and not self.full_file in mapdl.list_files():
self.create_cube(mapdl)

xpl.open(self.full_file)
return xpl

@staticmethod
Expand Down Expand Up @@ -116,6 +132,9 @@ def test_save(xpl):
@staticmethod
def test_copy(mapdl, cleared, xpl):
filename = "tmpfile.full"
if filename in mapdl.list_files():
mapdl.slashdelete(filename)

xpl.copy(filename)
assert filename in mapdl.list_files()

Expand Down Expand Up @@ -163,19 +182,18 @@ def test_goto(xpl):
xpl.goto("MASS")
assert "Current Location : FULL::MASS" in xpl.where()

@staticmethod
@requires("ansys-math-core")
@pytest.mark.usefixtures("check_supports_extract")
def test_extract(xpl):
def test_extract(self, xpl):
# expecting fixture to already have a non-result file open
assert xpl._filename[-3:] != "rst"
with pytest.raises(MapdlRuntimeError, match="result files"):
mat = xpl.extract("NSL")

xpl.open("file.rst")
xpl.open(xpl._mapdl.result_file)

with pytest.raises(ValueError, match="the only supported recordname is 'NSL'"):
xpl.extract("NOD")

mat = xpl.extract("NSL")
assert mat.shape == (243, 10)
assert mat.shape == (13851, 10)

0 comments on commit 6edbcb5

Please sign in to comment.