Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
chore: fixing race condition in tests (xdist); more robust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aorumbayev committed Mar 26, 2024
1 parent 2215bf7 commit e1e4728
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 61 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/check-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ jobs:
# TODO: restore to algokit prior to release
run: pipx install git+https://github.com/algorandfoundation/algokit-cli@feat/command_orchestration

- name: Run algokit localnet
# TODO: restore to algokit prior to release
run: algokit localnet reset

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,7 @@ examples/**/poetry.lock
# playground folder for previewing templates
.playground/*
!.playground/.gitkeep

# Misc
examples/**/smart_contracts/artifacts
examples/**/.algokit/sources
5 changes: 4 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ This repository is a template for creating new AlgoKit projects. It includes a b
## Pre-requisites

`poetry install` - Install the dependencies for the project.
`pipx install algokit` - Ensure cli is installed.

## Testing

Ensure localnet is running by executing `algokit localnet reset`.

```bash
poetry run pytest
poetry run pytest -n auto
```

This will regenerate the tests for default `starter` and `production` presets as well as default tests for `generators` available on the template.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ def deploy(
if is_mainnet
else algokit_utils.OnSchemaBreak.ReplaceApp
),
on_update=algokit_utils.OnUpdate.AppendApp
if is_mainnet
else algokit_utils.OnUpdate.UpdateApp,
on_update=(
algokit_utils.OnUpdate.AppendApp
if is_mainnet
else algokit_utils.OnUpdate.UpdateApp
),
allow_delete=not is_mainnet,
allow_update=not is_mainnet,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
@dataclasses.dataclass
class SmartContract:
app: Application
deploy: Callable[
[AlgodClient, IndexerClient, ApplicationSpecification, Account], None
] | None = None
deploy: (
Callable[[AlgodClient, IndexerClient, ApplicationSpecification, Account], None]
| None
) = None


def import_contract(folder: Path) -> Application:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ def deploy(
if is_mainnet
else algokit_utils.OnSchemaBreak.ReplaceApp
),
on_update=algokit_utils.OnUpdate.AppendApp
if is_mainnet
else algokit_utils.OnUpdate.UpdateApp,
on_update=(
algokit_utils.OnUpdate.AppendApp
if is_mainnet
else algokit_utils.OnUpdate.UpdateApp
),
allow_delete=not is_mainnet,
allow_update=not is_mainnet,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ def deploy(
if is_mainnet
else algokit_utils.OnSchemaBreak.ReplaceApp
),
on_update=algokit_utils.OnUpdate.AppendApp
if is_mainnet
else algokit_utils.OnUpdate.UpdateApp,
on_update=(
algokit_utils.OnUpdate.AppendApp
if is_mainnet
else algokit_utils.OnUpdate.UpdateApp
),
allow_delete=not is_mainnet,
allow_update=not is_mainnet,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
@dataclasses.dataclass
class SmartContract:
app: Application
deploy: Callable[
[AlgodClient, IndexerClient, ApplicationSpecification, Account], None
] | None = None
deploy: (
Callable[[AlgodClient, IndexerClient, ApplicationSpecification, Account], None]
| None
) = None


def import_contract(folder: Path) -> Application:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
@dataclasses.dataclass
class SmartContract:
app: Application
deploy: Callable[
[AlgodClient, IndexerClient, ApplicationSpecification, Account], None
] | None = None
deploy: (
Callable[[AlgodClient, IndexerClient, ApplicationSpecification, Account], None]
| None
) = None


def import_contract(folder: Path) -> Application:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
@dataclasses.dataclass
class SmartContract:
app: Application
deploy: Callable[
[AlgodClient, IndexerClient, ApplicationSpecification, Account], None
] | None = None
deploy: (
Callable[[AlgodClient, IndexerClient, ApplicationSpecification, Account], None]
| None
) = None


def import_contract(folder: Path) -> Application:
Expand Down
7 changes: 4 additions & 3 deletions examples/production_beaker/smart_contracts/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
@dataclasses.dataclass
class SmartContract:
app: Application
deploy: Callable[
[AlgodClient, IndexerClient, ApplicationSpecification, Account], None
] | None = None
deploy: (
Callable[[AlgodClient, IndexerClient, ApplicationSpecification, Account], None]
| None
) = None


def import_contract(folder: Path) -> Application:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ def deploy(
if is_mainnet
else algokit_utils.OnSchemaBreak.ReplaceApp
),
on_update=algokit_utils.OnUpdate.AppendApp
if is_mainnet
else algokit_utils.OnUpdate.UpdateApp,
on_update=(
algokit_utils.OnUpdate.AppendApp
if is_mainnet
else algokit_utils.OnUpdate.UpdateApp
),
allow_delete=not is_mainnet,
allow_update=not is_mainnet,
)
Expand Down
7 changes: 4 additions & 3 deletions examples/starter_beaker/smart_contracts/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
@dataclasses.dataclass
class SmartContract:
app: Application
deploy: Callable[
[AlgodClient, IndexerClient, ApplicationSpecification, Account], None
] | None = None
deploy: (
Callable[[AlgodClient, IndexerClient, ApplicationSpecification, Account], None]
| None
) = None


