# Utility functions for python tests that download their own (DICOM or other) data from the web

**URL:** <https://discourse.slicer.org/t/utility-functions-for-python-tests-that-download-their-own-dicom-or-other-data-from-the-web/1330>\
**Category:** Development\
**Created:** [October 31, 2017, 2:29pm UTC](https://discourse.slicer.org/t/utility-functions-for-python-tests-that-download-their-own-dicom-or-other-data-from-the-web/1330 "2017-10-31T14:29:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [October 31, 2017, 2:29pm UTC](https://discourse.slicer.org/t/utility-functions-for-python-tests-that-download-their-own-dicom-or-other-data-from-the-web/1330/1 "2017-10-31T14:29:12Z")

</div>

I’m writing a few new automated python tests for extensions, and realized that I keep adding the same functions in my tests unchanged. These functions

- Download data, unzip to temp folder, verify total number of unzipped files
- Import data to temporary DICOM database from the above folder
- Select loadables, verify plugin selection, and load loadables

Do you think it would make sense to add these in the ScriptedLoadableModuleTest class?

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [October 31, 2017, 2:34pm UTC](https://discourse.slicer.org/t/utility-functions-for-python-tests-that-download-their-own-dicom-or-other-data-from-the-web/1330/2 "2017-10-31T14:34:13Z")

</div>

It could be added to the `slicer.testing` module.

Ideally, it could be used as a function or a context manager.

something like:

```auto
with TemporaryDICOMData(url="http://path/to/file.zip") as loader:
  assert loader.selected_plugins == ["plugin1", ...]
  [...]

```

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [October 31, 2017, 6:46pm UTC](https://discourse.slicer.org/t/utility-functions-for-python-tests-that-download-their-own-dicom-or-other-data-from-the-web/1330/3 "2017-10-31T18:46:47Z")

</div>

Thanks! I’ll try to do it like this then. I’ll be back with a PR.

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [November 6, 2017, 8:53pm UTC](https://discourse.slicer.org/t/utility-functions-for-python-tests-that-download-their-own-dicom-or-other-data-from-the-web/1330/4 "2017-11-06T20:53:42Z")

</div>

I think I’ll add this to [https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/DICOMLib/DICOMUtils.py](https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/DICOMLib/DICOMUtils.py) instead. There is a feature very similar to the proposed one here already, and it would be confusing to separate them.

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [November 8, 2017, 9:36pm UTC](https://discourse.slicer.org/t/utility-functions-for-python-tests-that-download-their-own-dicom-or-other-data-from-the-web/1330/5 "2017-11-08T21:36:31Z")

</div>

I issued the pull request: [https://github.com/Slicer/Slicer/pull/835](https://github.com/Slicer/Slicer/pull/835)

I tested it with SubjectHierarchyGenericSelfTest and GelDosimetryAnalysis, both work well.
