|
1 | 1 | # Copyright (c) Microsoft Corporation. |
2 | 2 | # Licensed under the MIT license. |
3 | 3 |
|
4 | | -"""Tests for package-level imports. |
| 4 | +"""Tests for package-level re-exports. |
5 | 5 |
|
6 | | -The three sub-packages (``core``, ``models``, ``operations``) deliberately keep |
7 | | -``__all__`` empty to avoid creating duplicate doc-tool entries for re-exported |
8 | | -symbols. Symbols are still importable from the package namespace because |
9 | | -Python's ``from package import Symbol`` does not consult ``__all__``. |
| 6 | +Each package (``PowerPlatform.Dataverse``, ``core``, ``models``, ``operations``) |
| 7 | +re-exports its public symbols and declares them in ``__all__``. This gives users |
| 8 | +short, stable import paths (``from PowerPlatform.Dataverse.models import Record``) |
| 9 | +that survive internal module reorganization. |
10 | 10 |
|
11 | 11 | These tests verify: |
12 | | -1. ``__all__`` is empty (locks in the design decision). |
13 | | -2. Every expected public symbol is still importable from the package namespace. |
14 | | -3. Each imported symbol is the same object as its source definition. |
| 12 | +1. ``__all__`` matches the expected list exactly (catches accidental drift). |
| 13 | +2. Every name in ``__all__`` is importable from the package namespace. |
| 14 | +3. Each re-export is the same object as its source definition. |
15 | 15 | """ |
16 | 16 |
|
17 | 17 | import unittest |
18 | 18 |
|
| 19 | +DATAVERSE_EXPECTED = [ |
| 20 | + "DataverseClient", |
| 21 | + "DataverseModel", |
| 22 | + "QueryResult", |
| 23 | + "__version__", |
| 24 | + "col", |
| 25 | + "raw", |
| 26 | +] |
| 27 | + |
19 | 28 | CORE_EXPECTED = [ |
20 | 29 | "DataverseConfig", |
21 | 30 | "DataverseError", |
|
71 | 80 | ] |
72 | 81 |
|
73 | 82 |
|
| 83 | +class TestDataverseTopLevelExports(unittest.TestCase): |
| 84 | + """Verify top-level PowerPlatform.Dataverse package exports.""" |
| 85 | + |
| 86 | + def test_all_matches_expected(self): |
| 87 | + """``__all__`` matches the expected list exactly.""" |
| 88 | + import PowerPlatform.Dataverse as m |
| 89 | + |
| 90 | + self.assertEqual(sorted(m.__all__), sorted(DATAVERSE_EXPECTED)) |
| 91 | + |
| 92 | + def test_expected_symbols_importable(self): |
| 93 | + """Every expected public symbol is reachable from the package namespace.""" |
| 94 | + import PowerPlatform.Dataverse as m |
| 95 | + |
| 96 | + for name in DATAVERSE_EXPECTED: |
| 97 | + self.assertTrue(hasattr(m, name), f"{name!r} not importable from PowerPlatform.Dataverse") |
| 98 | + |
| 99 | + def test_identity(self): |
| 100 | + """Re-exported objects are the same objects as their source definitions.""" |
| 101 | + import PowerPlatform.Dataverse as m |
| 102 | + from PowerPlatform.Dataverse.client import DataverseClient |
| 103 | + from PowerPlatform.Dataverse.models.filters import col, raw |
| 104 | + from PowerPlatform.Dataverse.models.protocol import DataverseModel |
| 105 | + from PowerPlatform.Dataverse.models.record import QueryResult |
| 106 | + |
| 107 | + self.assertIs(m.DataverseClient, DataverseClient) |
| 108 | + self.assertIs(m.DataverseModel, DataverseModel) |
| 109 | + self.assertIs(m.QueryResult, QueryResult) |
| 110 | + self.assertIs(m.col, col) |
| 111 | + self.assertIs(m.raw, raw) |
| 112 | + self.assertIsInstance(m.__version__, str) |
| 113 | + |
| 114 | + |
74 | 115 | class TestCoreExports(unittest.TestCase): |
75 | 116 | """Verify package-level imports for PowerPlatform.Dataverse.core.""" |
76 | 117 |
|
77 | | - def test_all_is_empty(self): |
78 | | - """``__all__`` is deliberately empty to avoid doc-tool duplication.""" |
| 118 | + def test_all_matches_expected(self): |
| 119 | + """``__all__`` matches the expected list exactly.""" |
79 | 120 | import PowerPlatform.Dataverse.core as m |
80 | 121 |
|
81 | | - self.assertEqual(m.__all__, []) |
| 122 | + self.assertEqual(sorted(m.__all__), sorted(CORE_EXPECTED)) |
82 | 123 |
|
83 | 124 | def test_expected_symbols_importable(self): |
84 | 125 | """Every expected public symbol is reachable from the package namespace.""" |
@@ -113,11 +154,11 @@ def test_identity(self): |
113 | 154 | class TestModelsExports(unittest.TestCase): |
114 | 155 | """Verify package-level imports for PowerPlatform.Dataverse.models.""" |
115 | 156 |
|
116 | | - def test_all_is_empty(self): |
117 | | - """``__all__`` is deliberately empty to avoid doc-tool duplication.""" |
| 157 | + def test_all_matches_expected(self): |
| 158 | + """``__all__`` matches the expected list exactly.""" |
118 | 159 | import PowerPlatform.Dataverse.models as m |
119 | 160 |
|
120 | | - self.assertEqual(m.__all__, []) |
| 161 | + self.assertEqual(sorted(m.__all__), sorted(MODELS_EXPECTED)) |
121 | 162 |
|
122 | 163 | def test_expected_symbols_importable(self): |
123 | 164 | """Every expected public symbol is reachable from the package namespace.""" |
@@ -175,11 +216,11 @@ def test_identity(self): |
175 | 216 | class TestOperationsExports(unittest.TestCase): |
176 | 217 | """Verify package-level imports for PowerPlatform.Dataverse.operations.""" |
177 | 218 |
|
178 | | - def test_all_is_empty(self): |
179 | | - """``__all__`` is deliberately empty to avoid doc-tool duplication.""" |
| 219 | + def test_all_matches_expected(self): |
| 220 | + """``__all__`` matches the expected list exactly.""" |
180 | 221 | import PowerPlatform.Dataverse.operations as m |
181 | 222 |
|
182 | | - self.assertEqual(m.__all__, []) |
| 223 | + self.assertEqual(sorted(m.__all__), sorted(OPERATIONS_EXPECTED)) |
183 | 224 |
|
184 | 225 | def test_expected_symbols_importable(self): |
185 | 226 | """Every expected public symbol is reachable from the package namespace.""" |
|
0 commit comments