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

feat!: rework package to facilitate worker agent integ tests #6

Merged
merged 5 commits into from
Sep 5, 2023
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
87 changes: 79 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,101 @@
## Deadline Test Scaffolding
# Deadline Cloud Test Fixtures
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For folk to be able to use this it would be ideal to have the minimal IAM Policy that one needs to use the fixtures (i.e. deploy the Cfn stacks) in the README.

Figuring that out can be some serious whack-a-mole, so let's not hold up this PR to gather that, but we will need to figure out that minimal policy when integrating this in to our integration test runners.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I've got a backlog ticket to address this


# Build / Test / Release
This package contains pytest fixtures that are used to test Deadline Cloud Python packages.

## Setup Code Artifact
## Usage

## Build the package.
To use this package:
1. Install it into your test environment
1. Configure environment variables needed for your tests (see [src/deadline_test_fixtures/example_config.sh](https://github.com/casillas2/deadline-cloud-test-fixtures/blob/mainline/src/deadline_test_fixtures/example_config.sh) for available options)
1. Use the fixtures in your tests (see [src/deadline_test_fixtures/fixtures.py](https://github.com/casillas2/deadline-cloud-test-fixtures/blob/mainline/src/deadline_test_fixtures/fixtures.py) for available fixtures)

For example, to use the `worker` fixture:

```py
from deadline_test_fixtures import DeadlineWorker

def test_something_with_the_worker(worker: DeadlineWorker) -> None:
# GIVEN
worker.start()

# WHEN
result = worker.send_command("some command")

# THEN
assert result.stdout == "expected output"
```

You can also import the classes from this package directly to build your own fixtures

```py
# double_worker.py
from deadline_test_fixtures import (
DeadlineWorker,
EC2InstanceWorker,
DockerContainerWorker,
)

class DoubleWorker(DeadlineWorker):

def __init__(
self,
# args...
) -> None:
self.ec2_worker = EC2InstanceWorker(
# args...
)
self.docker_worker = DockerContainerWorker(
# args...
)

def start(self) -> None:
self.ec2_worker.start()
self.docker_worker.start()

# etc.


# test_something.py
from .double_worker import DoubleWorker

import pytest

@pytest.fixture
def double_worker() -> DoubleWorker:
return DoubleWorker(
# args...
)

def test_something(double_worker: DoubleWorker) -> None:
# GIVEN
double_worker.start()

# etc.
```

## Build / Test / Release

### Build the package.
```
hatch build
```

## Run tests
### Run tests
```
hatch run test
```

## Run linting
### Run linting
```
hatch run lint
```

## Run formating
### Run formating
```
hatch run fmt
```

## Run a tests for all supported Python versions.
### Run a tests for all supported Python versions.
```
hatch run all:test
```
Expand Down
2 changes: 1 addition & 1 deletion hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pre-install-commands = [

[envs.default.scripts]
sync = "pip install -r requirements-testing.txt"
test = "pytest --cov-config pyproject.toml {args:test/unit}"
test = "pytest --cov-config pyproject.toml {args:test}"
typing = "mypy {args:src test}"
style = [
"ruff {args:.}",
Expand Down
47 changes: 28 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ dynamic = ["version"]
requires-python = ">=3.7"

dependencies = [
"boto3 ~= 1.26",
"boto3 ~= 1.26",
]

[project.entry-points.pytest11]
deadline_test_scaffolding = "deadline_test_scaffolding.fixtures"
deadline_test_fixtures = "deadline_test_fixtures.fixtures"

[tool.hatch.build]
artifacts = [
Expand All @@ -36,7 +36,7 @@ sources = [
"_version.py",
]
destinations = [
"src/deadline_test_scaffolding",
"src/deadline_test_fixtures",
]

[tool.hatch.build.targets.sdist]
Expand All @@ -47,7 +47,7 @@ include = [

[tool.hatch.build.targets.wheel]
packages = [
"src/deadline_test_scaffolding"
"src/deadline_test_fixtures"
]

[tool.mypy]
Expand All @@ -58,11 +58,15 @@ files = [ "src/**/*.py" ]

[[tool.mypy.overrides]]
module = [
"boto3",
"botocore.*"
"boto3",
"botocore.*"
]
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "moto"
ignore_missing_imports = true

[tool.ruff]
ignore = [
"E501",
Expand All @@ -71,7 +75,7 @@ line-length = 100

[tool.ruff.isort]
known-first-party = [
"deadline_test_scaffolding"
"deadline_test_fixtures"
]

[tool.black]
Expand All @@ -80,26 +84,31 @@ line-length = 100
[tool.pytest.ini_options]
xfail_strict = true
addopts = [
"--durations=5",
"--cov=src/deadline_test_scaffolding",
"--color=yes",
"--cov-report=html:build/coverage",
"--cov-report=xml:build/coverage/coverage.xml",
"--cov-report=term-missing",
"--numprocesses=auto",
"--durations=5",
"--cov=src/deadline_test_fixtures",
"--color=yes",
"--cov-report=html:build/coverage",
"--cov-report=xml:build/coverage/coverage.xml",
"--cov-report=term-missing",
"--numprocesses=auto",
]
testpaths = [ "test" ]
looponfailroots = [
"src",
"test",
"src",
"test",
]
# looponfailroots is deprecated, this removes the deprecation from the test output
filterwarnings = [
"ignore::DeprecationWarning"
"ignore::DeprecationWarning"
]

[tool.coverage.run]
source_pkgs = [ "deadline_test_scaffolding" ]
source_pkgs = [ "deadline_test_fixtures" ]
omit = [
"models.py",
"fixtures.py",
"deadline/stubs.py",
]


[tool.coverage.paths]
Expand All @@ -108,4 +117,4 @@ source = [
]

[tool.coverage.report]
show_missing = true
show_missing = true
1 change: 1 addition & 0 deletions requirements-testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pytest-cov ~= 4.1
pytest-timeout ~= 2.1
pytest-xdist ~= 3.3
black ~= 23.7
moto[all] ~= 4.2
mypy == 1.5.0
ruff ~= 0.0.284
twine ~= 4.0
4 changes: 2 additions & 2 deletions scripts/add_copyright_headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ if [ $# -eq 0 ]; then
fi

for file in "$@"; do
if ! head -1 | grep 'Copyright ' "$file" >/dev/null; then
case $file in
if ! head -1 "$file" | grep 'Copyright ' >/dev/null; then
case "$file" in
*.java)
CONTENT=$(cat "$file")
cat > "$file" <<EOF
Expand Down
66 changes: 66 additions & 0 deletions src/deadline_test_fixtures/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
from .deadline import (
CommandResult,
DeadlineClient,
DeadlineWorker,
DeadlineWorkerConfiguration,
DockerContainerWorker,
EC2InstanceWorker,
Job,
Farm,
Fleet,
PipInstall,
Queue,
QueueFleetAssociation,
TaskStatus,
)
from .fixtures import (
BootstrapResources,
DeadlineResources,
bootstrap_resources,
deadline_client,
deadline_resources,
deploy_job_attachment_resources,
worker,
)
from .job_attachment_manager import JobAttachmentManager
from .models import (
CodeArtifactRepositoryInfo,
JobAttachmentSettings,
S3Object,
ServiceModel,
)
from ._version import __version__ as version # noqa

__all__ = [
"BootstrapResources",
"CodeArtifactRepositoryInfo",
"CommandResult",
"DeadlineResources",
"DeadlineClient",
"DeadlineScaffolding",
"DeadlineSubmitter",
"DeadlineJob",
"DeadlineWorker",
"DeadlineWorkerConfiguration",
"DockerContainerWorker",
"EC2InstanceWorker",
"Farm",
"Fleet",
"Job",
"JobAttachmentSettings",
"JobAttachmentManager",
"PipInstall",
"S3Object",
"ServiceModel",
"StubDeadlineClient",
"Queue",
"QueueFleetAssociation",
"TaskStatus",
"bootstrap_resources",
"deadline_client",
"deadline_resources",
"deploy_job_attachment_resources",
"version",
"worker",
]
9 changes: 9 additions & 0 deletions src/deadline_test_fixtures/cloudformation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

from .job_attachments_bootstrap_stack import JobAttachmentsBootstrapStack
from .worker_bootstrap_stack import WorkerBootstrapStack

__all__ = [
"JobAttachmentsBootstrapStack",
"WorkerBootstrapStack",
]
Loading