@@ -243,6 +243,78 @@ def test_package_existed_helper():
243
243
assert not _utils ._package_existed ([], "pandas" )
244
244
245
245
246
+ def _function_add_one (x ):
247
+ return x + 1
248
+
249
+
250
+ def _function_add_two (x ):
251
+ return x + 2
252
+
253
+
254
+ @pytest .mark .parametrize (
255
+ "func1, func2, should_be_equal, description" ,
256
+ [
257
+ (
258
+ _function_add_one ,
259
+ _function_add_one ,
260
+ True ,
261
+ "Identical functions should have the same hash." ,
262
+ ),
263
+ (
264
+ _function_add_one ,
265
+ _function_add_two ,
266
+ False ,
267
+ "Different functions should have different hashes." ,
268
+ ),
269
+ ],
270
+ )
271
+ def test_get_hash_without_package_requirements (
272
+ func1 , func2 , should_be_equal , description
273
+ ):
274
+ """Tests function hashes without any requirements."""
275
+ hash1 = _utils .get_hash (func1 )
276
+ hash2 = _utils .get_hash (func2 )
277
+
278
+ if should_be_equal :
279
+ assert hash1 == hash2 , f"FAILED: { description } "
280
+ else :
281
+ assert hash1 != hash2 , f"FAILED: { description } "
282
+
283
+
284
+ @pytest .mark .parametrize (
285
+ "reqs1, reqs2, should_be_equal, description" ,
286
+ [
287
+ (
288
+ None ,
289
+ ["pandas>=1.0" ],
290
+ False ,
291
+ "Hash with or without requirements should differ from hash." ,
292
+ ),
293
+ (
294
+ ["pandas" , "numpy" , "scikit-learn" ],
295
+ ["numpy" , "scikit-learn" , "pandas" ],
296
+ True ,
297
+ "Same requirements should produce the same hash." ,
298
+ ),
299
+ (
300
+ ["pandas==1.0" ],
301
+ ["pandas==2.0" ],
302
+ False ,
303
+ "Different requirement versions should produce different hashes." ,
304
+ ),
305
+ ],
306
+ )
307
+ def test_get_hash_with_package_requirements (reqs1 , reqs2 , should_be_equal , description ):
308
+ """Tests how package requirements affect the final hash."""
309
+ hash1 = _utils .get_hash (_function_add_one , package_requirements = reqs1 )
310
+ hash2 = _utils .get_hash (_function_add_one , package_requirements = reqs2 )
311
+
312
+ if should_be_equal :
313
+ assert hash1 == hash2 , f"FAILED: { description } "
314
+ else :
315
+ assert hash1 != hash2 , f"FAILED: { description } "
316
+
317
+
246
318
# Helper functions for signature inspection tests
247
319
def _func_one_arg_annotated (x : int ) -> int :
248
320
"""A function with one annotated arg and an annotated return type."""
0 commit comments