Skip to content

Commit d586990

Browse files
authored
Merge pull request #2241 from dhermes/use-pytest
Switching from nosetests to py.test.
2 parents f1ffbfd + 0a7bd23 commit d586990

9 files changed

Lines changed: 187 additions & 105 deletions

File tree

.coveragerc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
[run]
2+
branch = True
3+
4+
[report]
5+
fail_under = 100
6+
show_missing = True
7+
18
[report]
29
omit =
310
*/_generated/*.py

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pip-log.txt
2626
# Unit test / coverage reports
2727
.coverage
2828
.tox
29-
nosetests.xml
29+
.cache
3030

3131
# Translations
3232
*.mo

CONTRIBUTING.rst

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Running Tests
118118
--------------
119119

120120
- To run all tests for ``gcloud-python`` on a single Python version, run
121-
``nosetests`` from your development virtualenv (See
121+
``py.test`` from your development virtualenv (See
122122
*Using a Development Checkout* above).
123123

124124
- To run the full set of ``gcloud-python`` tests on all platforms, install
@@ -272,11 +272,7 @@ Test Coverage
272272
-------------
273273

274274
- The codebase *must* have 100% test statement coverage after each commit.
275-
You can test coverage via ``tox -e coverage``, or alternately by installing
276-
``nose`` and ``coverage`` into your virtualenv, and running
277-
``setup.py nosetests --with-coverage``. If you have ``tox`` installed::
278-
279-
$ tox -e cover
275+
You can test coverage via ``tox -e cover``.
280276

281277
Documentation Coverage and Building HTML Documentation
282278
------------------------------------------------------

appveyor.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,38 @@ environment:
1919
- PYTHON: "C:\\Python27"
2020
PYTHON_VERSION: "2.7.11"
2121
PYTHON_ARCH: "32"
22+
TOX_ENV: "py27"
2223

2324
- PYTHON: "C:\\Python27-x64"
2425
PYTHON_VERSION: "2.7.11"
2526
PYTHON_ARCH: "64"
27+
TOX_ENV: "py27"
2628

2729
# Python 3.4.4 is the latest Python 3.4 with a Windows installer
2830
# Python 3.4.4 is the overall latest
2931
# https://www.python.org/ftp/python/3.4.4/
3032
- PYTHON: "C:\\Python34"
3133
PYTHON_VERSION: "3.4.4"
3234
PYTHON_ARCH: "32"
35+
TOX_ENV: "py34"
3336

3437
- PYTHON: "C:\\Python34-x64"
3538
PYTHON_VERSION: "3.4.4"
3639
PYTHON_ARCH: "64"
40+
TOX_ENV: "py34"
3741

3842
# Python 3.5.1 is the latest Python 3.5 with a Windows installer
3943
# Python 3.5.1 is the overall latest
4044
# https://www.python.org/ftp/python/3.5.1/
4145
- PYTHON: "C:\\Python35"
4246
PYTHON_VERSION: "3.5.1"
4347
PYTHON_ARCH: "32"
48+
TOX_ENV: "py35"
4449

4550
- PYTHON: "C:\\Python35-x64"
4651
PYTHON_VERSION: "3.5.1"
4752
PYTHON_ARCH: "64"
53+
TOX_ENV: "py35"
4854

4955
install:
5056
- ECHO "Filesystem root:"
@@ -83,7 +89,7 @@ build_script:
8389
test_script:
8490
- "%CMD_IN_ENV% pip list"
8591
# Run the project tests
86-
- "%CMD_IN_ENV% python setup.py nosetests"
92+
- "%CMD_IN_ENV% tox -e %TOX_ENV%"
8793

8894
after_test:
8995
# If tests are successful, create binary packages for the project.

appveyor/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# pip will build them from source using the MSVC compiler matching the
44
# target Python version and architecture
55
wheel
6-
nose
7-
nose-exclude
6+
pytest
7+
tox
88
cryptography
99
grpcio >= 1.0rc1
1010
grpc-google-pubsub-v1

gcloud/_helpers.py

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,16 @@
5757
(?P<nanos>\d{1,9}) # nanoseconds, maybe truncated
5858
Z # Zulu
5959
""", re.VERBOSE)
60-
DEFAULT_CONFIGURATION_PATH = '~/.config/gcloud/configurations/config_default'
60+
# NOTE: Catching this ImportError is a workaround for GAE not supporting the
61+
# "pwd" module which is imported lazily when "expanduser" is called.
62+
try:
63+
_USER_ROOT = os.path.expanduser('~')
64+
except ImportError: # pragma: NO COVER
65+
_USER_ROOT = None
66+
_GCLOUD_CONFIG_FILE = os.path.join(
67+
'gcloud', 'configurations', 'config_default')
68+
_GCLOUD_CONFIG_SECTION = 'core'
69+
_GCLOUD_CONFIG_KEY = 'project'
6170

6271

6372
class _LocalStack(Local):
@@ -171,10 +180,10 @@ def _app_engine_id():
171180

172181

173182
def _file_project_id():
174-
"""Gets the project id from the credentials file if one is available.
183+
"""Gets the project ID from the credentials file if one is available.
175184
176185
:rtype: str or ``NoneType``
177-
:returns: Project-ID from JSON credentials file if value exists,
186+
:returns: Project ID from JSON credentials file if value exists,
178187
else ``None``.
179188
"""
180189
credentials_file_path = os.getenv(CREDENTIALS)
@@ -185,9 +194,37 @@ def _file_project_id():
185194
return credentials.get('project_id')
186195

187196

197+
def _get_nix_config_path():
198+
"""Get the ``gcloud`` CLI config path on *nix systems.
199+
200+
:rtype: str
201+
:returns: The filename on a *nix system containing the CLI
202+
config file.
203+
"""
204+
return os.path.join(_USER_ROOT, '.config', _GCLOUD_CONFIG_FILE)
205+
206+
207+
def _get_windows_config_path():
208+
"""Get the ``gcloud`` CLI config path on Windows systems.
209+
210+
:rtype: str
211+
:returns: The filename on a Windows system containing the CLI
212+
config file.
213+
"""
214+
appdata_dir = os.getenv('APPDATA', '')
215+
return os.path.join(appdata_dir, _GCLOUD_CONFIG_FILE)
216+
217+
188218
def _default_service_project_id():
189219
"""Retrieves the project ID from the gcloud command line tool.
190220
221+
This assumes the ``.config`` directory is stored
222+
- in ~/.config on *nix systems
223+
- in the %APPDATA% directory on Windows systems
224+
225+
Additionally, the ${HOME} / "~" directory may not be present on Google
226+
App Engine, so this may be conditionally ignored.
227+
191228
Files that cannot be opened with configparser are silently ignored; this is
192229
designed so that you can specify a list of potential configuration file
193230
locations.
@@ -196,21 +233,17 @@ def _default_service_project_id():
196233
:returns: Project-ID from default configuration file else ``None``
197234
"""
198235
search_paths = []
199-
# Workaround for GAE not supporting pwd which is used by expanduser.
200-
try:
201-
search_paths.append(os.path.expanduser(DEFAULT_CONFIGURATION_PATH))
202-
except ImportError:
203-
pass
236+
if _USER_ROOT is not None:
237+
search_paths.append(_get_nix_config_path())
238+
239+
if os.name == 'nt':
240+
search_paths.append(_get_windows_config_path())
204241

205-
windows_config_path = os.path.join(os.getenv('APPDATA', ''),
206-
'gcloud', 'configurations',
207-
'config_default')
208-
search_paths.append(windows_config_path)
209242
config = configparser.RawConfigParser()
210243
config.read(search_paths)
211244

212-
if config.has_section('core'):
213-
return config.get('core', 'project')
245+
if config.has_section(_GCLOUD_CONFIG_SECTION):
246+
return config.get(_GCLOUD_CONFIG_SECTION, _GCLOUD_CONFIG_KEY)
214247

215248

216249
def _compute_engine_id():

setup.cfg

Lines changed: 0 additions & 2 deletions
This file was deleted.

tox.ini

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@ envlist =
44

55
[testing]
66
deps =
7-
nose
8-
nose-exclude
7+
pytest
98
covercmd =
10-
nosetests \
11-
--exclude-dir=system_tests \
12-
--with-coverage \
13-
--cover-package=gcloud \
14-
--cover-package=unit_tests \
15-
--cover-erase \
16-
--cover-tests \
17-
--cover-branches \
18-
--nocapture
9+
py.test \
10+
--cov=gcloud \
11+
--cov=unit_tests \
12+
--cov-config {toxinidir}/.coveragerc \
13+
unit_tests
1914

2015
[grpc]
2116
deps =
@@ -28,7 +23,7 @@ deps =
2823

2924
[testenv]
3025
commands =
31-
nosetests
26+
py.test {posargs} unit_tests
3227
deps =
3328
{[testing]deps}
3429
{[grpc]deps}
@@ -44,16 +39,18 @@ deps =
4439
basepython =
4540
python2.7
4641
commands =
47-
{[testing]covercmd} --cover-min-percentage=100
42+
{[testing]covercmd}
4843
deps =
4944
{[testenv]deps}
5045
coverage
46+
pytest-cov
5147

5248
[testenv:coveralls]
5349
basepython = {[testenv:cover]basepython}
5450
commands =
5551
{[testing]covercmd}
5652
coveralls
53+
ignore_errors = True
5754
deps =
5855
{[testenv:cover]deps}
5956
coveralls

0 commit comments

Comments
 (0)