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

Provide means to run local unit tests consistently #262

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
55 changes: 28 additions & 27 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package
name: Build and test

on:
push:
Expand All @@ -10,38 +10,39 @@ on:
branches: [ master ]

jobs:
build:
pre-build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v3
with:
python-version: "3.x"
- name: Install tox
run: pip install tox
- name: Run flake8
run: tox -e lint
- name: Run coverage
run: tox -e coverage
- name: Export to Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./coverage.lcov

build:
needs: pre-build
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
python-version: ["2.7", "3.6", "3.7", "3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
- uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
pip install -r requirements.txt
- name: Lint with flake8
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 --ignore E501,E722
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
run: |
pip install coverage
pip install coveralls
pip install pytest
coverage run --source=aws_google_auth/ --omit=aws_google_auth/tests/* setup.py test
coverage report
coveralls
- name: Install tox
run: pip install tox
- name: Run package tests
run: tox -e py
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ Pull requests are definitely welcome. In order to be most useful, please try and
* the code is clean and understandable
* the pull request would merge cleanly

### Unit Tests

If you're adding new functionality to the code base, please make sure you add a
corresponding unit test in the tests/ directory.

The project's unit tests can be run using [tox](https://tox.wiki/en/latest/).
A container to use for testing can be built using the following steps:

1. Spin up a container using ubuntu:latest: `docker run -it ubuntu:latest`
2. Add a few of prerequisite packages: `apt -y update && apt -y install git python3 tox`
3. Clone the repository: `git clone https://github.com/cevoaustralia/aws-google-auth.git`
4. Navigate to the directory and run tox: `cd aws-google-auth && tox`

Running tox without any arguments will run flake8 and the full test suite!

## Issues

Issues are also very welcome! Please try and make sure that:
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,5 @@
],
},

test_suite='nose.collector',
tests_require=['nose', 'mock'],
tests_require=['mock'],
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import unittest

import mock
from nose.tools import nottest

from aws_google_auth import resolve_config, parse_args

Expand Down Expand Up @@ -130,7 +129,7 @@ def test_with_environment(self):

class TestRegionProcessing(unittest.TestCase):

@nottest
@unittest.skip("Skip until parameters that are coalesced can be tested")
def test_default(self):
args = parse_args([])
config = resolve_config(args)
Expand Down Expand Up @@ -183,7 +182,7 @@ def test_cli_param_supplied(self):
config = resolve_config(args)
self.assertTrue(config.ask_role)

@nottest
@unittest.skip("Skip until parameters that are coalesced can be tested")
@mock.patch.dict(os.environ, {'AWS_ASK_ROLE': 'true'})
def test_with_environment(self):
args = parse_args([])
Expand All @@ -203,7 +202,7 @@ def test_cli_param_supplied(self):
config = resolve_config(args)
self.assertTrue(config.u2f_disabled)

@nottest
@unittest.skip("Skip until parameters that are coalesced can be tested")
@mock.patch.dict(os.environ, {'U2F_DISABLED': 'true'})
def test_with_environment(self):
args = parse_args([])
Expand All @@ -223,7 +222,7 @@ def test_cli_param_supplied(self):
config = resolve_config(args)
self.assertTrue(config.resolve_aliases)

@nottest
@unittest.skip("Skip until parameters that are coalesced can be tested")
@mock.patch.dict(os.environ, {'RESOLVE_AWS_ALIASES': 'true'})
def test_with_environment(self):
args = parse_args([])
Expand All @@ -243,7 +242,7 @@ def test_cli_param_supplied(self):
config = resolve_config(args)
self.assertEqual(config.bg_response, 'foo')

@nottest
@unittest.skip("Skip until parameters that are coalesced can be tested")
@mock.patch.dict(os.environ, {'GOOGLE_BG_RESPONSE': 'foo'})
def test_with_environment(self):
args = parse_args([])
Expand All @@ -253,7 +252,7 @@ def test_with_environment(self):

class TestAccountProcessing(unittest.TestCase):

@nottest
@unittest.skip("Skip until parameters that are coalesced can be tested")
def test_default(self):
args = parse_args([])
config = resolve_config(args)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[tox]
envlist = lint, coverage

[testenv]
commands = pytest tests/ {posargs}
deps =
pytest
mock
-rrequirements.txt

[testenv:lint]
commands = flake8 --ignore E501,E722 .
deps = flake8

[testenv:coverage]
commands =
pytest --cov-report=term-missing --cov=aws_google_auth tests/
coverage lcov
deps =
{[testenv]deps}
pytest-cov