Skip to content

Commit 08df96f

Browse files
authored
Merge branch 'master' into some_option_renaming
2 parents a385d5e + deb72e6 commit 08df96f

19 files changed

+90
-129
lines changed

.travis.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ python:
66
- "3.8"
77
- "3.7"
88
- "3.6"
9-
- "3.5"
10-
- "2.7"
119

1210
matrix:
1311
allow_failures:
@@ -17,15 +15,9 @@ install:
1715
# We do this conditionally because it saves us some downloading if the
1816
# version is the same.
1917
- unset VIRTUAL_ENV
20-
# Python 3.4 and 2.7 need six installed before running setup.py
21-
- pip install six
2218
# Travis needs to update pip/setuptools
2319
- pip install --upgrade setuptools pip
2420
- pip install .
25-
- |
26-
if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
27-
pip install doit==0.29.0
28-
fi
2921
- pip install doit
3022
- doit install_test_deps
3123

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ Specify `-p no:python` if you would like to execute notebooks only. Alternativel
7272

7373
py.test --nbval my_notebook.ipynb
7474

75+
By default, each `.ipynb` file will be executed using the kernel
76+
specified in its metadata. You can override this behavior by passing
77+
either `--nbval-kernel-name mykernel` to run all the notebooks using
78+
`mykernel`, or `--current-env` to use a kernel in the same environment
79+
in which pytest itself was launched.
80+
7581
If the output lines are going to be sanitized, an extra flag, `--nbval-sanitize-with`
7682
together with the path to a confguration file with regex expressions, must be passed,
7783
i.e.
@@ -115,8 +121,8 @@ notebook are run on the same kernel.
115121
## Help
116122
The `py.test` system help can be obtained with `py.test -h`, which will
117123
show all the flags that can be passed to the command, such as the
118-
verbose `-v` option. The IPython notebook plugin can be found under the
119-
`general` section.
124+
verbose `-v` option. Nbval's options can be found under the
125+
`Jupyter Notebook validation` section.
120126

121127

122128
## Acknowledgements

appveyor.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ image: Visual Studio 2019
66
# environment variables
77
environment:
88
matrix:
9-
- PYTHON: "C:\\Python35-x64"
109
- PYTHON: "C:\\Python36-x64"
1110
- PYTHON: "C:\\Python37-x64"
1211
- PYTHON: "C:\\Python38-x64"

docs/environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: nbval_docs
22
channels:
33
- conda-forge
44
dependencies:
5-
- python=3.5
5+
- python=3.8
66
- numpy
77
- matplotlib
88
- sphinx

docs/source/index.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@
588588
"name": "python",
589589
"nbconvert_exporter": "python",
590590
"pygments_lexer": "ipython3",
591-
"version": "3.5.1"
591+
"version": "3.8.6"
592592
}
593593
},
594594
"nbformat": 4,

