Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Commit

Permalink
Migrate test runner to py.test
Browse files Browse the repository at this point in the history
Maintainer of pytest_gae needs to merge open PR and push to PyPI.
In the mean time, get code directly from GitHub mirror.
  • Loading branch information
pferate committed Jul 27, 2016
1 parent 25165ad commit 2e5b8cb
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 67 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ docs/_build

# Test files
.tox/
.cache/

# Django test database
db.sqlite3
Expand Down
1 change: 1 addition & 0 deletions oauth2client/crypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def _bad_pkcs12_key_as_pem(*args, **kwargs):
OpenSSLSigner = None
pkcs12_key_as_pem = _bad_pkcs12_key_as_pem


try:
from oauth2client._pycrypto_crypt import PyCryptoVerifier
from oauth2client._pycrypto_crypt import PyCryptoSigner
Expand Down
22 changes: 0 additions & 22 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +0,0 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Test package set-up."""

from oauth2client import util

__author__ = '[email protected] (Ali Afshar)'


def setup_package():
"""Run on testing package."""
util.positional_parameters_enforcement = util.POSITIONAL_EXCEPTION
25 changes: 25 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Test package set-up."""

import pytest

from oauth2client import util

__author__ = '[email protected] (Ali Afshar)'


@pytest.fixture(scope="session", autouse=True)
def setup_package():
"""Run on testing package."""
util.positional_parameters_enforcement = util.POSITIONAL_EXCEPTION
12 changes: 12 additions & 0 deletions tests/test_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,13 @@ def setUp(self):
class SignedJwtAssertionCredentialsTests(unittest2.TestCase):

def setUp(self):
self.orig_signer = crypt.Signer
self.format_ = 'p12'
crypt.Signer = crypt.OpenSSLSigner

def tearDown(self):
crypt.Signer = self.orig_signer

def _make_credentials(self):
private_key = datafile('privatekey.' + self.format_)
signer = crypt.Signer.from_string(private_key)
Expand Down Expand Up @@ -313,17 +317,25 @@ class PEMSignedJwtAssertionCredentialsOpenSSLTests(
SignedJwtAssertionCredentialsTests):

def setUp(self):
self.orig_signer = crypt.Signer
self.format_ = 'pem'
crypt.Signer = crypt.OpenSSLSigner

def tearDown(self):
crypt.Signer = self.orig_signer


class PEMSignedJwtAssertionCredentialsPyCryptoTests(
SignedJwtAssertionCredentialsTests):

def setUp(self):
self.orig_signer = crypt.Signer
self.format_ = 'pem'
crypt.Signer = crypt.PyCryptoSigner

def tearDown(self):
crypt.Signer = self.orig_signer


class TestHasOpenSSLFlag(unittest2.TestCase):

Expand Down
6 changes: 6 additions & 0 deletions tests/test_service_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def datafile(filename):
class ServiceAccountCredentialsTests(unittest2.TestCase):

def setUp(self):
self.orig_signer = crypt.Signer
self.orig_verifier = crypt.Verifier
self.client_id = '123'
self.service_account_email = '[email protected]'
self.private_key_id = 'ABCDEF'
Expand All @@ -60,6 +62,10 @@ def setUp(self):
client_id=self.client_id,
)

def tearDown(self):
crypt.Signer = self.orig_signer
crypt.Verifier = self.orig_verifier

