Skip to content

Commit 8cb32a8

Browse files
committed
Remove show json tests and add format option to show
1 parent f2ee759 commit 8cb32a8

File tree

2 files changed

+8
-177
lines changed

2 files changed

+8
-177
lines changed

src/pip/_internal/commands/show.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ def __init__(self, *args, **kw):
4040
action='store_true',
4141
default=False,
4242
help='Show the full list of installed files for each package.')
43-
43+
self.cmd_opts.add_option(
44+
'--format',
45+
action='store',
46+
dest='list_format',
47+
default="header",
48+
choices=('header', 'json'),
49+
help="Select the output format among: header (default) or json",
50+
)
4451
self.parser.insert_option_group(0, self.cmd_opts)
4552

4653
def run(self, options, args):

tests/functional/test_show.py

Lines changed: 0 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
import os
32
import re
43

@@ -22,18 +21,6 @@ def test_basic_show(script):
2221
assert 'Requires: ' in lines
2322

2423

25-
def test_basic_show_json(script):
26-
"""
27-
Test end to end test for show command.
28-
"""
29-
result = script.pip('show', 'pip', '--format=json')
30-
data = json.loads(result.stdout)[0]
31-
assert len(data) == 10
32-
assert data['name'] == 'pip'
33-
assert data['version'] == '{}'.format(__version__)
34-
assert {'location', 'requires'} <= set(data)
35-
36-
3724
def test_show_with_files_not_found(script, data):
3825
"""
3926
Test for show command with installed files listing enabled and
@@ -52,21 +39,6 @@ def test_show_with_files_not_found(script, data):
5239
assert 'Cannot locate installed-files.txt' in lines
5340

5441

55-
def test_show_with_files_not_found_json(script, data):
56-
"""
57-
Test for show command with installed files listing enabled and
58-
installed-files.txt not found.
59-
"""
60-
editable = data.packages.joinpath('SetupPyUTF8')
61-
script.pip('install', '-e', editable)
62-
result = script.pip('show', '-f', 'SetupPyUTF8', '--format=json')
63-
data = json.loads(result.stdout)[0]
64-
assert data['name'] == 'SetupPyUTF8'
65-
assert data['version'] == '0.0.0'
66-
assert {'location', 'requires'} <= set(data)
67-
assert not data['files']
68-
69-
7042
def test_show_with_files_from_wheel(script, data):
7143
"""
7244
Test that a wheel's files can be listed
@@ -80,18 +52,6 @@ def test_show_with_files_from_wheel(script, data):
8052
assert re.search(r"Files:\n( .+\n)+", result.stdout)
8153

8254

83-
def test_show_with_files_from_wheel_json(script, data):
84-
"""
85-
Test that a wheel's files can be listed
86-
"""
87-
wheel_file = data.packages.joinpath('simple.dist-0.1-py2.py3-none-any.whl')
88-
script.pip('install', '--no-index', wheel_file)
89-
result = script.pip('show', '-f', 'simple.dist', '--format=json')
90-
data = json.loads(result.stdout)[0]
91-
assert data['name'] == 'simple.dist'
92-
assert data['files']
93-
94-
9555
@pytest.mark.network
9656
def test_show_with_all_files(script):
9757
"""
@@ -104,17 +64,6 @@ def test_show_with_all_files(script):
10464
assert re.search(r"Files:\n( .+\n)+", result.stdout)
10565

10666

107-
@pytest.mark.network
108-
def test_show_with_all_files_json(script):
109-
"""
110-
Test listing all files in the show command.
111-
"""
112-
script.pip('install', 'initools==0.2')
113-
result = script.pip('show', '--files', 'initools', '--format=json')
114-
data = json.loads(result.stdout)[0]
115-
assert data['files']
116-
117-
11867
def test_missing_argument(script):
11968
"""
12069
Test show command with no arguments.
@@ -159,21 +108,6 @@ def test_report_mixed_not_found(script):
159108
assert 'Name: pip' in lines
160109

161110

162-
def test_report_mixed_not_found_json(script):
163-
"""
164-
Test passing a mixture of found and not-found names.
165-
"""
166-
# We test passing non-canonicalized names.
167-
result = script.pip(
168-
'show', 'Abcd3', 'A-B-C', 'pip', '--format=json',
169-
allow_stderr_warning=True
170-
)
171-
assert 'WARNING: Package(s) not found: A-B-C, Abcd3' in result.stderr
172-
print(result.stdout)
173-
data = json.loads(result.stdout)[0]
174-
assert data['name'] == 'pip'
175-
176-
177111
def test_search_any_case():
178112
"""
179113
Search for a package in any case.
@@ -204,17 +138,6 @@ def test_show_verbose_with_classifiers(script):
204138
assert "Intended Audience :: Developers" in result.stdout
205139

206140

207-
def test_show_verbose_with_classifiers_json(script):
208-
"""
209-
Test that classifiers can be listed
210-
"""
211-
result = script.pip('show', 'pip', '--verbose', '--format=json')
212-
data = json.loads(result.stdout)[0]
213-
assert data['name'] == 'pip'
214-
assert data['classifiers']
215-
assert "Intended Audience :: Developers" in data["classifiers"]
216-
217-
218141
def test_show_verbose_installer(script, data):
219142
"""
220143
Test that the installer is shown (this currently needs a wheel install)
@@ -227,18 +150,6 @@ def test_show_verbose_installer(script, data):
227150
assert 'Installer: pip' in lines
228151