issues/27/latex-example.ipynb

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
{
1212
"cell_type": "code",
1313
"execution_count": 18,
14-
"metadata": {
15-
"collapsed": false
16-
},
14+
"metadata": {},
1715
"outputs": [],
1816
"source": [
1917
"import sympy\n",
@@ -33,9 +31,7 @@
3331
{
3432
"cell_type": "code",
3533
"execution_count": 19,
36-
"metadata": {
37-
"collapsed": false
38-
},
34+
"metadata": {},
3935
"outputs": [
4036
{
4137
"data": {
@@ -79,9 +75,7 @@
7975
{
8076
"cell_type": "code",
8177
"execution_count": 21,
82-
"metadata": {
83-
"collapsed": false
84-
},
78+
"metadata": {},
8579
"outputs": [
8680
{
8781
"data": {
@@ -106,9 +100,9 @@
106100
],
107101
"metadata": {
108102
"kernelspec": {
109-
"display_name": "Python [conda root]",
103+
"display_name": "Python 3",
110104
"language": "python",
111-
"name": "conda-root-py"
105+
"name": "python3"
112106
},
113107
"language_info": {
114108
"codemirror_mode": {
@@ -120,7 +114,7 @@
120114
"name": "python",
121115
"nbconvert_exporter": "python",
122116
"pygments_lexer": "ipython3",
123-
"version": "3.5.2"
117+
"version": "3.8.6"
124118
}
125119
},
126120
"nbformat": 4,

issues/7/tutorial_lib.ipynb

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
{
2929
"cell_type": "code",
3030
"execution_count": 4,
31-
"metadata": {
32-
"collapsed": false
33-
},
31+
"metadata": {},
3432
"outputs": [
3533
{
3634
"data": {
@@ -50,9 +48,7 @@
5048
{
5149
"cell_type": "code",
5250
"execution_count": 5,
53-
"metadata": {
54-
"collapsed": false
55-
},
51+
"metadata": {},
5652
"outputs": [
5753
{
5854
"data": {
@@ -72,9 +68,7 @@
7268
{
7369
"cell_type": "code",
7470
"execution_count": 6,
75-
"metadata": {
76-
"collapsed": false
77-
},
71+
"metadata": {},
7872
"outputs": [
7973
{
8074
"data": {
@@ -101,9 +95,7 @@
10195
{
10296
"cell_type": "code",
10397
"execution_count": 7,
104-
"metadata": {
105-
"collapsed": false
106-
},
98+
"metadata": {},
10799
"outputs": [
108100
{
109101
"name": "stdout",
@@ -133,9 +125,7 @@
133125
{
134126
"cell_type": "code",
135127
"execution_count": 8,
136-
"metadata": {
137-
"collapsed": false
138-
},
128+
"metadata": {},
139129
"outputs": [
140130
{
141131
"data": {
@@ -155,9 +145,7 @@
155145
{
156146
"cell_type": "code",
157147
"execution_count": 9,
158-
"metadata": {
159-
"collapsed": false
160-
},
148+
"metadata": {},
161149
"outputs": [
162150
{
163151
"data": {
@@ -177,9 +165,7 @@
177165
{
178166
"cell_type": "code",
179167
"execution_count": 10,
180-
"metadata": {
181-
"collapsed": false
182-
},
168+
"metadata": {},
183169
"outputs": [
184170
{
185171
"data": {
@@ -229,9 +215,9 @@
229215
"name": "python",
230216
"nbconvert_exporter": "python",
231217
"pygments_lexer": "ipython3",
232-
"version": "3.4.4"
218+
"version": "3.8.6"
233219
}
234220
},
235221
"nbformat": 4,
236-
"nbformat_minor": 0
222+
"nbformat_minor": 1
237223
}

nbval/plugin.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@
1616
import warnings
1717
from collections import OrderedDict, defaultdict
1818

19-
# for python 3 compatibility
20-
import six
21-
22-
try:
23-
from Queue import Empty
24-
except:
25-
from queue import Empty
19+
from queue import Empty
2620

2721
# for reading notebook files
2822
import nbformat
@@ -71,9 +65,10 @@ def pytest_addoption(parser):
7165
7266
This is called by the pytest API
7367
"""
74-
group = parser.getgroup("general")
68+
group = parser.getgroup("nbval", "Jupyter Notebook validation")
69+
7570
group.addoption('--nbval', action='store_true',
76-
help="Validate Jupyter notebooks")
71+
help="Run Jupyter notebooks, validating all output")
7772

7873
group.addoption('--nbval-lax', action='store_true',
7974
help="Run Jupyter notebooks, only validating output on "
@@ -86,8 +81,16 @@ def pytest_addoption(parser):
8681

8782
group.addoption('--nbval-current-env', action='store_true',
8883
help='Force test execution to use a python kernel in '
89-
'the same enviornment that py.test was '
90-
'launched from.')
84+
'the same environment that py.test was '
85+
'launched from. Without this flag, the kernel stored '
86+
'in the notebook is used by default. '
87+
'See also: --nbval-kernel-name')
88+
89+
group.addoption('--nbval-kernel-name', action='store', default=None,
90+
help='Force test execution to use the named kernel. '
91+
'If a kernel is not named, the kernel stored in the '
92+
'notebook is used by default. '
93+
'See also: --current-env')
9194

9295
group.addoption('--nbval-cell-timeout', action='store', default=2000,
9396
type=float,
@@ -124,6 +127,11 @@ def pytest_configure(config):
124127
if config.option.nbval_current_env:
125128
raise ValueError("--current-env and --nbval-current-env were both supplied.")
126129
config.option.nbval_current_env = config.option.current_env
130+
if config.option.nbval or config.option.nbval_lax:
131+
if config.option.nbval_kernel_name and config.option.current_env:
132+
raise ValueError("--current-env and --nbval-kernel-name are mutually exclusive.")
133+
134+
127135

128136

129137
def pytest_collect_file(path, parent):
@@ -248,9 +256,12 @@ def setup(self):
248256
Called by pytest to setup the collector cells in .
249257
Here we start a kernel and setup the sanitize patterns.
250258
"""
251-
259+
# we've already checked that --nbval-current-env and
260+
# --nbval-kernel-name were not both supplied
252261
if self.parent.config.option.nbval_current_env:
253262
kernel_name = CURRENT_ENV_KERNEL_NAME
263+
elif self.parent.config.option.nbval_kernel_name:
264+
kernel_name = self.parent.config.option.nbval_kernel_name
254265
else:
255266
kernel_name = self.nb.metadata.get(
256267
'kernelspec', {}).get('name', 'python')
@@ -519,9 +530,9 @@ def compare_outputs(self, test, ref, skip_compare=None):
519530

520531
def format_output_compare(self, key, left, right):
521532
"""Format an output for printing"""
522-
if isinstance(left, six.string_types):
533+
if isinstance(left, str):
523534
left = _trim_base64(left)
524-
if isinstance(right, six.string_types):
535+
if isinstance(right, str):
525536
right = _trim_base64(right)
526537

527538
cc = self.colors
@@ -815,7 +826,7 @@ def sanitize_outputs(self, outputs, skip_sanitize=('metadata',
815826
def sanitize(self, s):
816827
"""sanitize a string for comparison.
817828
"""
818-
if not isinstance(s, six.string_types):
829+
if not isinstance(s, str):
819830
return s
820831

821832
"""
@@ -824,7 +835,7 @@ def sanitize(self, s):
824835
is passed when py.test is called. Otherwise, the strings
825836
are not processed
826837
"""
827-
for regex, replace in six.iteritems(self.parent.sanitize_patterns):
838+
for regex, replace in self.parent.sanitize_patterns.items():
828839
s = re.sub(regex, replace, s)
829840
return s
830841

@@ -920,6 +931,6 @@ def _trim_base64(s):
920931

921932
def _indent(s, indent=' '):
922933
"""Intent each line with indent"""
923-
if isinstance(s, six.string_types):
934+
if isinstance(s, str):
924935
return '\n'.join(('%s%s' % (indent, line) for line in s.splitlines()))
925936
return s

readthedocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
type: sphinx
22
python:
3-
version: 3.5
3+
version: 3.8
44
pip_install: true
55
conda:
66
file: docs/environment.yml

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@
2222
},
2323
install_requires = [
2424
'pytest >= 2.8',
25-
'six',
2625
'jupyter_client',
2726
'nbformat',
2827
'ipykernel',
2928
'coverage',
3029
],
30+
python_requires='>=3.6, <4',
3131
classifiers = [
3232
'Framework :: IPython',
3333
'Framework :: Pytest',
3434
'License :: OSI Approved :: BSD License',
35-
'Programming Language :: Python :: 2',
3635
'Programming Language :: Python :: 3',
3736
'Topic :: Software Development :: Testing',
3837
]

0 commit comments

Comments
 (0)