def test__to_json_override(self):
signer = object()
creds = ServiceAccountCredentials('[email protected]',
Expand Down
86 changes: 41 additions & 45 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ basedeps = mock>=1.3.0
cryptography>=1.0
pyopenssl>=0.14
webtest
nose
pytest
flask
unittest2
sqlalchemy
Expand All @@ -18,74 +18,70 @@ deps = {[testenv]basedeps}
setenv =
pypy: with_gmp=no
DJANGO_SETTINGS_MODULE=tests.contrib.django_util.settings
commands = nosetests --ignore-files=test_appengine\.py --ignore-files=test__appengine_ndb\.py {posargs}
commands =
py.test \
--ignore=tests/contrib/test_appengine.py \
--ignore=tests/contrib/test__appengine_ndb.py \
{posargs}

[coverbase]
basepython = python2.7
commands =
nosetests \
--with-coverage \
--cover-package=oauth2client \
--cover-package=tests \
--cover-erase \
--cover-tests \
--cover-branches \
--ignore-files=test_appengine\.py \
--ignore-files=test__appengine_ndb\.py
nosetests \
--with-coverage \
--cover-package=oauth2client.contrib.appengine \
--cover-package=oauth2client.contrib._appengine_ndb \
--cover-package=tests.contrib.test_appengine \
--cover-package=tests.contrib.test__appengine_ndb \
py.test \
--cov=oauth2client \
--cov=tests \
--ignore=tests/contrib/test_appengine.py \
--ignore=tests/contrib/test__appengine_ndb.py
py.test \
--cov=oauth2client.contrib.appengine \
--cov=oauth2client.contrib._appengine_ndb \
--cov=tests.contrib.test__appengine_ndb \
--cov=tests.contrib.test_appengine \
--cov-append \
--with-gae \
--cover-tests \
--cover-branches \
--gae-application=tests/data \
--gae-lib-root={env:GAE_PYTHONPATH:google_appengine} \
--logging-level=INFO \
--gae-path={env:GAE_PYTHONPATH:google_appengine} \
--gae-project-path=tests/data \
tests/contrib/test_appengine.py \
tests/contrib/test__appengine_ndb.py
deps = {[testenv]deps}
coverage
nosegae
pytest-cov
# pytest_gae # TODO: Move to official source when it is updated
-egit+https://github.com/MiCHiLU/pytest_gae#egg=tablib

[testenv:py26]
basepython =
python2.6
commands =
nosetests \
--ignore-files=test_appengine\.py \
--ignore-files=test__appengine_ndb\.py \
--ignore-files=test_keyring_storage\.py \
--exclude-dir=oauth2client/contrib/django_util \
--exclude-dir=tests/contrib/django_util \
py.test \
--ignore=tests/contrib/test_appengine.py \
--ignore=tests/contrib/test__appengine_ndb.py \
--ignore=tests/contrib/test_keyring_storage.py \
--ignore=oauth2client/contrib/django_util \
--ignore=tests/contrib/django_util \
{posargs}
deps = {[testenv]basedeps}
nose-exclude

[testenv:py33]
basepython =
python3.3
commands =
nosetests \
--ignore-files=test_appengine\.py \
--ignore-files=test__appengine_ndb\.py \
--ignore-files=test_django_orm\.py \
--ignore-files=test_django_settings\.py \
--ignore-files=test_django_util\.py \
--exclude-dir=oauth2client/contrib/django_util \
--exclude-dir=tests/contrib/django_util \
py.test \
--ignore=tests/contrib/test_appengine.py \
--ignore=tests/contrib/test__appengine_ndb.py \
--ignore=tests/contrib/test_django_orm.py \
--ignore=tests/contrib/test_django_settings.py \
--ignore=oauth2client/contrib/django_util \
--ignore=tests/contrib/django_util \
{posargs}
deps = {[testenv]basedeps}
keyring
nose-exclude

[testenv:cover]
basepython = {[coverbase]basepython}
commands =
{[coverbase]commands}
coverage report --show-missing --cover-min-percentage=100
coverage report --show-missing --fail-under=100
deps =
{[coverbase]deps}

Expand Down Expand Up @@ -114,13 +110,13 @@ commands = {toxinidir}/scripts/build_docs.sh
[testenv:gae]
basepython = python2.7
deps = {[testenv]basedeps}
nosegae
# pytest_gae # TODO: Move to official source when it is updated
-egit+https://github.com/MiCHiLU/pytest_gae#egg=tablib
commands =
nosetests \
py.test \
--with-gae \
--gae-lib-root={env:GAE_PYTHONPATH:google_appengine} \
--gae-application=tests/data \
--logging-level=INFO \
--gae-path={env:GAE_PYTHONPATH:google_appengine} \
--gae-project-path=tests/data \
tests/contrib/test_appengine.py \
tests/contrib/test__appengine_ndb.py

Expand Down

0 comments on commit 2e5b8cb

Please sign in to comment.