Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions sdks/python/pmxt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@
NetworkError,
ExchangeNotAvailable,
)
from ._hosted_errors import (
HostedTradingError,
InsufficientEscrowBalance,
OrderSizeTooSmall,
InvalidApiKey,
OutcomeNotFound,
CatalogUnavailable,
BuiltOrderExpired,
InvalidSignature,
NoLiquidity,
MissingWalletAddress,
)
from .models import (
UnifiedMarket,
UnifiedEvent,
Expand Down Expand Up @@ -225,6 +237,16 @@ def restart_server() -> None:
"ValidationError",
"NetworkError",
"ExchangeNotAvailable",
"HostedTradingError",
"InsufficientEscrowBalance",
"OrderSizeTooSmall",
"InvalidApiKey",
"OutcomeNotFound",
"CatalogUnavailable",
"BuiltOrderExpired",
"InvalidSignature",
"NoLiquidity",
"MissingWalletAddress",
# Data Models
"UnifiedMarket",
"UnifiedEvent",
Expand Down
43 changes: 43 additions & 0 deletions sdks/python/tests/test_public_exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,49 @@
from pathlib import Path


def test_hosted_trading_errors_are_top_level_public_exports():
import pmxt
from pmxt import _hosted_errors

init_path = Path(__file__).resolve().parents[1] / "pmxt" / "__init__.py"
tree = ast.parse(init_path.read_text(encoding="utf-8"))
expected = {
"HostedTradingError",
"InsufficientEscrowBalance",
"OrderSizeTooSmall",
"InvalidApiKey",
"OutcomeNotFound",
"CatalogUnavailable",
"BuiltOrderExpired",
"InvalidSignature",
"NoLiquidity",
"MissingWalletAddress",
}
imported_hosted_errors = set()
public_exports = set()

for node in tree.body:
if isinstance(node, ast.ImportFrom) and node.module == "_hosted_errors":
imported_hosted_errors.update(alias.name for alias in node.names)
elif (
isinstance(node, ast.Assign)
and len(node.targets) == 1
and isinstance(node.targets[0], ast.Name)
and node.targets[0].id == "__all__"
and isinstance(node.value, ast.List)
):
public_exports.update(
item.value
for item in node.value.elts
if isinstance(item, ast.Constant) and isinstance(item.value, str)
)

assert expected <= imported_hosted_errors
assert expected <= public_exports
for name in expected:
assert getattr(pmxt, name) is getattr(_hosted_errors, name)


def test_websocket_return_types_are_public_exports():
init_path = Path(__file__).resolve().parents[1] / "pmxt" / "__init__.py"
tree = ast.parse(init_path.read_text(encoding="utf-8"))
Expand Down