|
| 1 | +# |
| 2 | +# Copyright (c) 2015 nexB Inc. and others. All rights reserved. |
| 3 | +# http://nexb.com and https://github.com/nexB/scancode-toolkit/ |
| 4 | +# The ScanCode software is licensed under the Apache License version 2.0. |
| 5 | +# Data generated with ScanCode require an acknowledgment. |
| 6 | +# ScanCode is a trademark of nexB Inc. |
| 7 | +# |
| 8 | +# You may not use this software except in compliance with the License. |
| 9 | +# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0 |
| 10 | +# Unless required by applicable law or agreed to in writing, software distributed |
| 11 | +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 12 | +# CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 13 | +# specific language governing permissions and limitations under the License. |
| 14 | +# |
| 15 | +# When you publish or redistribute any data created with ScanCode or any ScanCode |
| 16 | +# derivative work, you must accompany this data with the following acknowledgment: |
| 17 | +# |
| 18 | +# Generated with ScanCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES |
| 19 | +# OR CONDITIONS OF ANY KIND, either express or implied. No content created from |
| 20 | +# ScanCode should be considered or used as legal advice. Consult an Attorney |
| 21 | +# for any legal advice. |
| 22 | +# ScanCode is a free software code scanning tool from nexB Inc. and others. |
| 23 | +# Visit https://github.com/nexB/scancode-toolkit/ for support and download. |
| 24 | + |
| 25 | +from __future__ import absolute_import, print_function |
| 26 | + |
| 27 | +import os |
| 28 | + |
| 29 | +from click.testing import CliRunner |
| 30 | + |
| 31 | +from commoncode.testcase import FileBasedTesting |
| 32 | +from scancode import cli |
| 33 | + |
| 34 | + |
| 35 | +class TestCommandLine(FileBasedTesting): |
| 36 | + test_data_dir = os.path.join(os.path.dirname(__file__), 'data') |
| 37 | + |
| 38 | + def test_extract_option_is_exclusive_of_other_options(self): |
| 39 | + test_dir = self.get_temp_dir() |
| 40 | + runner = CliRunner() |
| 41 | + result = runner.invoke(cli.scancode, ['--extract', '--copyright', test_dir]) |
| 42 | + assert result.exit_code == 2 |
| 43 | + assert 'option cannot be combined with other scanning options' in result.output |
| 44 | + |
| 45 | + result = runner.invoke(cli.scancode, ['--copyright', '--extract', test_dir]) |
| 46 | + assert result.exit_code == 2 |
| 47 | + assert 'option cannot be combined with other scanning options' in result.output |
| 48 | + |
| 49 | + result = runner.invoke(cli.scancode, ['--extract', '--license', test_dir]) |
| 50 | + assert result.exit_code == 2 |
| 51 | + assert 'option cannot be combined with other scanning options' in result.output |
| 52 | + |
| 53 | + result = runner.invoke(cli.scancode, ['--extract', '--license', '--copyright', test_dir]) |
| 54 | + assert result.exit_code == 2 |
| 55 | + assert 'option cannot be combined with other scanning options' in result.output |
| 56 | + |
| 57 | + def test_extract_option_can_take_an_empty_directory(self): |
| 58 | + test_dir = self.get_temp_dir() |
| 59 | + runner = CliRunner() |
| 60 | + result = runner.invoke(cli.scancode, ['--extract', test_dir]) |
| 61 | + assert result.exit_code == 0 |
| 62 | + assert 'Extracting done' in result.output |
| 63 | + |
| 64 | + def test_extract_option_does_extract(self): |
| 65 | + test_dir = self.get_test_loc('extract', copy=True) |
| 66 | + runner = CliRunner() |
| 67 | + result = runner.invoke(cli.scancode, ['--extract', test_dir]) |
| 68 | + assert result.exit_code == 0 |
| 69 | + assert 'Extracting done' in result.output |
| 70 | + assert os.path.exists(os.path.join(test_dir, 'some.tar.gz-extract')) |
| 71 | + |
| 72 | + def test_copyright_option_detects_copyrights(self): |
| 73 | + test_dir = self.get_test_loc('copyright', copy=True) |
| 74 | + runner = CliRunner() |
| 75 | + output_json = self.get_temp_file('json') |
| 76 | + result = runner.invoke(cli.scancode, ['--copyright', test_dir, output_json]) |
| 77 | + assert result.exit_code == 0 |
| 78 | + assert 'Scanning done' in result.output |
| 79 | + assert os.path.exists(output_json) |
| 80 | + assert len(open(output_json).read()) > 10 |
| 81 | + |
| 82 | + def test_license_option_detects_licenses(self): |
| 83 | + test_dir = self.get_test_loc('license', copy=True) |
| 84 | + runner = CliRunner() |
| 85 | + output_json = self.get_temp_file('json') |
| 86 | + result = runner.invoke(cli.scancode, ['--license', test_dir, output_json]) |
| 87 | + assert result.exit_code == 0 |
| 88 | + assert 'Scanning done' in result.output |
| 89 | + assert os.path.exists(output_json) |
| 90 | + assert len(open(output_json).read()) > 10 |
0 commit comments