Skip to content

Commit 057b27a

Browse files
committed
fix: proper public exports by __all__
1 parent 7e4ca9c commit 057b27a

2 files changed

Lines changed: 105 additions & 0 deletions

File tree

runpod/serverless/utils/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@
22

33
from .rp_download import download_files_from_urls
44
from .rp_upload import upload_file_to_bucket, upload_in_memory_object
5+
6+
__all__ = [
7+
"download_files_from_urls",
8+
"upload_file_to_bucket",
9+
"upload_in_memory_object"
10+
]
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
"""Tests for runpod.serverless.utils.__init__ module exports."""
2+
3+
import inspect
4+
import runpod.serverless.utils
5+
6+
7+
class TestServerlessUtilsInit:
8+
"""Test runpod.serverless.utils module __all__ exports."""
9+
10+
def test_all_defined(self):
11+
"""Test that __all__ is defined in the module."""
12+
assert hasattr(runpod.serverless.utils, '__all__')
13+
assert isinstance(runpod.serverless.utils.__all__, list)
14+
assert len(runpod.serverless.utils.__all__) > 0
15+
16+
def test_all_symbols_importable(self):
17+
"""Test that all symbols in __all__ are actually importable."""
18+
for symbol in runpod.serverless.utils.__all__:
19+
assert hasattr(runpod.serverless.utils, symbol), f"Symbol '{symbol}' in __all__ but not found in module"
20+
21+
def test_expected_public_symbols(self):
22+
"""Test that expected public symbols are in __all__."""
23+
expected_symbols = {
24+
'download_files_from_urls',
25+
'upload_file_to_bucket',
26+
'upload_in_memory_object'
27+
}
28+
actual_symbols = set(runpod.serverless.utils.__all__)
29+
assert expected_symbols == actual_symbols, f"Expected {expected_symbols}, got {actual_symbols}"
30+
31+
def test_utility_functions_accessible(self):
32+
"""Test that utility functions are accessible and callable."""
33+
utility_functions = [
34+
'download_files_from_urls',
35+
'upload_file_to_bucket',
36+
'upload_in_memory_object'
37+
]
38+
39+
for func_name in utility_functions:
40+
assert func_name in runpod.serverless.utils.__all__
41+
assert hasattr(runpod.serverless.utils, func_name)
42+
assert callable(getattr(runpod.serverless.utils, func_name))
43+
44+
def test_download_function_signature(self):
45+
"""Test that download function has expected signature."""
46+
func = runpod.serverless.utils.download_files_from_urls
47+
sig = inspect.signature(func)
48+
# Check that it has some parameters (exact signature may vary)
49+
assert len(sig.parameters) > 0
50+
51+
def test_upload_functions_signatures(self):
52+
"""Test that upload functions have expected signatures."""
53+
upload_funcs = [
54+
runpod.serverless.utils.upload_file_to_bucket,
55+
runpod.serverless.utils.upload_in_memory_object
56+
]
57+
58+
for func in upload_funcs:
59+
sig = inspect.signature(func)
60+
# Check that it has some parameters (exact signature may vary)
61+
assert len(sig.parameters) > 0
62+
63+
def test_no_duplicate_symbols_in_all(self):
64+
"""Test that __all__ contains no duplicate symbols."""
65+
all_symbols = runpod.serverless.utils.__all__
66+
unique_symbols = set(all_symbols)
67+
assert len(all_symbols) == len(unique_symbols), f"Duplicates found in __all__: {[x for x in all_symbols if all_symbols.count(x) > 1]}"
68+
69+
def test_all_covers_public_api_only(self):
70+
"""Test that __all__ contains only the intended public API."""
71+
# Get all non-private attributes from the module
72+
module_attrs = {name for name in dir(runpod.serverless.utils)
73+
if not name.startswith('_')}
74+
75+
# Filter out any imported modules that shouldn't be public
76+
expected_private_attrs = set() # No private imports in this module
77+
78+
public_attrs = module_attrs - expected_private_attrs
79+
all_symbols = set(runpod.serverless.utils.__all__)
80+
81+
# All symbols in __all__ should be actual public API
82+
assert all_symbols.issubset(public_attrs), f"__all__ contains non-public symbols: {all_symbols - public_attrs}"
83+
84+
# Expected public API should be exactly what's in __all__
85+
expected_public_api = {
86+
'download_files_from_urls',
87+
'upload_file_to_bucket',
88+
'upload_in_memory_object'
89+
}
90+
assert all_symbols == expected_public_api, f"Expected {expected_public_api}, got {all_symbols}"
91+
92+
def test_functions_from_correct_modules(self):
93+
"""Test that functions are imported from the expected modules."""
94+
# download_files_from_urls should be from rp_download
95+
# upload functions should be from rp_upload
96+
# We can't easily test the source module, but we can test they exist
97+
assert hasattr(runpod.serverless.utils, 'download_files_from_urls')
98+
assert hasattr(runpod.serverless.utils, 'upload_file_to_bucket')
99+
assert hasattr(runpod.serverless.utils, 'upload_in_memory_object')

0 commit comments

Comments
 (0)