def import_contract(folder: Path) -> Application:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ def deploy(
if is_mainnet
else algokit_utils.OnSchemaBreak.ReplaceApp
),
on_update=algokit_utils.OnUpdate.AppendApp
if is_mainnet
else algokit_utils.OnUpdate.UpdateApp,
on_update=(
algokit_utils.OnUpdate.AppendApp
if is_mainnet
else algokit_utils.OnUpdate.UpdateApp
),
allow_delete=not is_mainnet,
allow_update=not is_mainnet,
)
Expand Down
7 changes: 4 additions & 3 deletions template_content/smart_contracts/config.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ from beaker import Application
@dataclasses.dataclass
class SmartContract:
app: Application
deploy: Callable[
[AlgodClient, IndexerClient, ApplicationSpecification, Account], None
] | None = None
deploy: (
Callable[[AlgodClient, IndexerClient, ApplicationSpecification, Account], None]
| None
) = None


def import_contract(folder: Path) -> Application:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ def deploy(
if is_mainnet
else algokit_utils.OnSchemaBreak.ReplaceApp
),
on_update=algokit_utils.OnUpdate.AppendApp
if is_mainnet
else algokit_utils.OnUpdate.UpdateApp,
on_update=(
algokit_utils.OnUpdate.AppendApp
if is_mainnet
else algokit_utils.OnUpdate.UpdateApp
),
allow_delete=not is_mainnet,
allow_update=not is_mainnet,
)
Expand Down
21 changes: 11 additions & 10 deletions tests/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@
}
config_path = Path(__file__).parent.parent / "pyproject.toml"
BLACK_ARGS = ["black", "--check", "--diff", "--config", str(config_path), "."]
RUFF_ARGS = ["ruff", "--diff", "--config", str(config_path), "."]
MYPY_ARGS = [
"mypy",
"--ignore-missing-imports", # TODO: only ignore missing typed clients in config.py
".",
]
BUILD_ARGS = ["algokit", "project", "run", "build"]
TEST_ARGS = ["algokit", "project", "run", "test"]
LINT_ARGS = ["algokit", "project", "run", "lint"]


def _load_copier_yaml(path: Path) -> dict[str, str | bool | dict]:
Expand All @@ -52,7 +49,12 @@ def working_dir() -> Iterator[Path]:

dest_dir = generated_root / src_dir.stem
shutil.rmtree(dest_dir, ignore_errors=True)
shutil.copytree(src_dir, dest_dir, dirs_exist_ok=True)
shutil.copytree(
src_dir,
dest_dir,
dirs_exist_ok=True,
ignore=shutil.ignore_patterns(".*_cache", ".venv", "__pycache__"),
)


def run_init(
Expand Down Expand Up @@ -88,7 +90,6 @@ def run_init(
"--defaults",
"--no-ide",
"--no-git",
"--no-bootstrap",
"--no-workspace",
]
answers = {**DEFAULT_PARAMETERS, **(answers or {})}
Expand Down Expand Up @@ -121,13 +122,13 @@ def check_codebase(working_dir: Path, test_name: str) -> subprocess.CompletedPro
content = src_path_pattern.sub("_src_path: <src>", content)
copier_answers.write_text(content, "utf-8")

check_args = [BLACK_ARGS]
check_args = [BLACK_ARGS, BUILD_ARGS]

# Starter template does not have ruff config or mypy config by default
# so only check for them if the starter template is not used
processed_questions = _load_copier_yaml(copier_answers)
if processed_questions["preset_name"] == "production":
check_args += [RUFF_ARGS, MYPY_ARGS]
check_args += [LINT_ARGS, TEST_ARGS]

for check_arg in check_args:
result = subprocess.run(
Expand Down
23 changes: 12 additions & 11 deletions tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@
"author_email": "None",
}
config_path = Path(__file__).parent.parent / "pyproject.toml"
BLACK_ARGS = ["black", "--check", "--diff", "--config", str(config_path), "."]
RUFF_ARGS = ["ruff", "--diff", "--config", str(config_path), "."]
MYPY_ARGS = [
"mypy",
"--ignore-missing-imports", # TODO: only ignore missing typed clients in config.py
".",
]
BASELINE_LINT_ARGS = ["black", "--check", "--diff", "--config", str(config_path), "."]
BUILD_ARGS = ["algokit", "project", "run", "build"]
TEST_ARGS = ["algokit", "project", "run", "test"]
LINT_ARGS = ["algokit", "project", "run", "lint"]


def _load_copier_yaml(path: Path) -> dict[str, str | bool | dict]:
Expand All @@ -52,7 +49,12 @@ def working_dir() -> Iterator[Path]:

dest_dir = generated_root / src_dir.stem
shutil.rmtree(dest_dir, ignore_errors=True)
shutil.copytree(src_dir, dest_dir, dirs_exist_ok=True)
shutil.copytree(
src_dir,
dest_dir,
dirs_exist_ok=True,
ignore=shutil.ignore_patterns(".*_cache", ".venv", "__pycache__"),
)


def run_init(
Expand Down Expand Up @@ -88,7 +90,6 @@ def run_init(
"--defaults",
"--no-ide",
"--no-git",
"--no-bootstrap",
"--no-workspace",
]
answers = {**DEFAULT_PARAMETERS, **(answers or {})}
Expand Down Expand Up @@ -118,13 +119,13 @@ def run_init(
content = src_path_pattern.sub("_src_path: <src>", content)
copier_answers.write_text(content, "utf-8")

check_args = [BLACK_ARGS]
check_args = [BUILD_ARGS, BASELINE_LINT_ARGS]

# Starter template does not have ruff config or mypy config by default
# so only check for them if the starter template is not used
processed_questions = _load_copier_yaml(copier_answers)
if processed_questions["preset_name"] == "production":
check_args += [RUFF_ARGS, MYPY_ARGS]
check_args += [LINT_ARGS, TEST_ARGS]

for check_arg in check_args:
result = subprocess.run(
Expand Down

0 comments on commit e1e4728

Please sign in to comment.