Skip to content

Commit a2af434

Browse files
authored
Merge pull request nltk#3054 from tomaarsen/tests/doctests
Resolve the last failing doctests, add doctests to CI
2 parents 720ba44 + 1bfd34e commit a2af434

File tree

13 files changed

+228
-179
lines changed

13 files changed

+228
-179
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
id: restore-cache
6464
with:
6565
path: ~/third
66-
key: third_${{ secrets.CACHE_VERSION }}
66+
key: third_${{ hashFiles('tools/github_actions/third-party.sh') }}_${{ secrets.CACHE_VERSION }}
6767

6868
- name: Download third party data
6969
run: |
@@ -119,10 +119,10 @@ jobs:
119119
uses: actions/cache@v3
120120
with:
121121
path: ~/third
122-
key: third_${{ secrets.CACHE_VERSION }}
122+
key: third_${{ hashFiles('tools/github_actions/third-party.sh') }}_${{ secrets.CACHE_VERSION }}
123123
if: runner.os == 'Linux'
124124

125125
- name: Run pytest
126126
shell: bash
127127
run: |
128-
pytest --numprocesses auto -rsx --doctest-modules nltk/test
128+
pytest --numprocesses auto -rsx --doctest-modules nltk

nltk/classify/senna.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
Note: Unit tests for this module can be found in test/unit/test_senna.py
3131
3232
>>> from nltk.classify import Senna
33-
>>> pipeline = Senna('/usr/share/senna-v3.0', ['pos', 'chk', 'ner'])
33+
>>> pipeline = Senna('/usr/share/senna-v3.0', ['pos', 'chk', 'ner']) # doctest: +SKIP
3434
>>> sent = 'Dusseldorf is an international business center'.split()
35-
>>> [(token['word'], token['chk'], token['ner'], token['pos']) for token in pipeline.tag(sent)] # doctest: +SKIP
35+
>>> [(token['word'], token['chk'], token['ner'], token['pos']) for token in pipeline.tag(sent)] # doctest: +SKIP
3636
[('Dusseldorf', 'B-NP', 'B-LOC', 'NNP'), ('is', 'B-VP', 'O', 'VBZ'), ('an', 'B-NP', 'O', 'DT'),
3737
('international', 'I-NP', 'O', 'JJ'), ('business', 'I-NP', 'O', 'NN'), ('center', 'I-NP', 'O', 'NN')]
3838
"""
@@ -62,7 +62,7 @@ def __init__(self, senna_path, operations, encoding="utf-8"):
6262
self._path = path.normpath(environ["SENNA"]) + sep
6363
exe_file_2 = self.executable(self._path)
6464
if not path.isfile(exe_file_2):
65-
raise OSError(
65+
raise LookupError(
6666
"Senna executable expected at %s or %s but not found"
6767
% (exe_file_1, exe_file_2)
6868
)
@@ -115,7 +115,7 @@ def tag_sents(self, sentences):
115115
encoding = self._encoding
116116

117117
if not path.isfile(self.executable(self._path)):
118-
raise OSError(
118+
raise LookupError(
119119
"Senna executable expected at %s but not found"
120120
% self.executable(self._path)
121121
)

nltk/corpus/reader/markdown.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from collections import namedtuple
22
from functools import partial, wraps
33

4-
from yaml import safe_load
5-
64
from nltk.corpus.reader.api import CategorizedCorpusReader
75
from nltk.corpus.reader.plaintext import PlaintextCorpusReader
86
from nltk.corpus.reader.util import concat, read_blankline_block
@@ -206,6 +204,8 @@ def concatenated_view(self, reader, fileids, categories):
206204
)
207205

208206
def metadata_reader(self, stream):
207+
from yaml import safe_load
208+
209209
return [
210210
safe_load(t.content)
211211
for t in self.parser.parse(stream.read())

nltk/draw/table.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,8 @@ def __init__(self, master, columns, column_weights=None, cnf={}, **kw):
7676
:param cnf, kw: Configuration parameters for this widget.
7777
Use ``label_*`` to configure all labels; and ``listbox_*``
7878
to configure all listboxes. E.g.:
79-
>>> from nltk.draw.util import TextWidget, CanvasFrame, SpaceWidget
80-
>>> from nltk.draw.table import MultiListbox
81-
>>> cf = CanvasFrame(closeenough=10, width=300, height=300)
82-
>>> c = cf.canvas()
83-
>>> master = TextWidget(c, "hiya there", draggable=1)
84-
>>> master = SpaceWidget(c, 0, 30)
85-
>>> mlb = MultiListbox(master, 5, label_foreground='red')
79+
>>> root = Tk() # doctest: +SKIP
80+
>>> MultiListbox(root, ["Subject", "Sender", "Date"], label_foreground='red').pack() # doctest: +SKIP
8681
"""
8782
# If columns was specified as an int, convert it to a list.
8883
if isinstance(columns, int):
@@ -139,7 +134,7 @@ def __init__(self, master, columns, column_weights=None, cnf={}, **kw):
139134
# the default listbox behavior, which scrolls):
140135
lb.bind("<B1-Leave>", lambda e: "break")
141136
# Columns can be resized by dragging them:
142-
l.bind("<Button-1>", self._resize_column)
137+
lb.bind("<Button-1>", self._resize_column)
143138

