Skip to content

Commit 18df5b2

Browse files
authored
add Doctest in pipelines (#103)
* update pipelines * update doc strings
1 parent b3df360 commit 18df5b2

15 files changed

+222
-85
lines changed

.ci/azure-pipelines.yml

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,49 @@ jobs:
4444

4545
- script: |
4646
pip install -r requirements_test.txt
47+
displayName: Install Test Environment
48+
49+
- script: |
4750
set THISDIR=$(System.DefaultWorkingDirectory)
48-
cd tests=$(System.DefaultWorkingDirectory)
51+
cd tests
4952
set AWP_ROOT212=%THISDIR%\server\v212
5053
pytest -v --junitxml=junit/test-results.xml --cov ansys.dpf.core --cov-report=xml --reruns 3
5154
5255
displayName: Test Core API
53-
56+
timeoutInMinutes: 10
57+
5458
- task: PublishTestResults@2
5559
inputs:
5660
testResultsFormat: 'JUnit'
57-
testResultsFiles: 'junit/test-results.xml'
61+
testResultsFiles: 'tests/junit/test-results.xml'
5862
testRunTitle: 'windowsTests'
59-
publishRunAttachments: true
63+
publishRunAttachments: true
6064
condition: always()
61-
65+
66+
- script: |
67+
set THISDIR=$(System.DefaultWorkingDirectory)
68+
cd $(System.DefaultWorkingDirectory)
69+
set AWP_ROOT212=%THISDIR%\server\v212
70+
pytest --doctest-modules --junitxml=junit/test-doctests-results.xml ansys\dpf\core
71+
condition: always()
72+
displayName: Test API Docstrings
73+
timeoutInMinutes: 5
74+
75+
- task: PublishTestResults@2
76+
inputs:
77+
testResultsFormat: 'JUnit'
78+
testResultsFiles: 'junit/test-doctests-results.xml'
79+
testRunTitle: 'docTestsTests'
80+
publishRunAttachments: true
81+
condition: always()
82+
83+
- script: |
84+
set THISDIR=$(System.DefaultWorkingDirectory)
85+
set AWP_ROOT212=%THISDIR%\server\v212
86+
python .ci/run_examples.py
87+
displayName: 'Run example scripts'
88+
timeoutInMinutes: 5
89+
6290
- script: |
6391
pip install twine
6492
python setup.py sdist

.ci/run_examples.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os
2+
import glob
3+
import pathlib
4+
from ansys.dpf import core
5+
6+
core.disable_off_screen_rendering()
7+
8+
actual_path = pathlib.Path(__file__).parent.absolute()
9+
print(os.path.join(actual_path, os.path.pardir, "examples"))
10+
for root, subdirectories, files in os.walk(os.path.join(actual_path, os.path.pardir, "examples")):
11+
for subdirectory in subdirectories:
12+
subdir = os.path.join(root, subdirectory)
13+
for file in glob.iglob(os.path.join(subdir, "*.py")):
14+
print("\n\n--------------------------------------------------\n")
15+
print(file)
16+
print("--------------------------------------------------\n")
17+
exec(
18+
open(file, mode="r", encoding="utf8").read(),
19+
globals(),
20+
globals())

ansys/dpf/core/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,16 @@
104104
SERVER = None
105105

106106
_server_instances = []
107+
108+
def disable_off_screen_rendering() -> None:
109+
# enable matplotlib off_screen plotting to avoid test interruption
110+
if module_exists("matplotlib"):
111+
import matplotlib as mpl
112+
113+
mpl.use("Agg")
114+
115+
# enable off_screen plotting to avoid test interruption
116+
if module_exists("pyvista"):
117+
import pyvista as pv
118+
119+
pv.OFF_SCREEN = True

ansys/dpf/core/aeneid.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

ansys/dpf/core/custom_fields_container.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,13 @@ def solid_fields(self, timeid=None, complexid=None):
6363
6464
Examples
6565
--------
66+
>>> from ansys.dpf import core as dpf
67+
>>> from ansys.dpf.core import examples
68+
>>> model = dpf.Model(examples.download_all_kinds_of_complexity_modal())
69+
>>> fc = model.results.displacement.split_by_shape.eval()
6670
>>> len(fc.solid_fields())
67-
45
68-
>>> len(fc.solid_fields(timeid=3))
71+
1
72+
>>> len(fc.solid_fields(timeid=1))
6973
1
7074
7175
"""
@@ -94,6 +98,10 @@ def shell_fields(self, timeid=None, complexid=None):
9498
9599
Examples
96100
--------
101+
>>> from ansys.dpf import core as dpf
102+
>>> from ansys.dpf.core import examples
103+
>>> model = dpf.Model(examples.download_all_kinds_of_complexity_modal())
104+
>>> fc = model.results.displacement.on_all_time_freqs.split_by_shape.eval()
97105
>>> len(fc.shell_fields())
98106
45
99107
>>> len(fc.shell_fields(timeid=3))
@@ -125,6 +133,10 @@ def beam_fields(self, timeid=None, complexid=None):
125133
126134
Examples
127135
--------
136+
>>> from ansys.dpf import core as dpf
137+
>>> from ansys.dpf.core import examples
138+
>>> model = dpf.Model(examples.download_all_kinds_of_complexity_modal())
139+
>>> fc = model.results.displacement.on_all_time_freqs.split_by_shape.eval()
128140
>>> len(fc.beam_fields())
129141
45
130142
>>> len(fc.beam_fields(timeid=3))
@@ -156,6 +168,10 @@ def solid_field(self, timeid=None, complexid=None):
156168
157169
Examples
158170
--------
171+
>>> from ansys.dpf import core as dpf
172+
>>> from ansys.dpf.core import examples
173+
>>> model = dpf.Model(examples.download_all_kinds_of_complexity_modal())
174+
>>> fc = model.results.displacement.on_all_time_freqs.split_by_shape.eval()
159175
>>> field = fc.solid_field(timeid=3)
160176
161177
"""
@@ -185,6 +201,10 @@ def shell_field(self, timeid=None, complexid=None):
185201
186202
Examples
187203
--------
204+
>>> from ansys.dpf import core as dpf
205+
>>> from ansys.dpf.core import examples
206+
>>> model = dpf.Model(examples.download_all_kinds_of_complexity_modal())
207+
>>> fc = model.results.displacement.on_all_time_freqs.split_by_shape.eval()
188208
>>> field = fc.shell_field(timeid=3)
189209
190210
"""
@@ -213,6 +233,10 @@ def beam_field(self, timeid=None, complexid=None):
213233
214234
Examples
215235
--------
236+
>>> from ansys.dpf import core as dpf
237+
>>> from ansys.dpf.core import examples
238+
>>> model = dpf.Model(examples.download_all_kinds_of_complexity_modal())
239+
>>> fc = model.results.displacement.on_all_time_freqs.split_by_shape.eval()
216240
>>> field = fc.beam_field(timeid=3)
217241
218242
"""
@@ -280,6 +304,10 @@ def get_fields_by_mat_id(self, matid, timeid=None, complexid=None):
280304
281305
Examples
282306
--------
307+
>>> from ansys.dpf import core as dpf
308+
>>> from ansys.dpf.core import examples
309+
>>> model = dpf.Model(examples.download_all_kinds_of_complexity_modal())
310+
>>> fc = model.results.displacement.on_all_time_freqs.split_by_body.eval()
283311
>>> len(fc.get_fields_by_mat_id(1))
284312
45
285313
>>> len(fc.get_fields_by_mat_id(1, timeid=3))
@@ -313,6 +341,10 @@ def get_field_by_mat_id(self, matid, timeid=None, complexid=None):
313341
314342
Examples
315343
--------
344+
>>> from ansys.dpf import core as dpf
345+
>>> from ansys.dpf.core import examples
346+
>>> model = dpf.Model(examples.download_all_kinds_of_complexity_modal())
347+
>>> fc = model.results.displacement.on_all_time_freqs.split_by_body.eval()
316348
>>> f_time_2 = fc.get_field_by_mat_id(45, timeid=2)
317349
318350
"""

ansys/dpf/core/dpf_operator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ def _add_sub_res_operators(self, sub_results):
9191
9292
Examples
9393
--------
94+
>>> from ansys.dpf.core import Model
95+
>>> from ansys.dpf.core import examples
96+
>>> model = Model(examples.static_rst)
97+
>>> disp_oper = model.results.displacement()
9498
>>> disp_oper = model.results.displacement()
9599
>>> disp_x = model.results.displacement().X()
96100
>>> disp_y = model.results.displacement().Y()

ansys/dpf/core/elements.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ def node_ids(self):
6565
6666
Examples
6767
--------
68+
>>> import ansys.dpf.core as dpf
69+
>>> from ansys.dpf.core import examples
70+
>>> model = dpf.Model(examples.static_rst)
71+
>>> elements = model.metadata.meshed_region.elements
72+
>>> element = elements[0]
6873
>>> element.node_ids
6974
[1, 26, 14, 12, 2, 27, 15, 13, 33, 64, 59, 30, 37, 65, 61, 34, 28, 81, 63, 58]
7075
@@ -105,6 +110,11 @@ def nodes(self):
105110
106111
Examples
107112
--------
113+
>>> import ansys.dpf.core as dpf
114+
>>> from ansys.dpf.core import examples
115+
>>> model = dpf.Model(examples.static_rst)
116+
>>> elements = model.metadata.meshed_region.elements
117+
>>> element = elements[0]
108118
>>> first_node = element.nodes[0]
109119
110120
"""
@@ -142,6 +152,11 @@ def type(self) -> int:
142152
143153
Examples
144154
--------
155+
>>> import ansys.dpf.core as dpf
156+
>>> from ansys.dpf.core import examples
157+
>>> model = dpf.Model(examples.static_rst)
158+
>>> elements = model.metadata.meshed_region.elements
159+
>>> element = elements[0]
145160
>>> element.type
146161
<element_types.Hex20: 1>
147162
@@ -170,6 +185,11 @@ def shape(self) -> str:
170185
171186
Examples
172187
--------
188+
>>> import ansys.dpf.core as dpf
189+
>>> from ansys.dpf.core import examples
190+
>>> model = dpf.Model(examples.static_rst)
191+
>>> elements = model.metadata.meshed_region.elements
192+
>>> element = elements[0]
173193
>>> element.shape
174194
'solid'
175195
@@ -434,6 +454,10 @@ def scoping(self) -> scoping.Scoping:
434454
435455
Examples
436456
--------
457+
>>> import ansys.dpf.core as dpf
458+
>>> from ansys.dpf.core import examples
459+
>>> model = dpf.Model(examples.static_rst)
460+
>>> elements = model.metadata.meshed_region.elements
437461
>>> my_scoping = elements.scoping
438462
439463
"""
@@ -450,6 +474,10 @@ def element_types_field(self):
450474
451475
Examples
452476
--------
477+
>>> import ansys.dpf.core as dpf
478+
>>> from ansys.dpf.core import examples
479+
>>> model = dpf.Model(examples.static_rst)
480+
>>> elements = model.metadata.meshed_region.elements
453481
>>> field = elements.element_types_field
454482
>>> field.data
455483
array([1, 1, 1, 1, 1, 1, 1, 1])
@@ -476,6 +504,10 @@ def materials_field(self):
476504
--------
477505
Extract the material IDs from the materials_field
478506
507+
>>> import ansys.dpf.core as dpf
508+
>>> from ansys.dpf.core import examples
509+
>>> model = dpf.Model(examples.static_rst)
510+
>>> elements = model.metadata.meshed_region.elements
479511
>>> elements.materials_field.data
480512
array([1, 1, 1, 1, 1, 1, 1, 1])
481513
@@ -498,6 +530,10 @@ def connectivities_field(self):
498530
499531
Examples
500532
--------
533+
>>> import ansys.dpf.core as dpf
534+
>>> from ansys.dpf.core import examples
535+
>>> model = dpf.Model(examples.static_rst)
536+
>>> elements = model.metadata.meshed_region.elements
501537
>>> field = elements.connectivities_field
502538
>>> field.get_entity_data(1)
503539
array([ 0, 11, 13, 25, 2, 9, 8, 3, 29, 58, 63, 32, 40, 52, 42, 37, 28,
@@ -535,8 +571,11 @@ def mapping_id_to_index(self) -> dict:
535571
536572
Examples
537573
--------
538-
>>> meshed_region.nodes.mapping_id_to_index
539-
{1: 0, 2: 1, 3: 2, 4: 3}
574+
>>> import ansys.dpf.core as dpf
575+
>>> from ansys.dpf.core import examples
576+
>>> model = dpf.Model(examples.simple_bar)
577+
>>> meshed_region = model.metadata.meshed_region
578+
>>> map = meshed_region.nodes.mapping_id_to_index
540579
541580
"""
542581
if self._mapping_id_to_index is None:

0 commit comments

Comments
 (0)