Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add SimpleEnumV2 TestModel for Python #346

Merged
merged 2 commits into from
May 1, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/test_models_python_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
# TestModels/SimpleTypes/SimpleByte,
TestModels/SimpleTypes/SimpleDouble,
TestModels/SimpleTypes/SimpleEnum,
# TestModels/SimpleTypes/SimpleEnumV2,
TestModels/SimpleTypes/SimpleEnumV2,
# TestModels/SimpleTypes/SimpleFloat,
TestModels/SimpleTypes/SimpleInteger,
TestModels/SimpleTypes/SimpleLong,
Expand Down
3 changes: 3 additions & 0 deletions TestModels/SimpleTypes/SimpleEnumV2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ include ../../SharedMakefile.mk

NAMESPACE=simple.types.enumV2

# TODO-Python-PYTHONPATH: Move into dfyproject.toml
PYTHON_MODULE_NAME=simple_types_smithyenumv2

PROJECT_SERVICES := \
SimpleTypesEnumV2

Expand Down
25 changes: 25 additions & 0 deletions TestModels/SimpleTypes/SimpleEnumV2/runtimes/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[tool.poetry]
name = "simple-types-smithyenum-v2"
version = "0.1.0"
description = ""
authors = ["AWS <[email protected]>"]
packages = [
{ include = "simple_types_smithyenumv2", from = "src" }
]
# Include all of the following .gitignored files in package distributions,
# even though it is not included in version control
include = ["**/smithygenerated/**/*.py", "**/internaldafny/generated/*.py"]

[tool.poetry.dependencies]
python = "^3.11.0"
# TODO: Depend on PyPi once Smithy-Python publishes their Python package there
smithy-python = { path = "../../../../../codegen/smithy-dafny-codegen-modules/smithy-python/python-packages/smithy-python", develop = false}
standard-library = {path = "../../../../dafny-dependencies/StandardLibrary/runtimes/python", develop = false}
DafnyRuntimePython = "^4.4.0"

[tool.poetry.group.test.dependencies]
pytest = "^7.4.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# __init__.py for a Smithy-Dafny generated Python project

# TODO-Python: Remove PYTHONPATH workaround, use fully-qualified module names via dfyproject.toml.
# Import project dependencies.
# TODO-Python-PYTHONPATH: Remove dependency imports to initialize PYTHONPATH with their modules

import standard_library

# Add internaldafny and smithygenerated code to PYTHONPATH (TODO-Python-PYTHONPATH: Remove)
import sys

module_root_dir = '/'.join(__file__.split("/")[:-1])

sys.path.append(module_root_dir + "/internaldafny/extern")
sys.path.append(module_root_dir + "/internaldafny/generated")
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

# TODO-Python-PYTHONPATH: Qualify imports
import simple_types_enumv2_internaldafny_wrapped
from simple_types_smithyenumv2.smithygenerated.simple_types_enumv2.client import SimpleTypesEnumV2
from simple_types_smithyenumv2.smithygenerated.simple_types_enumv2.shim import SimpleEnumV2Shim
from simple_types_smithyenumv2.smithygenerated.simple_types_enumv2.config import dafny_config_to_smithy_config
import Wrappers

class default__(simple_types_enumv2_internaldafny_wrapped.default__):

@staticmethod
def WrappedSimpleEnumV2(config):
wrapped_config = dafny_config_to_smithy_config(config)
impl = SimpleTypesEnumV2(wrapped_config)
wrapped_client = SimpleEnumV2Shim(impl)
return Wrappers.Result_Success(wrapped_client)

# (TODO-Python-PYTHONPATH: Remove)
simple_types_enumv2_internaldafny_wrapped.default__ = default__
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Wrapper file for executing Dafny tests from pytest.
This allows us to import modules required by Dafny-generated tests
before executing Dafny-generated tests.
pytest will find and execute the `test_dafny` method below,
which will execute the `internaldafny_test_executor.py` file in the `dafny` directory.
"""

# TODO-Python-PYTHONPATH: Remove all sys.path.append logic from this file
import sys

internaldafny_dir = '/'.join(__file__.split("/")[:-1])

sys.path.append(internaldafny_dir + "/extern")
sys.path.append(internaldafny_dir + "/generated")

# Import modules required for Dafny-generated tests.
# This is not generated; these must be manually added.
# These are only imported to populate the PYTHONPATH.
# This can be removed once PYTHONPATH workaround is removed,
# and all Dafny-generated imports are fully qualified.
# TODO-Python-PYTHONPATH: Remove imports to initialize modules' PYTHONPATHs from this file
import simple_types_smithyenumv2
import wrapped_simple_enum

def test_dafny():
# Dafny tests are executed when importing `internaldafny_test_executor`
# TODO-Python-PYTHONPATH: Qualify import
import internaldafny_test_executor
13 changes: 13 additions & 0 deletions TestModels/SimpleTypes/SimpleEnumV2/runtimes/python/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[tox]
isolated_build = True
envlist =
py{311}

[testenv]
skip_install = true
allowlist_externals = poetry
commands_pre =
poetry lock
poetry install
commands =
poetry run pytest -s -v test/ --import-mode importlib
Loading