229152

230-
def test_show_verbose_installer_json(script, data):
231-
"""
232-
Test that the installer is shown (this currently needs a wheel install)
233-
"""
234-
wheel_file = data.packages.joinpath('simple.dist-0.1-py2.py3-none-any.whl')
235-
script.pip('install', '--no-index', wheel_file)
236-
result = script.pip('show', '--verbose', 'simple.dist', '--format=json')
237-
data = json.loads(result.stdout)[0]
238-
assert data['name'] == 'simple.dist'
239-
assert data['installer'] == 'pip'
240-
241-
242153
def test_show_verbose(script):
243154
"""
244155
Test end to end test for verbose show command.
@@ -251,17 +162,6 @@ def test_show_verbose(script):
251162
assert 'Classifiers:' in lines
252163

253164

254-
def test_show_verbose_json(script):
255-
"""
256-
Test end to end test for verbose show command.
257-
"""
258-
result = script.pip('show', '--verbose', 'pip', '--format=json')
259-
data = json.loads(result.stdout)[0]
260-
261-
assert {'metadata-version', 'installer',
262-
'entry-points', 'classifiers'} <= set(data)
263-
264-
265165
def test_all_fields(script):
266166
"""
267167
Test that all the fields are present
@@ -275,18 +175,6 @@ def test_all_fields(script):
275175
assert actual == expected
276176

277177

278-
def test_all_fields_json(script):
279-
"""
280-
Test that all the fields are present
281-
"""
282-
result = script.pip('show', 'pip', '--format=json')
283-
data = json.loads(result.stdout)[0]
284-
expected = {'name', 'version', 'summary', 'home-page', 'author',
285-
'author-email', 'license', 'location', 'requires',
286-
'required-by'}
287-
assert set(data) == expected
288-
289-
290178
def test_pip_show_is_short(script):
291179
"""
292180
Test that pip show stays short
@@ -296,15 +184,6 @@ def test_pip_show_is_short(script):
296184
assert len(lines) <= 10
297185

298186

299-
def test_pip_show_is_short_json(script):
300-
"""
301-
Test that pip show stays short
302-
"""
303-
result = script.pip('show', 'pip', '--format=json')
304-
data = json.loads(result.stdout)[0]
305-
assert len(data) <= 10
306-
307-
308187
def test_pip_show_divider(script, data):
309188
"""
310189
Expect a divider between packages
@@ -343,22 +222,6 @@ def test_show_required_by_packages_basic(script, data):
343222
assert 'Required-by: requires-simple' in lines
344223

345224

346-
def test_show_required_by_packages_basic_json(script, data):
347-
"""
348-
Test that installed packages that depend on this package are shown
349-
"""
350-
editable_path = os.path.join(data.src, 'requires_simple')
351-
script.pip(
352-
'install', '--no-index', '-f', data.find_links, editable_path
353-
)
354-
355-
result = script.pip('show', 'simple', '--format=json')
356-
data = json.loads(result.stdout)[0]
357-
358-
assert data['name'] == 'simple'
359-
assert data['required-by'] == ['requires-simple']
360-
361-
362225
def test_show_required_by_packages_capitalized(script, data):
363226
"""
364227
Test that the installed packages which depend on a package are shown
@@ -376,23 +239,6 @@ def test_show_required_by_packages_capitalized(script, data):
376239
assert 'Required-by: Requires-Capitalized' in lines
377240

378241

379-
def test_show_required_by_packages_capitalized_json(script, data):
380-
"""
381-
Test that the installed packages which depend on a package are shown
382-
where the package has a capital letter
383-
"""
384-
editable_path = os.path.join(data.src, 'requires_capitalized')
385-
script.pip(
386-
'install', '--no-index', '-f', data.find_links, editable_path
387-
)
388-
389-
result = script.pip('show', 'simple', '--format=json')
390-
data = json.loads(result.stdout)[0]
391-
392-
assert data['name'] == 'simple'
393-
assert data['required-by'] == ['Requires-Capitalized']
394-
395-
396242
def test_show_required_by_packages_requiring_capitalized(script, data):
397243
"""
398244
Test that the installed packages which depend on a package are shown
@@ -415,28 +261,6 @@ def test_show_required_by_packages_requiring_capitalized(script, data):
415261
assert 'Required-by: requires-requires-capitalized' in lines
416262

417263

418-
def test_show_required_by_packages_requiring_capitalized_json(script, data):
419-
"""
420-
Test that the installed packages which depend on a package are shown
421-
where the package has a name with a mix of
422-
lower and upper case letters
423-
"""
424-
required_package_path = os.path.join(data.src, 'requires_capitalized')
425-
script.pip(
426-
'install', '--no-index', '-f', data.find_links, required_package_path
427-
)
428-
editable_path = os.path.join(data.src, 'requires_requires_capitalized')
429-
script.pip(
430-
'install', '--no-index', '-f', data.find_links, editable_path
431-
)
432-
433-
result = script.pip('show', 'Requires_Capitalized', '--format=json')
434-
data = json.loads(result.stdout)[0]
435-
436-
assert data['name'] == 'Requires-Capitalized'
437-
assert data['required-by'] == ['requires-requires-capitalized']
438-
439-
440264
def test_show_skip_work_dir_pkg(script):
441265
"""
442266
Test that show should not include package

0 commit comments

Comments
 (0)