Skip to content

Commit fc792d8

Browse files
steven-esserpombredanne
authored andcommitted
#262: initial test cases created and passing
Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent e43ed2f commit fc792d8

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/scancode/extract_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class ExtractCommand(utils.BaseCommand):
8686

8787
@click.option('--verbose', is_flag=True, default=False, help='Print verbose file-by-file progress messages.')
8888
@click.option('--quiet', is_flag=True, default=False, help='Do not print any summary or progress message.')
89-
@click.option('--shallow', is_flag=True, default=False, help='Extract only first level of archives (and not archives in archives).')
89+
@click.option('--shallow', is_flag=True, default=False, help='Do not extract recursively nested archives (e.g. not archives in archives).')
9090

9191
@click.help_option('-h', '--help')
9292
@click.option('--about', is_flag=True, is_eager=True, callback=print_about, help='Show information about ScanCode and licensing and exit.')
801 Bytes
Binary file not shown.

tests/scancode/test_extract_cli.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,21 @@ def test_extractcode_command_can_extract_archive_with_unicode_names(monkeypatch)
209209
'/unicodepath/koristenjem_Karkkainen_-_Sander.pdf'
210210
]
211211
assert sorted(expected) == sorted(file_result)
212+
213+
214+
def test_extractcode_command_can_extract_shallow(monkeypatch):
215+
test_dir = test_env.get_test_loc('extract_shallow', copy=True)
216+
monkeypatch.setattr(click._termui_impl, 'isatty', lambda _: True)
217+
runner = CliRunner()
218+
result = runner.invoke(extract_cli.extractcode, ['--shallow', test_dir])
219+
assert result.exit_code == 0
220+
file_result = [f for f in map(as_posixpath, file_iter(test_dir)) if not f.endswith('unicodepath.tgz')]
221+
file_result = [''.join(f.partition('/top.zip-extract/')[1:]) for f in file_result]
222+
file_result = [f for f in file_result if f]
223+
# this checks that the zip in top.zip are not extracted
224+
expected = [
225+
'/top.zip-extract/some3.zip',
226+
'/top.zip-extract/some2.zip',
227+
'/top.zip-extract/some1.zip',
228+
]
229+
assert sorted(expected) == sorted(file_result)

0 commit comments

Comments
 (0)