|
| 1 | +"""Test module imports and package-level functionality.""" |
| 2 | + |
| 3 | + |
| 4 | +class TestPackageImports: |
| 5 | + """Test cases for package imports.""" |
| 6 | + |
| 7 | + def test_main_package_imports(self): |
| 8 | + """Test importing main classes from the package.""" |
| 9 | + # This should import all main classes and trigger __init__.py coverage |
| 10 | + from apihub_client import ( |
| 11 | + ApiHubClient, |
| 12 | + ApiHubClientException, |
| 13 | + DocSplitterClient, |
| 14 | + GenericUnstractClient, |
| 15 | + ) |
| 16 | + |
| 17 | + # Verify classes are importable and are actually classes |
| 18 | + assert ApiHubClient is not None |
| 19 | + assert ApiHubClientException is not None |
| 20 | + assert DocSplitterClient is not None |
| 21 | + assert GenericUnstractClient is not None |
| 22 | + |
| 23 | + # Verify they are actually classes/exceptions |
| 24 | + assert callable(ApiHubClient) |
| 25 | + assert callable(ApiHubClientException) |
| 26 | + assert callable(DocSplitterClient) |
| 27 | + assert callable(GenericUnstractClient) |
| 28 | + |
| 29 | + def test_package_metadata(self): |
| 30 | + """Test package metadata is accessible.""" |
| 31 | + import apihub_client |
| 32 | + |
| 33 | + # Check metadata attributes exist |
| 34 | + assert hasattr(apihub_client, "__version__") |
| 35 | + assert hasattr(apihub_client, "__author__") |
| 36 | + assert hasattr(apihub_client, "__email__") |
| 37 | + assert hasattr(apihub_client, "__all__") |
| 38 | + |
| 39 | + # Check metadata values |
| 40 | + assert apihub_client.__version__ == "0.1.1" |
| 41 | + assert apihub_client.__author__ == "Unstract Team" |
| 42 | + assert apihub_client. __email__ == "[email protected]" |
| 43 | + |
| 44 | + # Check __all__ contains expected items |
| 45 | + expected_all = [ |
| 46 | + "ApiHubClient", |
| 47 | + "ApiHubClientException", |
| 48 | + "DocSplitterClient", |
| 49 | + "GenericUnstractClient", |
| 50 | + ] |
| 51 | + assert apihub_client.__all__ == expected_all |
| 52 | + |
| 53 | + def test_direct_module_imports(self): |
| 54 | + """Test direct module imports work.""" |
| 55 | + from apihub_client.client import ApiHubClient, ApiHubClientException |
| 56 | + from apihub_client.doc_splitter import DocSplitterClient |
| 57 | + from apihub_client.generic_client import GenericUnstractClient |
| 58 | + |
| 59 | + # Verify classes are importable |
| 60 | + assert ApiHubClient is not None |
| 61 | + assert ApiHubClientException is not None |
| 62 | + assert DocSplitterClient is not None |
| 63 | + assert GenericUnstractClient is not None |
| 64 | + |
| 65 | + def test_client_instantiation(self): |
| 66 | + """Test that clients can be instantiated from package imports.""" |
| 67 | + from apihub_client import ( |
| 68 | + ApiHubClient, |
| 69 | + DocSplitterClient, |
| 70 | + GenericUnstractClient, |
| 71 | + ) |
| 72 | + |
| 73 | + # Test ApiHubClient instantiation |
| 74 | + api_client = ApiHubClient(api_key="test_key", base_url="https://test.com") |
| 75 | + assert api_client.api_key == "test_key" |
| 76 | + assert api_client.base_url == "https://test.com" |
| 77 | + |
| 78 | + # Test DocSplitterClient instantiation |
| 79 | + doc_client = DocSplitterClient(api_key="test_key", base_url="https://test.com") |
| 80 | + assert doc_client.api_key == "test_key" |
| 81 | + assert doc_client.base_url == "https://test.com" |
| 82 | + |
| 83 | + # Test GenericUnstractClient instantiation |
| 84 | + generic_client = GenericUnstractClient( |
| 85 | + api_key="test_key", base_url="https://test.com" |
| 86 | + ) |
| 87 | + assert generic_client.api_key == "test_key" |
| 88 | + assert generic_client.base_url == "https://test.com" |
| 89 | + |
| 90 | + def test_exception_instantiation(self): |
| 91 | + """Test that exception can be instantiated from package imports.""" |
| 92 | + from apihub_client import ApiHubClientException |
| 93 | + |
| 94 | + # Test exception creation |
| 95 | + exc = ApiHubClientException("Test message", 400) |
| 96 | + assert exc.message == "Test message" |
| 97 | + assert exc.status_code == 400 |
| 98 | + |
| 99 | + # Test exception string representation |
| 100 | + str_repr = str(exc) |
| 101 | + assert "Test message" in str_repr |
| 102 | + assert "400" in str_repr |
| 103 | + |
| 104 | + def test_star_import(self): |
| 105 | + """Test that star import works correctly.""" |
| 106 | + # This imports everything in __all__ |
| 107 | + exec("from apihub_client import *") # noqa: S102 |
| 108 | + |
| 109 | + # Check that the main classes are available in local scope |
| 110 | + locals_dict = locals() |
| 111 | + assert "ApiHubClient" in locals_dict |
| 112 | + assert "ApiHubClientException" in locals_dict |
| 113 | + assert "DocSplitterClient" in locals_dict |
| 114 | + assert "GenericUnstractClient" in locals_dict |
| 115 | + |
| 116 | + def test_package_docstring(self): |
| 117 | + """Test package docstring is accessible.""" |
| 118 | + import apihub_client |
| 119 | + |
| 120 | + assert apihub_client.__doc__ is not None |
| 121 | + assert "Unstract API Hub Python Client" in apihub_client.__doc__ |
| 122 | + assert "dynamic, extensible Python client" in apihub_client.__doc__ |
| 123 | + |
| 124 | + def test_import_order_independence(self): |
| 125 | + """Test that imports work regardless of order.""" |
| 126 | + # Import in different order |
| 127 | + from apihub_client import ( |
| 128 | + ApiHubClient, # noqa: F401 |
| 129 | + ApiHubClientException, # noqa: F401 |
| 130 | + DocSplitterClient, # noqa: F401 |
| 131 | + GenericUnstractClient, |
| 132 | + ) |
| 133 | + |
| 134 | + # Should work fine |
| 135 | + client = GenericUnstractClient(api_key="test", base_url="https://test.com") |
| 136 | + assert client.api_key == "test" |
| 137 | + |
| 138 | + def test_submodule_access(self): |
| 139 | + """Test that submodules are accessible through the package.""" |
| 140 | + import apihub_client |
| 141 | + |
| 142 | + # Should be able to access submodules |
| 143 | + assert hasattr(apihub_client, "client") |
| 144 | + assert hasattr(apihub_client, "doc_splitter") |
| 145 | + assert hasattr(apihub_client, "generic_client") |
| 146 | + |
| 147 | + # Should be able to access classes through submodules |
| 148 | + assert hasattr(apihub_client.client, "ApiHubClient") |
| 149 | + assert hasattr(apihub_client.client, "ApiHubClientException") |
| 150 | + assert hasattr(apihub_client.doc_splitter, "DocSplitterClient") |
| 151 | + assert hasattr(apihub_client.generic_client, "GenericUnstractClient") |
0 commit comments