25
25
from __future__ import absolute_import , print_function
26
26
27
27
import os
28
+ import json
28
29
29
30
from click .testing import CliRunner
30
31
31
32
from commoncode .testcase import FileBasedTesting
32
- from scancode import cli
33
33
from commoncode .fileutils import as_posixpath
34
34
35
+ from scancode import cli
36
+
35
37
36
38
class TestCommandLine (FileBasedTesting ):
37
39
test_data_dir = os .path .join (os .path .dirname (__file__ ), 'data' )
@@ -85,7 +87,7 @@ def test_extract_option_works_with_relative_paths(self):
85
87
scancode_tmp = join (scancode_root , 'tmp' )
86
88
fileutils .create_dir (scancode_tmp )
87
89
scancode_root_abs = abspath (scancode_root )
88
- test_src_dir = tempfile .mkdtemp (dir = scancode_tmp ).replace (scancode_root_abs , '' ).strip ('\\ /' )
90
+ test_src_dir = tempfile .mkdtemp (dir = scancode_tmp ).replace (scancode_root_abs , '' ).strip ('\\ /' )
89
91
test_file = self .get_test_loc ('extract_relative_path/basic.zip' )
90
92
shutil .copy (test_file , test_src_dir )
91
93
test_src_file = join (test_src_dir , 'basic.zip' )
@@ -98,8 +100,8 @@ def test_extract_option_works_with_relative_paths(self):
98
100
assert not 'WARNING' in result .output
99
101
assert not 'ERROR' in result .output
100
102
expected = ['/c/a/a.txt' , '/c/b/a.txt' , '/c/c/a.txt' ]
101
- file_result = [as_posixpath (f .replace (test_tgt_dir , '' )) for f in fileutils .file_iter (test_tgt_dir )]
102
- assert sorted (expected )== sorted (file_result )
103
+ file_result = [as_posixpath (f .replace (test_tgt_dir , '' )) for f in fileutils .file_iter (test_tgt_dir )]
104
+ assert sorted (expected ) == sorted (file_result )
103
105
104
106
def test_copyright_option_detects_copyrights (self ):
105
107
test_dir = self .get_test_loc ('copyright' , copy = True )
@@ -120,3 +122,15 @@ def test_license_option_detects_licenses(self):
120
122
assert 'Scanning done' in result .output
121
123
assert os .path .exists (output_json )
122
124
assert len (open (output_json ).read ()) > 10
125
+
126
+ def test_scancode_skip_vcs_files_and_dirs_by_default (self ):
127
+ test_dir = self .extract_test_tar ('ignore/vcs.tgz' )
128
+ runner = CliRunner ()
129
+ output_json = self .get_temp_file ('json' )
130
+ result = runner .invoke (cli .scancode , ['--copyright' , test_dir , output_json ])
131
+ assert result .exit_code == 0
132
+ with open (output_json ) as res :
133
+ scan_result = json .load (res )
134
+ # a single test.tst file that is not a VCS file should be listed
135
+ assert 1 == scan_result ['count' ]
136
+ assert scan_result ['results' ][0 ]['location' ].endswith ('vcs.tgz/vcs/test.txt' )
0 commit comments