@@ -95,30 +95,21 @@ def package_helper(container: TrackedContainer) -> CondaPackageHelper:
95
95
96
96
97
97
@pytest .fixture (scope = "function" )
98
- def packages (package_helper : CondaPackageHelper ) -> dict [str , set [str ]]:
98
+ def requested_packages (package_helper : CondaPackageHelper ) -> dict [str , set [str ]]:
99
99
"""Return the list of requested packages (i.e. packages explicitly installed excluding dependencies)"""
100
100
return package_helper .requested_packages ()
101
101
102
102
103
- def get_package_import_name (package : str ) -> str :
104
- """Perform a mapping between the python package name and the name used for the import"""
105
- return PACKAGE_MAPPING .get (package , package )
106
-
107
-
108
- def excluded_package_predicate (package : str ) -> bool :
109
- """Return whether a package is excluded from the list
110
- (i.e. a package that cannot be tested with standard imports)"""
111
- return package in EXCLUDED_PACKAGES
112
-
103
+ def is_r_package (package : str ) -> bool :
104
+ """Check if a package is an R package"""
105
+ return package .startswith ("r-" )
113
106
114
- def python_package_predicate (package : str ) -> bool :
115
- """Predicate matching python packages"""
116
- return not excluded_package_predicate (package ) and not r_package_predicate (package )
117
107
118
-
119
- def r_package_predicate (package : str ) -> bool :
120
- """Predicate matching R packages"""
121
- return not excluded_package_predicate (package ) and package .startswith ("r-" )
108
+ def get_package_import_name (package : str ) -> str :
109
+ """Perform a mapping between the package name and the name used for the import"""
110
+ if is_r_package (package ):
111
+ package = package [2 :]
112
+ return PACKAGE_MAPPING .get (package , package )
122
113
123
114
124
115
def _check_import_package (
@@ -127,9 +118,7 @@ def _check_import_package(
127
118
"""Generic function executing a command"""
128
119
LOGGER .debug (f"Trying to import a package with [{ command } ] ..." )
129
120
exec_result = package_helper .running_container .exec_run (command )
130
- assert (
131
- exec_result .exit_code == 0
132
- ), f"Import package failed, output: { exec_result .output } "
121
+ assert exec_result .exit_code == 0 , exec_result .output .decode ("utf-8" )
133
122
134
123
135
124
def check_import_python_package (
@@ -154,25 +143,26 @@ def _check_import_packages(
154
143
Note: using a list of packages instead of a fixture for the list of packages
155
144
since pytest prevents the use of multiple yields
156
145
"""
157
- failures = {}
146
+ failed_imports = []
158
147
LOGGER .info ("Testing the import of packages ..." )
159
148
for package in packages_to_check :
160
149
LOGGER .info (f"Trying to import { package } " )
161
150
try :
162
151
check_function (package_helper , package )
163
152
except AssertionError as err :
164
- failures [package ] = err
165
- if len (failures ) > 0 :
166
- raise AssertionError (failures )
153
+ failed_imports .append (package )
154
+ LOGGER .error (f"Failed to import package: { package } , output:\n { err } " )
155
+ if failed_imports :
156
+ pytest .fail (f"following packages are not import-able: { failed_imports } " )
167
157
168
158
169
159
@pytest .fixture (scope = "function" )
170
- def r_packages (packages : dict [str , set [str ]]) -> Iterable [str ]:
160
+ def r_packages (requested_packages : dict [str , set [str ]]) -> Iterable [str ]:
171
161
"""Return an iterable of R packages"""
172
- # package[2:] is to remove the leading "r-" appended on R packages
173
- return map (
174
- lambda package : get_package_import_name ( package [ 2 :]),
175
- filter ( r_package_predicate , packages ),
162
+ return (
163
+ get_package_import_name ( pkg )
164
+ for pkg in requested_packages
165
+ if is_r_package ( pkg ) and pkg not in EXCLUDED_PACKAGES
176
166
)
177
167
178
168
@@ -184,9 +174,13 @@ def test_r_packages(
184
174
185
175
186
176
@pytest .fixture (scope = "function" )
187
- def python_packages (packages : dict [str , set [str ]]) -> Iterable [str ]:
177
+ def python_packages (requested_packages : dict [str , set [str ]]) -> Iterable [str ]:
188
178
"""Return an iterable of Python packages"""
189
- return map (get_package_import_name , filter (python_package_predicate , packages ))
179
+ return (
180
+ get_package_import_name (pkg )
181
+ for pkg in requested_packages
182
+ if not is_r_package (pkg ) and pkg not in EXCLUDED_PACKAGES
183
+ )
190
184
191
185
192
186
def test_python_packages (
0 commit comments