Skip to content

Commit 44123b7

Browse files
committed
Move CLI to a separate folder
1 parent 4ac7956 commit 44123b7

6 files changed

Lines changed: 50 additions & 32 deletions

File tree

opus/cli/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .cli import *

opus/cli/cassini.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from ..api import API
4+
from .cli import data
5+
6+
api = API()
7+
8+
def vims(argv=None, api=api):
9+
'''Cassini VIMS data entry point'''
10+
return data(argv, desc='Get Cassini VIMS Images and Cubes from OPUS API',
11+
args=[{'surfacegeometrytargetname': {'help': 'VIMS target name', 'metavar': 'TARGET_NAME'}},
12+
{'--cols': {'default': 'ringobsid,target,revno,time1,primaryfilespec,channel',
13+
'help': 'Output columns (default: `ringobsid,target,revno,time1,primaryfilespec,channel`)'}}],
14+
defaults={'instrumentid': 'Cassini+VIMS', 'typeid': 'Image,Cube'}, api=api)

opus/cli.py renamed to opus/cli/cli.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import argparse
44

5-
from .api import API
5+
from ..api import API
66

77
api = API()
88

@@ -63,12 +63,3 @@ def data(argv=None, desc='Get Data from OPUS-SETI API', args=[], defaults={}, ap
6363
os.sys.exit(2)
6464

6565
return api.data(**vars(args))
66-
67-
68-
def vims(argv=None, api=api):
69-
'''Cassini VIMS data entry point'''
70-
return data(argv, desc='Get Cassini VIMS Images and Cubes from OPUS API',
71-
args=[{'surfacegeometrytargetname': {'help': 'VIMS target name', 'metavar': 'TARGET_NAME'}},
72-
{'--cols': {'default': 'ringobsid,target,revno,time1,primaryfilespec,channel',
73-
'help': 'Output columns (default: `ringobsid,target,revno,time1,primaryfilespec,channel`)'}}],
74-
defaults={'instrumentid': 'Cassini+VIMS', 'typeid': 'Image,Cube'}, api=api)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ addopts = -vv --cov-report term-missing --cov-report html --cov-report xml
3434
[entry_points]
3535
console_scripts =
3636
opus = opus.cli:data
37-
opus-vims = opus.cli:vims
37+
opus-vims = opus.cli.cassini:vims

tests/test_cli.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import six
55

66
from opus.api import API
7-
from opus.cli import read, data, vims
7+
from opus.cli import read, data
88

99

1010
@pytest.fixture
@@ -84,23 +84,3 @@ def test_data_argv_none(api):
8484
with pytest.raises(SystemExit):
8585
resp = data(argv, api=api)
8686
assert len(responses.calls) == 0
87-
88-
89-
@responses.activate
90-
def test_cli_vims(api):
91-
json = open('tests/api/data_vims.json', 'r').read()
92-
responses.add(responses.GET,
93-
'http://localhost/data.json',
94-
body=json)
95-
96-
argv = ['TITAN']
97-
resp = vims(argv, api=api)
98-
99-
assert len(responses.calls) == 1
100-
if six.PY3:
101-
assert responses.calls[0].request.url == 'http://localhost/data.json?surfacegeometrytargetname=TITAN&cols=ringobsid,target,revno,time1,primaryfilespec,channel&instrumentid=Cassini+VIMS&typeid=Image,Cube&limit=10&page=1'
102-
else:
103-
assert 'surfacegeometrytargetname=TITAN' in responses.calls[0].request.url
104-
105-
assert responses.calls[0].response.text == json
106-
assert len(resp) == 10

tests/test_cli_cassini.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding: utf-8 -*-
2+
import pytest
3+
import responses
4+
import six
5+
6+
from opus.api import API
7+
from opus.cli.cassini import vims
8+
9+
10+
@pytest.fixture
11+
def api():
12+
return API('http://localhost/')
13+
14+
15+
@responses.activate
16+
def test_cli_vims(api):
17+
json = open('tests/api/data_vims.json', 'r').read()
18+
responses.add(responses.GET,
19+
'http://localhost/data.json',
20+
body=json)
21+
22+
argv = ['TITAN']
23+
resp = vims(argv, api=api)
24+
25+
assert len(responses.calls) == 1
26+
if six.PY3:
27+
assert responses.calls[0].request.url == 'http://localhost/data.json?surfacegeometrytargetname=TITAN&cols=ringobsid,target,revno,time1,primaryfilespec,channel&instrumentid=Cassini+VIMS&typeid=Image,Cube&limit=10&page=1'
28+
else:
29+
assert 'surfacegeometrytargetname=TITAN' in responses.calls[0].request.url
30+
31+
assert responses.calls[0].response.text == json
32+
assert len(resp) == 10

0 commit comments

Comments
 (0)