Skip to content

Commit 4bdfe3f

Browse files
authored
refactor: moving implementation into private namespace; refining docs; configuring api docs (#17)
1 parent 596c72f commit 4bdfe3f

File tree

102 files changed

+568
-533
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+568
-533
lines changed

docs/api.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
# API Reference
22

3-
```{autodoc2-summary}
4-
:renderer: myst
3+
## Contexts
54

5+
```{autodoc2-summary}
66
algopy_testing.AlgopyTestContext
77
algopy_testing.LedgerContext
88
algopy_testing.TransactionContext
9+
```
10+
11+
## Value Generators
12+
13+
```{autodoc2-summary}
914
algopy_testing.AVMValueGenerator
10-
algopy_testing.TxnValueGenerator
1115
algopy_testing.ARC4ValueGenerator
16+
algopy_testing.TxnValueGenerator
1217
```
1318

14-
> TODO: 1.0 Restructure algopy_testing index file once refactoring changes are merged
19+
## Inner transaction loaders
20+
21+
```{autodoc2-summary}
22+
algopy_testing.ITxnGroupLoader
23+
algopy_testing.ITxnLoader
24+
```
25+
26+
## Utils
27+
28+
```{autodoc2-summary}
29+
algopy_testing.algopy_testing_context
30+
algopy_testing.arc4_prefix
31+
```

docs/conf.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@
6161
autodoc2_packages = [
6262
{
6363
"path": "../src/algopy_testing",
64-
"auto_mode": False,
64+
"auto_mode": True,
65+
},
66+
{
67+
"path": "../src/_algopy_testing",
68+
"auto_mode": True,
6569
},
6670
]
6771
autodoc2_render_plugin = "myst"

docs/coverage.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Coverage
22

3-
See which `algorand-python` stubs are implemented by the `algorand-python-testing` library. See the [Concepts](testing-guide/concepts.md#types-of-algopy-stub-implementations) section for more details on the implementation categories.
4-
5-
Based on the definitions provided and the implementation details in the `src` directory, here is the classification for the abstractions outlined in the table under the `Name` column:
3+
See which `algorand-python` stubs are implemented by the `algorand-python-testing` library. See the [Concepts](testing-guide/concepts.md#types-of-algopy-stub-implementations) section for more details on the implementation categories. Refer to the [`algorand-python` stubs API](api.md) for the full list of the stubs for which the `algorand-python-testing` library provides implementations referenced in the table below.
64

75
| Name | Implementation type |
86
| ------------------------------------------- | ------------------- |
@@ -159,4 +157,3 @@ Based on the definitions provided and the implementation details in the `src` di
159157
| algopy.op.EllipticCurve | Mockable |
160158
| algopy.op.VrfVerify | Mockable |
161159
| algopy.op.vrf_verify | Mockable |
162-

examples/zk_whitelist/test_contract.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
import algopy
55
import pytest
6-
from algopy_testing import AlgopyTestContext, algopy_testing_context
7-
from algopy_testing.utils import arc4_prefix
6+
from algopy_testing import AlgopyTestContext, algopy_testing_context, arc4_prefix
87

98
from .contract import ZkWhitelistContract
109

src/_algopy_testing/__init__.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
from _algopy_testing import arc4, gtxn, itxn
2+
from _algopy_testing._context_helpers.context_storage import algopy_testing_context
3+
from _algopy_testing._context_helpers.ledger_context import LedgerContext
4+
from _algopy_testing._context_helpers.txn_context import TransactionContext
5+
from _algopy_testing._itxn_loader import ITxnGroupLoader, ITxnLoader
6+
from _algopy_testing._value_generators.arc4 import ARC4ValueGenerator
7+
from _algopy_testing._value_generators.avm import AVMValueGenerator
8+
from _algopy_testing._value_generators.txn import TxnValueGenerator
9+
from _algopy_testing.context import AlgopyTestContext
10+
from _algopy_testing.decorators.subroutine import subroutine
11+
from _algopy_testing.enums import OnCompleteAction, TransactionType
12+
from _algopy_testing.models import (
13+
Account,
14+
Application,
15+
ARC4Contract,
16+
Asset,
17+
Contract,
18+
LogicSig,
19+
StateTotals,
20+
TemplateVar,
21+
logicsig,
22+
uenumerate,
23+
urange,
24+
)
25+
from _algopy_testing.primitives import BigUInt, Bytes, String, UInt64
26+
from _algopy_testing.state import Box, BoxMap, BoxRef, GlobalState, LocalState
27+
28+
# TODO: clean up and ensure only algopy_testing namespace specific user facing abstractions
29+
# are exposed Only keep the _value_generators, ledger_context, txn_context,
30+
# context, and arc4_prexif from utils (make utils private)
31+
__all__ = [
32+
"ARC4Contract",
33+
"ARC4ValueGenerator",
34+
"Account",
35+
"AlgopyTestContext",
36+
"Application",
37+
"Asset",
38+
"BigUInt",
39+
"Box",
40+
"BoxMap",
41+
"BoxRef",
42+
"Bytes",
43+
"Contract",
44+
"GlobalState",
45+
"LocalState",
46+
"LogicSig",
47+
"ITxnLoader",
48+
"TxnValueGenerator",
49+
"ITxnGroupLoader",
50+
"OnCompleteAction",
51+
"StateTotals",
52+
"String",
53+
"TemplateVar",
54+
"LedgerContext",
55+
"TransactionContext",
56+
"AVMValueGenerator",
57+
"TxnValueGenerator",
58+
"TransactionType",
59+
"UInt64",
60+
"algopy_testing_context",
61+
"arc4",
62+
"gtxn",
63+
"itxn",
64+
"logicsig",
65+
"subroutine",
66+
"uenumerate",
67+
"urange",
68+
]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import dataclasses
55
import typing
66

7-
from algopy_testing.utils import raise_mocked_function_error
7+
from _algopy_testing.utils import raise_mocked_function_error
88

99
if typing.TYPE_CHECKING:
1010
from collections.abc import Mapping
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from _algopy_testing._context_helpers.context_storage import (
2+
algopy_testing_context,
3+
lazy_context,
4+
)
5+
from _algopy_testing._context_helpers.ledger_context import LedgerContext
6+
from _algopy_testing._context_helpers.txn_context import TransactionContext
7+
8+
__all__ = [
9+
"LedgerContext",
10+
"TransactionContext",
11+
"algopy_testing_context",
12+
"lazy_context",
13+
]

src/algopy_testing/_context_helpers/context_storage.py renamed to src/_algopy_testing/_context_helpers/context_storage.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
import algopy
1111

12-
from algopy_testing._context_helpers.ledger_context import LedgerContext
13-
from algopy_testing._context_helpers.txn_context import TransactionContext, TransactionGroup
14-
from algopy_testing._value_generators import AlgopyValueGenerator
15-
from algopy_testing.context import AlgopyTestContext
16-
from algopy_testing.models.account import AccountContextData
17-
from algopy_testing.models.application import ApplicationContextData
18-
from algopy_testing.models.asset import AssetFields
12+
from _algopy_testing._context_helpers.ledger_context import LedgerContext
13+
from _algopy_testing._context_helpers.txn_context import TransactionContext, TransactionGroup
14+
from _algopy_testing._value_generators import AlgopyValueGenerator
15+
from _algopy_testing.context import AlgopyTestContext
16+
from _algopy_testing.models.account import AccountContextData
17+
from _algopy_testing.models.application import ApplicationContextData
18+
from _algopy_testing.models.asset import AssetFields
1919

2020
_var: ContextVar[AlgopyTestContext] = ContextVar("_var")
2121

@@ -97,7 +97,12 @@ def algopy_testing_context(
9797
*,
9898
default_sender: str | None = None,
9999
) -> Generator[AlgopyTestContext, None, None]:
100-
from algopy_testing.context import AlgopyTestContext
100+
"""Context manager for the AlgopyTestContext.
101+
102+
Args:
103+
default_sender: The default sender for the context.
104+
"""
105+
from _algopy_testing.context import AlgopyTestContext
101106

102107
token = _var.set(
103108
AlgopyTestContext(

src/algopy_testing/_context_helpers/ledger_context.py renamed to src/_algopy_testing/_context_helpers/ledger_context.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
import typing
44
from collections import defaultdict
55

6-
from algopy_testing.constants import MAX_BOX_SIZE
7-
from algopy_testing.models.account import Account
8-
from algopy_testing.primitives.uint64 import UInt64
9-
from algopy_testing.utils import as_bytes, assert_address_is_valid, get_default_global_fields
6+
from _algopy_testing.constants import MAX_BOX_SIZE
7+
from _algopy_testing.models.account import Account
8+
from _algopy_testing.primitives.uint64 import UInt64
9+
from _algopy_testing.utils import as_bytes, assert_address_is_valid, get_default_global_fields
1010

1111
if typing.TYPE_CHECKING:
1212
import algopy
1313

14-
from algopy_testing.models.account import AccountFields
15-
from algopy_testing.models.application import ApplicationContextData, ApplicationFields
16-
from algopy_testing.models.asset import AssetFields
17-
from algopy_testing.op.global_values import GlobalFields
14+
from _algopy_testing.models.account import AccountFields
15+
from _algopy_testing.models.application import ApplicationContextData, ApplicationFields
16+
from _algopy_testing.models.asset import AssetFields
17+
from _algopy_testing.op.global_values import GlobalFields
1818

1919

2020
class LedgerContext:
2121
"""Context for managing the ledger state."""
2222

2323
def __init__(self) -> None:
24-
from algopy_testing.models.account import AccountContextData, get_empty_account
24+
from _algopy_testing.models.account import AccountContextData, get_empty_account
2525

2626
self.account_data = defaultdict[str, AccountContextData](get_empty_account)
2727
self.app_data: dict[int, ApplicationContextData] = {}
@@ -374,7 +374,7 @@ def patch_global_fields(self, **global_fields: typing.Unpack[GlobalFields]) -> N
374374
Raises:
375375
AttributeError: If invalid fields are provided.
376376
"""
377-
from algopy_testing.op.global_values import GlobalFields
377+
from _algopy_testing.op.global_values import GlobalFields
378378

379379
invalid_keys = global_fields.keys() - GlobalFields.__annotations__.keys()
380380

@@ -436,8 +436,8 @@ def _get_app_id(app: algopy.UInt64 | algopy.Application | algopy.Contract | int)
436436
Raises:
437437
TypeError: If an invalid type is provided.
438438
"""
439-
from algopy_testing.models import Application, Contract
440-
from algopy_testing.primitives import UInt64
439+
from _algopy_testing.models import Application, Contract
440+
from _algopy_testing.primitives import UInt64
441441

442442
if isinstance(app, Contract):
443443
app_id = app.__app_id__

src/algopy_testing/_context_helpers/txn_context.py renamed to src/_algopy_testing/_context_helpers/txn_context.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,30 @@
55

66
import algosdk
77

8-
from algopy_testing._itxn_loader import ITxnGroupLoader
9-
from algopy_testing.decorators.arc4 import (
8+
from _algopy_testing._itxn_loader import ITxnGroupLoader
9+
from _algopy_testing.decorators.arc4 import (
1010
check_routing_conditions,
1111
create_abimethod_txns,
1212
create_baremethod_txns,
1313
get_arc4_metadata,
1414
get_ordered_args,
1515
)
16-
from algopy_testing.enums import OnCompleteAction
16+
from _algopy_testing.enums import OnCompleteAction
1717

1818
if typing.TYPE_CHECKING:
1919
from collections.abc import Callable, Iterator, Sequence
2020

2121
import algopy
2222

23-
from algopy_testing._itxn_loader import InnerTransactionResultType
24-
from algopy_testing.models.txn_fields import ActiveTransactionFields
23+
from _algopy_testing._itxn_loader import InnerTransactionResultType
24+
from _algopy_testing.models.txn_fields import ActiveTransactionFields
2525

26-
from algopy_testing import gtxn
27-
from algopy_testing._itxn_loader import ITxnLoader
28-
from algopy_testing.gtxn import TransactionBase
29-
from algopy_testing.itxn import InnerTransaction, submit_txns
30-
from algopy_testing.models import Application
31-
from algopy_testing.primitives import UInt64
26+
from _algopy_testing import gtxn
27+
from _algopy_testing._itxn_loader import ITxnLoader
28+
from _algopy_testing.gtxn import TransactionBase
29+
from _algopy_testing.itxn import InnerTransaction, submit_txns
30+
from _algopy_testing.models import Application
31+
from _algopy_testing.primitives import UInt64
3232

3333
TReturn = typing.TypeVar("TReturn")
3434
TParamSpec = typing.ParamSpec("TParamSpec")
@@ -56,6 +56,8 @@ def submit(self) -> TReturn:
5656

5757

5858
class TransactionContext:
59+
"""Context for managing transaction groups and active transactions."""
60+
5961
def __init__(self) -> None:
6062
self._groups: list[TransactionGroup] = []
6163
self._active_group: TransactionGroup | None = None
@@ -91,7 +93,7 @@ def defer_app_call(
9193
) -> DeferredAppCall[TReturn]:
9294
r"""Prepare an application call transaction group for a contract method without
9395
executing it."""
94-
from algopy_testing.models import ARC4Contract
96+
from _algopy_testing.models import ARC4Contract
9597

9698
arc4_metadata = get_arc4_metadata(method)
9799
# unwrap instance method

0 commit comments

Comments
 (0)