144139
# Columns can be resized by dragging them. (This binding is
145140
# used if they click on the grid between columns:)
@@ -305,9 +300,10 @@ def configure(self, cnf={}, **kw):
305300
Configure this widget. Use ``label_*`` to configure all
306301
labels; and ``listbox_*`` to configure all listboxes. E.g.:
307302
308-
>>> mlb = MultiListbox(master, 5)
309-
>>> mlb.configure(label_foreground='red')
310-
>>> mlb.configure(listbox_foreground='red')
303+
>>> master = Tk() # doctest: +SKIP
304+
>>> mlb = MultiListbox(master, 5) # doctest: +SKIP
305+
>>> mlb.configure(label_foreground='red') # doctest: +SKIP
306+
>>> mlb.configure(listbox_foreground='red') # doctest: +SKIP
311307
"""
312308
cnf = dict(list(cnf.items()) + list(kw.items()))
313309
for (key, val) in list(cnf.items()):
@@ -592,13 +588,13 @@ class Table:
592588
refers to the j-th column of the i-th row. This can be used to
593589
both read and write values from the table. E.g.:
594590
595-
>>> table[i,j] = 'hello'
591+
>>> table[i,j] = 'hello' # doctest: +SKIP
596592
597593
The column (j) can be given either as an index number, or as a
598594
column name. E.g., the following prints the value in the 3rd row
599595
for the 'First Name' column:
600596
601-
>>> print(table[3, 'First Name'])
597+
>>> print(table[3, 'First Name']) # doctest: +SKIP
602598
John
603599
604600
You can configure the colors for individual rows, columns, or

nltk/draw/util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,17 @@ class CanvasWidget(metaclass=ABCMeta):
8080
arguments of the form ``attribute=value``:
8181
8282
>>> from nltk.draw.util import TextWidget
83-
>>> cn = TextWidget(Canvas(), 'test', color='red')
83+
>>> cn = TextWidget(Canvas(), 'test', color='red') # doctest: +SKIP
8484
8585
Attribute values can also be changed after a canvas widget has
8686
been constructed, using the ``__setitem__`` operator:
8787
88-
>>> cn['font'] = 'times'
88+
>>> cn['font'] = 'times' # doctest: +SKIP
8989
9090
The current value of an attribute value can be queried using the
9191
``__getitem__`` operator:
9292
93-
>>> cn['color']
93+
>>> cn['color'] # doctest: +SKIP
9494
'red'
9595
9696
For a list of the attributes supported by a type of canvas widget,

0 commit comments

Comments
 (0)