Passed
Pull Request — master (#1929)
by
unknown
02:32
created

gammapy/scripts/tests/test_download.py (2 issues)

1
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2
from __future__ import absolute_import, division, print_function, unicode_literals
3
from ...utils.testing import run_cli
4
from ..main import cli
5
from ...extern.pathlib import Path
6
from ...utils.testing import requires_dependency
7
import pytest
8
9
10
@pytest.fixture(scope="session")
11
def files_dir(tmpdir_factory):
12
    filesdir = tmpdir_factory.mktemp("tmpdwn")
13
    return filesdir
14
15
16
def test_cli_download_help():
17
    result = run_cli(cli, ["download", "--help"])
18
    assert "Usage" in result.output
19
20
21
@requires_dependency("yaml")
22
def test_cli_download_datasets(files_dir):
0 ignored issues
show
Comprehensibility Bug introduced by
files_dir is re-defining a name which is already available in the outer-scope (previously defined on line 11).

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...
23
    dataset = "ebl"
24
    option_out = "--out=" + str(files_dir)
25
    option_src = "--src=" + dataset
26
27
    args = ["download", "datasets", option_src, option_out]
28
    run_cli(cli, args)
29
30
    filepath = Path(str(files_dir)) / dataset
31
    assert filepath.exists()
32
33
34
@requires_dependency("yaml")
35
def test_cli_download_notebooks(files_dir):
0 ignored issues
show
Comprehensibility Bug introduced by
files_dir is re-defining a name which is already available in the outer-scope (previously defined on line 11).

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...
36
    release = "0.8"
37
    notebook = "first_steps"
38
    nbfilename = notebook + ".ipynb"
39
    envfilename = "gammapy-" + release + "-environment.yml"
40
    dirnbsname = "notebooks-" + release
41
    option_out = "--out=" + str(files_dir)
42
    option_src = "--src=" + notebook
43
    option_release = "--release=" + release
44
45
    args = ["download", "notebooks", option_src, option_out, option_release]
46
    run_cli(cli, args)
47
48
    envfilepath = Path(str(files_dir)) / envfilename
49
    nbfilepath = Path(str(files_dir)) / dirnbsname / nbfilename
50
    assert envfilepath.exists()
51
    assert nbfilepath.exists()
52