Repository: gammapy/gammapy

Issue:
Sphinx build warnings with `astropy.utils.data.get_pkg_data_filename`
I'm using `astropy.utils.data.get_pkg_data_filename` in a few places in `tevpy` (see [here](https://github.com/gammapy/tevpy/search?q=get_pkg_data_filename&ref=cmdform&type=Code)).

This causes four `tevpy` Sphinx build warnings:

```
building [html]: all source files
updating environment: 126 added, 0 changed, 0 removed
reading sources... [100%] tevpy/utils/index                                    rocity
/Users/deil/code/tevpy/docs/tevpy/detect/index.rst:85: WARNING: toctree references unknown document u'_generated/astropy.utils.data.get_pkg_data_filename'
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] tevpy/utils/index                                     ocity
None:None: WARNING: toctree contains reference to nonexisting document '_generated/astropy.utils.data.get_pkg_data_filename'
<autosummary>:None: WARNING: toctree contains reference to nonexisting document '_generated/astropy.utils.data.get_pkg_data_filename'
None:None: WARNING: toctree contains reference to nonexisting document '_generated/astropy.utils.data.get_pkg_data_filename'
writing additional files... (31 module code pages) _modules/index
 genindex py-modindex np-modindex search
copying static files... done
dumping search index... done
dumping object inventory... done
build succeeded, 4 warnings.
```

It's annoying because it makes the travis-ci sphinx build fail:
https://travis-ci.org/gammapy/tevpy/jobs/9869684#L686

@eteq @astrofrog @iguananaut Do you know why this is happening? How can I fix it?



Discussion:

Resolving patch:
diff --git a/gammapy/astro/snr.py b/gammapy/astro/snr.py
--- a/gammapy/astro/snr.py
+++ b/gammapy/astro/snr.py
@@ -21,6 +21,7 @@
 DEFAULT_THETA = 0.1
 DEFAULT_M = M_SUN
 
+
 class SNR(object):
     """Supernova remnant (SNR) evolution models.
 
@@ -69,7 +70,7 @@ def r_out(self, t):
 
         # proportional constant for the free expansion phase
         term1 = (self.E_SN / self.E_SN_ref) ** (1. / 2)
-        term2 = (self.m / self.m_ref) ** (-1. / 2) 
+        term2 = (self.m / self.m_ref) ** (-1. / 2)
         A = 0.01 * term1 * term2
         # The proportional constant for the sedov phase is choosen such,
         # that the function is continuous at tf.
@@ -94,12 +95,14 @@ def r_in(self, t):
         return self.r_out(t) * (1 - 0.0914)
 
     def r_free_expansion(self, t):
-        """Reverse shock radius (pc) at age t (yr)
-        during free expansion phase"""
+        """
+        Shock radius (pc) at age t (yr) during free expansion phase.
+        """
         return 1.12 * self.r_c * (t / self.t_c) ** (2. / 3)
 
     def r_reverse(self, t):
-        """Reverse shock radius (pc) at age t (yr)
+        """
+        Reverse shock radius (pc) at age t (yr).
 
         Reference: Gelfand & Slane 2009, Appendix A.
         """
@@ -107,7 +110,7 @@ def r_reverse(self, t):
         t = YEAR_TO_SEC * t
         # Time when reverse shock reaches the "core"
         t_core = 0.25 * self.t_c
-        
+
         term1 = (t - t_core) / (self.t_c)
         term2 = (1.49 - 0.16 * term1 - 0.46 * log(t / t_core))
         R_1 = self.r_free_expansion(t) / 1.19
@@ -142,7 +145,7 @@ def L(self, t):
     def _t_start(self):
         term1 = 200 * (self.E_SN / self.E_SN_ref) ** (-1. / 2)
         term2 = (self.m / self.m_ref) ** (5. / 6)
-        term3 = (self.rho_ISM / self.rho_ISM_ref) ** (-1. / 3)         
+        term3 = (self.rho_ISM / self.rho_ISM_ref) ** (-1. / 3)
         return term1 * term2 * term3
 
     def _t_end(self):
