Skip to content

Commit

Permalink
refresh the sanity tests
Browse files Browse the repository at this point in the history
- Use `tox` to run the sanity tests
- Upgrade the default versions
- Break the dependency on Python3.7
- Adjust some issues in the code to be compliant with the update tests
- Do not run `policy` by default because ansible-core 2.13 depends on Python3.8

The fixed errors are listed below:
```
************* Module cleanup
aws/cleanup.py:53:9: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
************* Module terminator
aws/terminator/__init__.py:273:8: R1725: Consider using Python 3 style super() without arguments (super-with-arguments)
************* Module terminator.compute
aws/terminator/compute.py:195:15: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
************* Module terminator.networking
aws/terminator/networking.py:142:8: R1725: Consider using Python 3 style super() without arguments (super-with-arguments)
aws/terminator/networking.py:164:27: R1729: Use a generator instead 'any(self.is_vpc_default(attachment_id) for attachment_id in attachments)' (use-a-generator)
aws/terminator/networking.py:272:15: R1729: Use a generator instead 'any(association['Main'] for association in self.instance.get('Associations', []))' (use-a-generator)
************* Module terminator.storage_services
aws/terminator/storage_services.py:55:30: R1735: Consider using {} instead of dict() (use-dict-literal)
```
  • Loading branch information
goneri committed Nov 17, 2022
1 parent 03c8209 commit fa75736
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 80 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ default:
.PHONY: test-all
test-all: test
make test -C aws
make test -C hacking
tox

.PHONY: test-all-requirements
test-all-requirements: test-requirements
make test-requirements -C aws FLAGS="$(FLAGS)"
make test-requirements -C hacking

.PHONY: test
test: yamllint
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# AWS Terminator

An AWS Lambda function for cleaning up AWS resources.

## Run the sanity tests

We use `tox` to run the sanity tests:

```console
$ tox
```

You can run one specific test with a `-e foo` parameter. Use `tox -av` to list them all:

```console
$ tox -e pylint
```
19 changes: 0 additions & 19 deletions aws/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,3 @@ terminator_lambda:
.PHONY: test_policy
test_policy:
$(RUN_TEST_POLICY_PLAYBOOK)

.PHONY: test
test: yamllint pycodestyle pylint

.PHONY: test-requirements
test-requirements:
"$(PYTHON3)" -m pip install -c ../constraints.txt -r requirements.txt -r test-requirements.txt --disable-pip-version-check $(FLAGS)

.PHONY: yamllint
yamllint:
"$(PYTHON3)" -m yamllint --config-file ../.yamllint .

.PHONY: pycodestyle
pycodestyle:
find . -name '*.py' | xargs "$(PYTHON3)" -m pycodestyle --config ../pycodestyle.ini

.PHONY: pylint
pylint:
find . -name '*.py' | xargs "$(PYTHON3)" -m pylint --rcfile pylint.rc
20 changes: 10 additions & 10 deletions aws/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
boto3==1.21.10
botocore==1.24.10
certifi==2021.10.8
charset-normalizer==2.0.12
docutils==0.18.1
idna==3.3
jmespath==0.10.0
boto3==1.25.5
botocore==1.28.5
certifi==2022.9.24
charset-normalizer==2.1.1
idna==3.4
jmespath==1.0.1
python-dateutil==2.8.2
requests==2.27.1
s3transfer==0.5.2
requests==2.28.1
s3transfer==0.6.0
six==1.16.0
urllib3==1.26.8
urllib3==1.26.12
PyYAML==6.0
6 changes: 4 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ steps:
inputs:
versionSpec: '3.7'
displayName: Install Python 3.7
- script: make test-all-requirements FLAGS=--user
- script: pip install --user tox
displayName: Install tox
- script: tox --notest
displayName: Install test requirements
- script: make test-all
- script: tox
displayName: Run tests
31 changes: 24 additions & 7 deletions constraints.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
# freeze pylint and its requirements for consistent test results
astroid == 2.2.5
isort == 4.3.15
lazy-object-proxy == 1.3.1
mccabe == 0.6.1
pylint == 2.3.1
typed-ast == 1.4.0 # 1.4.0 is required to compile on Python 3.8
wrapt == 1.11.1
ansible-core==2.13.5
astroid==2.12.12
cffi==1.15.1
cryptography==38.0.3
dill==0.3.6
isort==5.10.1
Jinja2==3.1.2
lazy-object-proxy==1.8.0
MarkupSafe==2.1.1
mccabe==0.7.0
packaging==21.3
pathspec==0.10.1
platformdirs==2.5.2
pycodestyle==2.9.1
pycparser==2.21
pylint==2.15.5
pyparsing==3.0.9
PyYAML==6.0
resolvelib==0.8.1
tomli==2.0.1
tomlkit==0.11.6
typing_extensions==4.4.0
wrapt==1.14.1
yamllint==1.28.0
40 changes: 0 additions & 40 deletions hacking/Makefile

This file was deleted.

36 changes: 36 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[tox]
skipsdist=True
envlist=pycodestyle,pylint,yamllint

[test-deps]
deps =
-cconstraints.txt
-raws/requirements.txt

[testenv:pylint]
description = Check with Pylint
deps =
{[test-deps]deps}
pylint
commands = pylint --rcfile {toxinidir}/hacking/pylint.rc {toxinidir}/aws

[testenv:pycodestyle]
description = Check with pycodestyle
deps =
{[test-deps]deps}
pycodestyle
commands = pycodestyle --config {toxinidir}/pycodestyle.ini {toxinidir}/aws

[testenv:yamllint]
description = Check with YAMLlint
deps =
{[test-deps]deps}
yamllint
commands = yamllint --config-file {toxinidir}/.yamllint {toxinidir}/aws {toxinidir}/hacking

[testenv:policy]
description = Run the test-policies playbook
deps =
{[test-deps]deps}
ansible-core
commands = ansible-playbook -i localhost {toxinidir}/hacking/aws_config/test-policies.yml

0 comments on commit fa75736

Please sign in to comment.