Skip to content

Commit 8b9e5f2

Browse files
germa89akaszynski
andauthored
Download error page and helper (#1283)
* Improving exception message when error found. * Adding unit test. * Adding documentation. * Apply suggestions from code review Co-authored-by: Alex Kaszynski <[email protected]>
1 parent ddcbb76 commit 8b9e5f2

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

doc/source/examples/index.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,24 @@ Here are a series of examples using MAPDL with ``ansys-mapdl-core``.
4343
.. include:: extended_examples/index.rst
4444
:start-line: 2
4545

46+
47+
.. === DOWNLOAD EXAMPLES ===
48+
49+
.. _ref_download_files:
50+
51+
Download Example Files
52+
======================
53+
54+
Each example should contain all the necessary resources to run the example.
55+
However in some cases, external files are needed. A link to those files is
56+
available at each example page.
57+
These links refers to the following GitHub repository where you can find all of them:
58+
59+
`GitHub Example Data Repository <https://github.com/pyansys/example-data>`_
60+
61+
If you find out a missing or broken link, please open an issue in
62+
Github (`PyMAPDL Issues <https://github.com/pyansys/pymapdl/issues>`_)
63+
or email us at `PyAnsys Support <[email protected]>`_.
64+
65+
66+

src/ansys/mapdl/core/examples/downloads.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,17 @@ def _retrieve_file(url, filename):
5656

5757
def _download_file(filename, directory=None):
5858
url = _get_file_url(filename, directory)
59-
return _retrieve_file(url, filename)
59+
try:
60+
return _retrieve_file(url, filename)
61+
except Exception as e: # Genering exception
62+
raise RuntimeError(
63+
"For the reason mentioned below, retrieving the file from internet failed.\n"
64+
"You can download this file from:\n"
65+
f"{url}\n"
66+
"\n"
67+
"The reported error message is:\n"
68+
f"{str(e)}"
69+
)
6070

6171

6272
def download_bracket():

tests/test_examples.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
22
import re
33

4+
import pytest
5+
46
from ansys.mapdl.core import examples
5-
from ansys.mapdl.core.examples.downloads import download_example_data
7+
from ansys.mapdl.core.examples.downloads import _download_file, download_example_data
68

79

810
def test_load_verif():
@@ -25,3 +27,9 @@ def test_bracket(mapdl, cleared):
2527
def test_download_example_data():
2628
path = download_example_data("LatheCutter.anf", "geometry")
2729
assert os.path.exists(path)
30+
31+
32+
def test_failed_download():
33+
filename = "non_existing_file"
34+
with pytest.raises(RuntimeError):
35+
_download_file(filename, directory=None)

0 commit comments

Comments
 (0)