1616from chalice .deploy .packager import NoSuchPackageError
1717
1818
19+ PY_VERSION = sys .version_info [:2 ]
20+ VERSION_CUTOFF = (3 , 9 )
21+ # We're being cautious here, but we want to fix the package versions we
22+ # try to install on older versions of python.
23+ # If the python version being tested is less than the VERSION_CUTOFF of 3.9,
24+ # then we'll install the `legacy_version` in the packages below. This is to
25+ # ensure we don't regress on being able to package older package versions on
26+ # older versions on python. Any python version above the VERSION_CUTOFF will
27+ # install the `version` identifier. That way newer versions of python won't
28+ # need to update this list as long as a package can still be installed on
29+ # 3.10 or higher.
30+ PACKAGES_TO_TEST = {
31+ 'pandas' : {
32+ 'version' : '1.5.3' ,
33+ 'legacy_version' : '1.1.5' ,
34+ 'contents' : [
35+ 'pandas/_libs/__init__.py' ,
36+ 'pandas/io/sas/_sas.cpython-*-x86_64-linux-gnu.so'
37+ ],
38+ },
39+ 'SQLAlchemy' : {
40+ 'version' : '1.4.47' ,
41+ 'legacy_version' : '1.3.20' ,
42+ 'contents' : [
43+ 'sqlalchemy/__init__.py' ,
44+ 'sqlalchemy/cresultproxy.cpython-*-x86_64-linux-gnu.so'
45+ ],
46+ },
47+ 'numpy' : {
48+ 'version' : '1.21.6' ,
49+ 'legacy_version' : '1.19.4' ,
50+ 'contents' : [
51+ 'numpy/__init__.py' ,
52+ 'numpy/core/_struct_ufunc_tests.cpython-*-x86_64-linux-gnu.so'
53+ ],
54+ },
55+ 'cryptography' : {
56+ 'version' : '3.3.1' ,
57+ 'legacy_version' : '3.3.1' ,
58+ 'contents' : [
59+ 'cryptography/__init__.py' ,
60+ 'cryptography/hazmat/bindings/_openssl.abi3.so'
61+ ],
62+ },
63+ 'Jinja2' : {
64+ 'version' : '2.11.2' ,
65+ 'legacy_version' : '2.11.2' ,
66+ 'contents' : ['jinja2/__init__.py' ],
67+ },
68+ 'Mako' : {
69+ 'version' : '1.1.3' ,
70+ 'legacy_version' : '1.1.3' ,
71+ 'contents' : ['mako/__init__.py' ],
72+ },
73+ 'MarkupSafe' : {
74+ 'version' : '1.1.1' ,
75+ 'legacy_version' : '1.1.1' ,
76+ 'contents' : ['markupsafe/__init__.py' ],
77+ },
78+ 'scipy' : {
79+ 'version' : '1.7.3' ,
80+ 'legacy_version' : '1.5.4' ,
81+ 'contents' : [
82+ 'scipy/__init__.py' ,
83+ 'scipy/cluster/_hierarchy.cpython-*-x86_64-linux-gnu.so'
84+ ],
85+ },
86+ 'cffi' : {
87+ 'version' : '1.15.1' ,
88+ 'legacy_version' : '1.14.5' ,
89+ 'contents' : ['_cffi_backend.cpython-*-x86_64-linux-gnu.so' ],
90+ },
91+ 'pygit2' : {
92+ 'version' : '1.10.1' ,
93+ 'legacy_version' : '1.5.0' ,
94+ 'contents' : ['pygit2/_pygit2.cpython-*-x86_64-linux-gnu.so' ],
95+ },
96+ 'pyrsistent' : {
97+ 'version' : '0.17.3' ,
98+ 'legacy_version' : '0.17.3' ,
99+ 'contents' : ['pyrsistent/__init__.py' ],
100+ },
101+ }
102+
103+
19104@contextmanager
20105def cd (path ):
106+ original_dir = os .getcwd ()
21107 try :
22- original_dir = os .getcwd ()
23108 os .chdir (path )
24109 yield
25110 finally :
@@ -43,41 +128,26 @@ def _get_random_package_name():
43128 return 'foobar-%s' % str (uuid .uuid4 ())[:8 ]
44129
45130
131+ def _get_package_install_test_cases ():
132+ testcases = []
133+ if PY_VERSION <= VERSION_CUTOFF :
134+ version_key = 'legacy_version'
135+ else :
136+ version_key = 'version'
137+ for package , config in PACKAGES_TO_TEST .items ():
138+ package_version = f'{ package } =={ config [version_key ]} '
139+ testcases .append (
140+ (package_version , config ['contents' ])
141+ )
142+ return testcases
143+
144+
46145# This test can take a while, but you can set this env var to make sure that
47146# the commonly used python packages can be packaged successfully.
48147@pytest .mark .skipif (not os .environ .get ('CHALICE_TEST_EXTENDED_PACKAGING' ),
49148 reason = 'Set CHALICE_TEST_EXTENDED_PACKAGING for extended '
50149 'packaging tests.' )
51- @pytest .mark .skipif (sys .version_info [0 ] == 2 ,
52- reason = 'Extended packaging tests only run on py3.' )
53- @pytest .mark .parametrize (
54- 'package,contents' , [
55- ('pandas==1.5.3' if sys .version_info [1 ] >= 10 else 'pandas==1.1.5' , [
56- 'pandas/_libs/__init__.py' ,
57- 'pandas/io/sas/_sas.cpython-*-x86_64-linux-gnu.so' ]),
58- ('SQLAlchemy==1.4.47' , [
59- 'sqlalchemy/__init__.py' ,
60- 'sqlalchemy/cresultproxy.cpython-*-x86_64-linux-gnu.so' ]),
61- ('numpy==1.21.6' , [
62- 'numpy/__init__.py' ,
63- 'numpy/core/_struct_ufunc_tests.cpython-*-x86_64-linux-gnu.so' ]),
64- ('cryptography==3.3.1' , [
65- 'cryptography/__init__.py' ,
66- 'cryptography/hazmat/bindings/_openssl.abi3.so' ]),
67- ('Jinja2==2.11.2' , ['jinja2/__init__.py' ]),
68- ('Mako==1.1.3' , ['mako/__init__.py' ]),
69- ('MarkupSafe==1.1.1' , ['markupsafe/__init__.py' ]),
70- ('scipy==1.7.3' , [
71- 'scipy/__init__.py' ,
72- 'scipy/cluster/_hierarchy.cpython-*-x86_64-linux-gnu.so' ]),
73- ('cffi==1.15.1' , [
74- '_cffi_backend.cpython-*-x86_64-linux-gnu.so' ]),
75- ('pygit2==1.10.1' , [
76- 'pygit2/_pygit2.cpython-*-x86_64-linux-gnu.so' ]),
77- ('pyrsistent==0.17.3' , [
78- 'pyrsistent/__init__.py' ]),
79- ]
80- )
150+ @pytest .mark .parametrize ('package,contents' , _get_package_install_test_cases ())
81151def test_package_install_smoke_tests (package , contents , runner , app_skeleton ):
82152 assert_can_package_dependency (runner , app_skeleton , package , contents )
83153
0 commit comments