@@ -158,12 +161,11 @@ class SNR_Truelove(SNR):
     """
 
     def r_out(self, t):
-        """Outer shell radius (pc) at age t (yr).
-        """
+        """Outer shell radius (pc) at age t (yr)."""
         t = YEAR_TO_SEC * t
         # Sedov Taylor Phase
         t_ST = 0.52 * self.t_c
-        R_FE = self.r_reverse_free_expansion(t_ST)
+        R_FE = self.r_free_expansion(t_ST)
         term1 = R_FE ** (5. / 2)
         term2 = (2.026 * (self.E_SN / self.rho_ISM)) ** (1. / 2)
         R_ST = (term1 + term2 * (t - t_ST)) ** (2. / 5)
diff --git a/gammapy/detect/blob.py b/gammapy/detect/blob.py
--- a/gammapy/detect/blob.py
+++ b/gammapy/detect/blob.py
@@ -1,5 +1,6 @@
 # Licensed under a 3-clause BSD style license - see LICENSE.rst
-"""Blob detection tool for source detection
+"""
+Blob detection tool for source detection
 
 This generic blob detection algorithm is based on:
 http://www.cs.utah.edu/~jfishbau/advimproc/project1/ (04.04.2013)
diff --git a/gammapy/detect/sex.py b/gammapy/detect/sex.py
--- a/gammapy/detect/sex.py
+++ b/gammapy/detect/sex.py
@@ -19,6 +19,8 @@
 from astropy.io import fits
 from astropy.table import Table
 
+__all__ = ['sex']
+
 
 def sex(image,
         image2='',
@@ -31,7 +33,7 @@ def sex(image,
         deblend_mincont=1,
         ):
     """Run SExtractor to detect sources in an image.
-    
+
     Parameters
     ----------
     image : str
@@ -39,58 +41,58 @@ def sex(image,
 
     image2 : str
         Measurement image filename (same as image if '')
-    
+
     catalog_name : str
         Output catalog filename
-    
+
     config_name : str
         Config filename
-    
+
     parameters_name : str
         Name of the file describing the catalog output parameters
-    
+
     checkimage_name : str
         Filename for the check-image (TODO: none for '')
-    
+
     detect_thresh : float
         Detection threshold
-    
+
     detect_minarea : int
         Minimum number of pixels above threshold
-    
+
     deblend_mincont : float in range 0 to 1
         Minimum contrast parameter for deblending
         0 = each peak is a single source
         1 = no deblending, one source per segment
-    
+
     Returns
     -------
     catalog : astropy.table.Table
         Catalog of detected objects
-    
+
     checkimage : astropy.io.fits.hdu.image.PrimaryHDU
         Segmented image
-    
+
     Examples
     --------
     TODO
-    
+
     TODO: look what other Python sextractor wrappers do:
     TODO: where to run the command and put the output files?
     TODO: return filenames or dict with results?
     """
     if catalog_name == None:
         catalog_name = tempfile.mktemp('.fits')
-    
+
     if checkimage_name == None:
         checkimage_name = tempfile.mktemp('.fits')
 
     if config_name == None:
         config_name = get_pkg_data_filename('sex.cfg')
-        
+
     if parameters_name == None:
         parameters_name = get_pkg_data_filename('sex.param')
-    
+
     logging.info('Running SExtractor')
     logging.info('INPUT  image: {0}'.format(image))
     logging.info('INPUT  image2: {0}'.format(image2))
@@ -111,7 +113,7 @@ def sex(image,
     logging.info('Executing the following command now:\n\n{0}\n'.format(' '.join(cmd)))
     process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     stdout, stderr = process.communicate()
-    
+
     # Read output files
     catalog = Table.read(catalog_name)
     checkimage = fits.open(checkimage_name)[0]


Test patch:
diff --git a/gammapy/astro/tests/test_snr.py b/gammapy/astro/tests/test_snr.py
--- a/gammapy/astro/tests/test_snr.py
+++ b/gammapy/astro/tests/test_snr.py
@@ -12,4 +12,4 @@ def test_SNR():
 def test_SNR_Truelove():
     snr = SNR_Truelove()
     assert_approx_equal(snr.L(1e3), 1.0768456645602824e+33)
-    assert_approx_equal(snr.r_out(1e3), 42)
+    assert_approx_equal(snr.r_out(1e3), 5.1177107050629278)
diff --git a/gammapy/spectrum/tests/test_isrf.py b/gammapy/spectrum/tests/test_isrf.py
--- a/gammapy/spectrum/tests/test_isrf.py
+++ b/gammapy/spectrum/tests/test_isrf.py
@@ -1,10 +1,10 @@
 # Licensed under a 3-clause BSD style license - see LICENSE.rst
-import unittest
+import pytest
 from ..isrf import Schlickeiser, Galprop
 
 
-@unittest.skip('TODO')
-class TestSchlickeiser(unittest.TestCase):
+@pytest.skip('TODO')
+class TestSchlickeiser:
 
     def test_omega_g_over_b(self):
         """ Check that CMB has the energy density it is
@@ -21,10 +21,8 @@ def test_call(self):
         self.assertAlmostEqual(actual / 189946, 1, places=5)
 
 
-class TestGalprop(unittest.TestCase):
+class TestGalprop:
 
     def test_call(self):
         Galprop()
 
-if __name__ == "__main__":
-    unittest.main()