Skip to content

Download error page and helper #1283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions doc/source/examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,24 @@ Here are a series of examples using MAPDL with ``ansys-mapdl-core``.
.. include:: extended_examples/index.rst
:start-line: 2


.. === DOWNLOAD EXAMPLES ===

.. _ref_download_files:

Download Example Files
======================

Each example should contain all the necessary resources to run the example.
However in some cases, external files are needed. A link to those files is
available at each example page.
These links refers to the following GitHub repository where you can find all of them:

`GitHub Example Data Repository <https://github.com/pyansys/example-data>`_

If you find out a missing or broken link, please open an issue in
Github (`PyMAPDL Issues <https://github.com/pyansys/pymapdl/issues>`_)
or email us at `PyAnsys Support <[email protected]>`_.



12 changes: 11 additions & 1 deletion src/ansys/mapdl/core/examples/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,17 @@ def _retrieve_file(url, filename):

def _download_file(filename, directory=None):
url = _get_file_url(filename, directory)
return _retrieve_file(url, filename)
try:
return _retrieve_file(url, filename)
except Exception as e: # Genering exception
raise RuntimeError(
"For the reason mentioned below, retrieving the file from internet failed.\n"
"You can download this file from:\n"
f"{url}\n"
"\n"
"The reported error message is:\n"
f"{str(e)}"
)


def download_bracket():
Expand Down
10 changes: 9 additions & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os
import re

import pytest

from ansys.mapdl.core import examples
from ansys.mapdl.core.examples.downloads import download_example_data
from ansys.mapdl.core.examples.downloads import _download_file, download_example_data


def test_load_verif():
Expand All @@ -25,3 +27,9 @@ def test_bracket(mapdl, cleared):
def test_download_example_data():
path = download_example_data("LatheCutter.anf", "geometry")
assert os.path.exists(path)


def test_failed_download():
filename = "non_existing_file"
with pytest.raises(RuntimeError):
_download_file(filename, directory=None)