99# See https://aboutcode.org for more information about nexB OSS projects.
1010#
1111
12- import hashlib
1312import os
1413import shutil
1514import subprocess
1615import sys
1716
18- # TODO: also test a pip install with a find-links option to our new PyPI repo
1917
20-
21- def run_pypi_smoke_tests (pypi_archive ):
18+ def run_pypi_smoke_tests (pypi_archive , venv_prefix = "venv/bin/" ):
2219 """
2320 Run basic install and "smoke" scancode tests for a PyPI archive.
2421 """
2522 # archive is either a wheel or an sdist as in
2623 # scancode_toolkit-21.1.21-py3-none-any.whl or scancode-toolkit-21.1.21.tar.gz
27- run_command (["pip" , "install" , pypi_archive + "[full]" ])
24+ run_command ([venv_prefix + "pip" , "install" , pypi_archive + "[full]" ])
2825
2926 with open ("some.file" , "w" ) as sf :
3027 sf .write ("license: gpl-2.0" )
3128
32- run_command (["scancode" , "-clipeu" , "--json-pp" , "-" , "some.file" ])
29+ run_command ([venv_prefix + "scancode" , "-clipeu" , "--json-pp" , "-" , "some.file" ])
3330
3431
3532def run_app_smoke_tests (app_archive ):
@@ -42,36 +39,61 @@ def run_app_smoke_tests(app_archive):
4239 # We split the name on "_" to extract the laft hand side which is name of
4340 # the root directory inside the archive e.g. "scancode-toolkit-21.1.21"
4441 # where the archive gest extracted
45- extract_dir , _ , _py_ver_ext = app_archive .partition ("_" )
42+
43+ _base , _ , fn = app_archive .partition ("/" )
44+ extract_dir , _ , _py_ver_ext = fn .partition ("_" )
45+ print ("run_app_smoke_tests: cwd:" , os .getcwd ())
46+ print ("run_app_smoke_tests:" , "extracting archive:" , app_archive , "to:" , extract_dir )
4647 shutil .unpack_archive (app_archive )
47- print ()
48- print ("cwd:" , os .getcwd ())
4948
5049 extract_loc = os .path .normpath (os .path .abspath (os .path .expanduser (extract_dir )))
51- print ("extract_loc:" , extract_loc )
50+ print ("run_app_smoke_tests: extract_loc:" , extract_loc )
5251 for f in os .listdir (extract_loc ):
5352 print (" " , f )
5453 print ()
5554
5655 os .chdir (extract_loc )
5756
57+ print (f"Configuring scancode for release: { app_archive } " )
58+ run_command ([
59+ os .path .join (extract_loc , "configure" ),
60+ ])
61+
5862 # minimal tests: update when new scans are available
5963 args = [
6064 os .path .join (extract_loc , "scancode" ),
61- "-clipeu" ,
65+ "--license" ,
66+ "--license-text" ,
67+ "--license-clarity-score" ,
68+
69+ "--copyright" ,
70+ "--info" ,
71+ "--email" ,
72+ "--url" ,
73+ "--generated" ,
74+
75+ "--package" ,
76+ "--system-package" ,
77+
78+ "--summary" ,
79+ "--tallies" ,
6280 "--classify" ,
81+ "--consolidate" ,
82+
6383 "--verbose" ,
64- "--json" ,
65- "test_scan.json" ,
66- "--csv" ,
67- "test_scan.csv" ,
68- "--html" ,
69- "test_scan.html" ,
70- "--spdx-tv" ,
71- "test_scan.spdx" ,
72- "--json-pp" ,
73- "-" ,
74- os .path .join (extract_loc , "apache-2.0.LICENSE" ),
84+
85+ "--yaml" , "test_scan.yml" ,
86+ "--json" , "test_scan.json" ,
87+ "--json-lines" , "test_scan.json-lines" ,
88+ "--csv" , "test_scan.csv" ,
89+ "--html" , "test_scan.html" ,
90+ "--cyclonedx" , "test_scan.cdx" ,
91+ "--cyclonedx-xml" , "test_scan.cdx.xml" ,
92+ "--spdx-tv" , "test_scan.spdx" ,
93+
94+ "--debian" , "test_scan.debian.copyright" ,
95+ "--json-pp" , "-" ,
96+ "apache-2.0.LICENSE"
7597 ]
7698
7799 print (f"Testing scancode release: { app_archive } " )
@@ -100,18 +122,14 @@ def run_command(args):
100122
101123if __name__ == "__main__" :
102124 args = sys .argv [1 :]
103- action , archive , sha_arch , sha_py = args
104-
105- with open (archive , "rb" ) as arch :
106- current_sha_arch = hashlib .sha256 (arch .read ()).hexdigest ()
107- assert current_sha_arch == sha_arch
108-
109- with open (__file__ , "rb" ) as py :
110- current_sha_py = hashlib .sha256 (py .read ()).hexdigest ()
111- assert current_sha_py == sha_py
125+ action = args [0 ]
126+ archive = args [1 ]
112127
113128 if action == "pypi" :
114- run_pypi_smoke_tests ( archive )
115- else :
116- # action =='app':
129+ venv_prefix = args [ 2 ]
130+ run_pypi_smoke_tests ( archive , venv_prefix )
131+ elif action == 'app' :
117132 run_app_smoke_tests (archive )
133+ else :
134+ raise Exception ("Usage: scancode_release_tests.py <pypi or app> <archive-to-test>" )
135+
0 commit comments