1 | # Licensed under a 3-clause BSD style license - see LICENSE.rst |
||
2 | from __future__ import absolute_import, division, print_function, unicode_literals |
||
3 | import pytest |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
4 | import astropy.units as u |
||
5 | from ....utils.testing import ( |
||
6 | assert_quantity_allclose, |
||
7 | requires_data, |
||
8 | requires_dependency, |
||
9 | ) |
||
10 | from ....maps import WcsGeom |
||
11 | from .. import JFactory, profiles, PrimaryFlux, compute_dm_flux |
||
12 | |||
13 | |||
14 | @pytest.fixture(scope="session") |
||
15 | def geom(): |
||
16 | return WcsGeom.create(binsz=0.5, npix=10) |
||
17 | |||
18 | |||
19 | @pytest.fixture(scope="session") |
||
20 | def jfact(geom): |
||
0 ignored issues
–
show
geom is re-defining a name which is already available in the outer-scope (previously defined on line 15 ).
It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior: param = 5
class Foo:
def __init__(self, param): # "param" would be flagged here
self.param = param
Loading history...
|
|||
21 | jfactory = JFactory(geom=geom, profile=profiles.NFWProfile(), distance=8 * u.kpc) |
||
0 ignored issues
–
show
|
|||
22 | return jfactory.compute_jfactor() |
||
23 | |||
24 | |||
25 | @pytest.fixture(scope="session") |
||
26 | def prim_flux(): |
||
27 | return PrimaryFlux(mDM=1 * u.TeV, channel="W") |
||
0 ignored issues
–
show
|
|||
28 | |||
29 | |||
30 | @requires_dependency("scipy") |
||
31 | @requires_data("gammapy-extra") |
||
32 | def test_dmfluxmapmaker(jfact, prim_flux): |
||
0 ignored issues
–
show
jfact is re-defining a name which is already available in the outer-scope (previously defined on line 20 ).
It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior: param = 5
class Foo:
def __init__(self, param): # "param" would be flagged here
self.param = param
Loading history...
prim_flux is re-defining a name which is already available in the outer-scope (previously defined on line 26 ).
It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior: param = 5
class Foo:
def __init__(self, param): # "param" would be flagged here
self.param = param
Loading history...
|
|||
33 | x_section = 1e-26 * u.Unit("cm3 s-1") |
||
34 | energy_range = [0.1, 1] * u.TeV |
||
0 ignored issues
–
show
|
|||
35 | flux = compute_dm_flux( |
||
36 | jfact=jfact, prim_flux=prim_flux, x_section=x_section, energy_range=energy_range |
||
37 | ) |
||
38 | |||
39 | actual = flux[5, 5] |
||
40 | desired = 6.49463e-13 / u.cm ** 2 / u.s |
||
0 ignored issues
–
show
|
|||
41 | assert_quantity_allclose(actual, desired, rtol=1e-5) |
||
42 |