Skip to content
This repository was archived by the owner on Jun 11, 2019. It is now read-only.

Commit 259324e

Browse files
committed
Moving pytest run fixture into pytest namespace.
Pytest namespaces are the proper place to put variables and functions, instead of creating fixtures that just return functions. Fixing broken lints due to changed dependencies. Touching up CI files, docs conf.py file, and tox.ini file; from PythonTemplates.
1 parent 37bb6e3 commit 259324e

19 files changed

+413
-460
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Configure.
2+
env: TOX_ENV=py
23
language: python
34
matrix:
45
include:
@@ -27,7 +28,7 @@ install: pip install tox
2728
before_script:
2829
- git config --global user.email "[email protected]"
2930
- git config --global user.name "Travis CI"
30-
script: tox -e ${TOX_ENV:-py}
31+
script: tox -e $TOX_ENV
3132
after_success:
3233
- bash <(curl -s https://codecov.io/bash)
3334

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Configure.
22
environment:
3+
PATH: C:\%PYTHON%;C:\%PYTHON%\Scripts;%PATH%
34
PYTHON: Python35
45
matrix:
56
- TOX_ENV: lint
@@ -17,7 +18,6 @@ environment:
1718
PYTHON: Python27-x64
1819

1920
# Run.
20-
init: set PATH=C:\%PYTHON%;C:\%PYTHON%\Scripts;%PATH%
2121
build_script: pip install tox
2222
test_script: tox -e %TOX_ENV%
2323
on_success: IF %TOX_ENV% NEQ lint pip install codecov & codecov

docs/conf.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
"""Sphinx configuration file."""
22

33
import os
4+
import sys
45
import time
56

6-
from setup import NAME, VERSION
7-
87

98
# General configuration.
9+
sys.path.append(os.path.realpath(os.path.join(os.path.dirname(__file__), '..')))
1010
author = '@Robpol86'
1111
copyright = '{}, {}'.format(time.strftime('%Y'), author)
1212
master_doc = 'index'
13-
project = NAME
13+
project = __import__('setup').NAME
1414
pygments_style = 'friendly'
15-
release = version = VERSION
15+
release = version = __import__('setup').VERSION
1616
templates_path = ['_templates']
1717
extensions = list()
1818

@@ -31,10 +31,12 @@
3131
html_theme = 'sphinx_rtd_theme'
3232
html_title = project
3333

34+
3435
# google analytics
3536
extensions.append('sphinxcontrib.googleanalytics')
3637
googleanalytics_id = 'UA-82627369-1'
3738

39+
3840
# SCVersioning.
3941
scv_banner_greatest_tag = True
4042
scv_grm_exclude = ('.gitignore', '.nojekyll', 'README.rst')

tests/conftest.py

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,31 @@
1111
RE_URLS = re.compile('<li><a href="[^"]+">[^<]+</a></li>')
1212

1313

14+
def run(directory, command, *args, **kwargs):
15+
"""Run command using run_command() function. Supports string and py.path paths.
16+
17+
:param directory: Root git directory and current working directory.
18+
:param iter command: Command to run.
19+
:param iter args: Passed to run_command().
20+
:param dict kwargs: Passed to run_command().
21+
22+
:return: run_command() output.
23+
:rtype: str
24+
"""
25+
return run_command(str(directory), [str(i) for i in command], *args, **kwargs)
26+
27+
28+
def pytest_namespace():
29+
"""Add objects to the pytest namespace. Can be retrieved by importing pytest and accessing pytest.<name>.
30+
31+
:return: Namespace dict.
32+
:rtype: dict
33+
"""
34+
return dict(
35+
run=run,
36+
)
37+
38+
1439
@pytest.fixture
1540
def config(monkeypatch):
1641
"""Mock config from Click context.
@@ -26,19 +51,13 @@ def config(monkeypatch):
2651
return instance
2752

2853

29-
@pytest.fixture
30-
def run():
31-
"""run_command() wrapper returned from a pytest fixture."""
32-
return lambda d, c, *args, **kwargs: run_command(str(d), [str(i) for i in c], *args, **kwargs)
33-
34-
3554
@pytest.fixture
3655
def banner():
3756
"""Verify banner in HTML file match expected."""
3857
def match(path, expected_url=None, expected_base=None):
3958
"""Assert equals and return file contents.
4059
41-
:param py.path path: Path to file to read.
60+
:param py.path.local path: Path to file to read.
4261
:param str expected_url: Expected URL in <a href="" /> link.
4362
:param str expected_base: Expected base message.
4463
@@ -61,7 +80,7 @@ def urls():
6180
def match(path, expected):
6281
"""Assert equals and return file contents.
6382
64-
:param py.path path: Path to file to read.
83+
:param py.path.local path: Path to file to read.
6584
:param list expected: Expected matches.
6685
6786
:return: File contents.
@@ -75,11 +94,10 @@ def match(path, expected):
7594

7695

7796
@pytest.fixture
78-
def local_empty(tmpdir, run):
97+
def local_empty(tmpdir):
7998
"""Local git repository with no commits.
8099
81100
:param tmpdir: pytest fixture.
82-
:param run: local fixture.
83101
84102
:return: Path to repo root.
85103
:rtype: py.path
@@ -90,11 +108,10 @@ def local_empty(tmpdir, run):
90108

91109

92110
@pytest.fixture
93-
def remote(tmpdir, run):
111+
def remote(tmpdir):
94112
"""Remote git repository with nothing pushed to it.
95113
96114
:param tmpdir: pytest fixture.
97-
:param run: local fixture.
98115
99116
:return: Path to bare repo root.
100117
:rtype: py.path
@@ -105,11 +122,10 @@ def remote(tmpdir, run):
105122

106123

107124
@pytest.fixture
108-
def local_commit(local_empty, run):
125+
def local_commit(local_empty):
109126
"""Local git repository with one commit.
110127
111128
:param local_empty: local fixture.
112-
:param run: local fixture.
113129
114130
:return: Path to repo root.
115131
:rtype: py.path
@@ -121,12 +137,11 @@ def local_commit(local_empty, run):
121137

122138

123139
@pytest.fixture
124-
def local(local_commit, remote, run):
140+
def local(local_commit, remote):
125141
"""Local git repository with branches, light tags, and annotated tags pushed to remote.
126142
127143
:param local_commit: local fixture.
128144
:param remote: local fixture.
129-
:param run: local fixture.
130145
131146
:return: Path to repo root.
132147
:rtype: py.path
@@ -141,13 +156,12 @@ def local(local_commit, remote, run):
141156

142157

143158
@pytest.fixture
144-
def local_light(tmpdir, local, remote, run):
159+
def local_light(tmpdir, local, remote):
145160
"""Light-weight local repository similar to how Travis/AppVeyor clone repos.
146161
147162
:param tmpdir: pytest fixture.
148163
:param local: local fixture.
149164
:param remote: local fixture.
150-
:param run: local fixture.
151165
152166
:return: Path to repo root.
153167
:rtype: py.path
@@ -162,13 +176,12 @@ def local_light(tmpdir, local, remote, run):
162176

163177

164178
@pytest.fixture
165-
def outdate_local(tmpdir, local_light, remote, run):
179+
def outdate_local(tmpdir, local_light, remote):
166180
"""Clone remote to other directory and push changes. Causes `local` fixture to be outdated.
167181
168182
:param tmpdir: pytest fixture.
169183
:param local_light: local fixture.
170184
:param remote: local fixture.
171-
:param run: local fixture.
172185
173186
:return: Path to repo root.
174187
:rtype: py.path
@@ -190,11 +203,10 @@ def outdate_local(tmpdir, local_light, remote, run):
190203

191204

192205
@pytest.fixture
193-
def local_docs(local, run):
206+
def local_docs(local):
194207
"""Local repository with Sphinx doc files. Pushed to remote.
195208
196209
:param local: local fixture.
197-
:param run: local fixture.
198210
199211
:return: Path to repo root.
200212
:rtype: py.path
@@ -242,11 +254,10 @@ def local_docs(local, run):
242254

243255

244256
@pytest.fixture
245-
def local_docs_ghp(local_docs, run):
257+
def local_docs_ghp(local_docs):
246258
"""Add an orphaned branch to remote.
247259
248260
:param local_docs: local fixture.
249-
:param run: local fixture.
250261
"""
251262
run(local_docs, ['git', 'checkout', '--orphan', 'gh-pages'])
252263
run(local_docs, ['git', 'rm', '-rf', '.'])

tests/test__main__/test_arguments.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,13 @@ def test_args(push):
8888

8989

9090
@pytest.mark.parametrize('push', [False, True])
91-
def test_global_options(monkeypatch, tmpdir, caplog, local_empty, run, push):
91+
def test_global_options(monkeypatch, tmpdir, caplog, local_empty, push):
9292
"""Test options that apply to all sub commands.
9393
9494
:param monkeypatch: pytest fixture.
9595
:param tmpdir: pytest fixture.
9696
:param caplog: pytest extension fixture.
9797
:param local_empty: conftest fixture.
98-
:param run: conftest fixture.
9998
:param bool push: Run push sub command instead of build.
10099
"""
101100
if push:
@@ -119,7 +118,7 @@ def test_global_options(monkeypatch, tmpdir, caplog, local_empty, run, push):
119118
# Defined.
120119
empty = tmpdir.ensure_dir('empty')
121120
repo = tmpdir.ensure_dir('repo')
122-
run(repo, ['git', 'init'])
121+
pytest.run(repo, ['git', 'init'])
123122
local_empty.ensure('conf.py')
124123
args = ['-L', '-l', 'conf.py', '-c', str(empty), '-g', str(repo), '-N', '-v', '-v'] + args
125124
result = CliRunner().invoke(cli, args)

0 commit comments

Comments
 (0)