Skip to content

Commit 8a4cf5d

Browse files
Madnexjingbelstomaarsen
authored
Docstring tests (nltk#3050)
* fixed pytests * fixed more pytests * fixed more pytest and changed multiline pytest issues fixes for snowball.py and causal.py * fixed pytests (mainly multiline or rounding issues) * fixed treebank pytests, removed test for return_string=True (deprecated) * fixed destructive.py pytests, removed test for return_string=True (deprecated) * fixed pytest (rounding issues) * fixed pytest (initialised missing object) * fixed pytest (formatting issues) * fixed pytest (formatting issues) * fixed pytest (formatting issues) * added pytest +SKIP for deprecated module stanford * updated AUTHORS.md * changed docstring corrections by usage of ELLIPSIS and different roundings * fixed AUTHORS.md to be consistent * Fix framenet doctest formatting with pprint * Change docstring on MultiListBox.__init__ I believe the original typo was misinterpreted and changed to something that was not originally intended. Co-authored-by: Jan Lennartz <[email protected]> Co-authored-by: Tom Aarsen <[email protected]> Co-authored-by: Tom Aarsen <[email protected]>
1 parent 9851f74 commit 8a4cf5d

39 files changed

+156
-129
lines changed

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@
294294
- Heungson Lee <https://github.com/heungson>
295295
- M.K. Pawelkiewicz <https://github.com/hamiltonianflow>
296296
- Steven Thomas Smith <https://github.com/essandess>
297+
- Jan Lennartz <https://github.com/Madnex>
297298

298299
## Others whose work we've taken and included in NLTK, but who didn't directly contribute it:
299300

nltk/corpus/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
``nltk.corpus.brown.words()``:
5555
5656
>>> from nltk.corpus import brown
57-
>>> print(", ".join(brown.words()))
57+
>>> print(", ".join(brown.words())) # doctest: +ELLIPSIS
5858
The, Fulton, County, Grand, Jury, said, ...
5959
6060
"""

nltk/corpus/reader/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
``nltk.corpus.brown.words()``:
4949
5050
>>> from nltk.corpus import brown
51-
>>> print(", ".join(brown.words()))
52-
The, Fulton, County, Grand, Jury, said, ...
51+
>>> print(", ".join(brown.words()[:6])) # only first 6 words
52+
The, Fulton, County, Grand, Jury, said
5353
5454
isort:skip_file
5555
"""

nltk/corpus/reader/categorized_sents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class CategorizedSentencesCorpusReader(CategorizedCorpusReader, CorpusReader):
5151
Examples using the Subjectivity Dataset:
5252
5353
>>> from nltk.corpus import subjectivity
54-
>>> subjectivity.sents()[23]
54+
>>> subjectivity.sents()[23] # doctest: +NORMALIZE_WHITESPACE
5555
['television', 'made', 'him', 'famous', ',', 'but', 'his', 'biggest', 'hits',
5656
'happened', 'off', 'screen', '.']
5757
>>> subjectivity.categories()
@@ -62,7 +62,7 @@ class CategorizedSentencesCorpusReader(CategorizedCorpusReader, CorpusReader):
6262
Examples using the Sentence Polarity Dataset:
6363
6464
>>> from nltk.corpus import sentence_polarity
65-
>>> sentence_polarity.sents()
65+
>>> sentence_polarity.sents() # doctest: +NORMALIZE_WHITESPACE
6666
[['simplistic', ',', 'silly', 'and', 'tedious', '.'], ["it's", 'so', 'laddish',
6767
'and', 'juvenile', ',', 'only', 'teenage', 'boys', 'could', 'possibly', 'find',
6868
'it', 'funny', '.'], ...]

nltk/corpus/reader/comparative_sents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class ComparativeSentencesCorpusReader(CorpusReader):
9999
100100
>>> from nltk.corpus import comparative_sentences
101101
>>> comparison = comparative_sentences.comparisons()[0]
102-
>>> comparison.text
102+
>>> comparison.text # doctest: +NORMALIZE_WHITESPACE
103103
['its', 'fast-forward', 'and', 'rewind', 'work', 'much', 'more', 'smoothly',
104104
'and', 'consistently', 'than', 'those', 'of', 'other', 'models', 'i', "'ve",
105105
'had', '.']

nltk/corpus/reader/framenet.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,8 +1400,10 @@ def frame_by_id(self, fn_fid, ignorekeys=[]):
14001400
256
14011401
>>> f.name
14021402
'Medical_specialties'
1403-
>>> f.definition
1404-
"This frame includes words that name ..."
1403+
>>> f.definition # doctest: +NORMALIZE_WHITESPACE
1404+
"This frame includes words that name medical specialties and is closely related to the
1405+
Medical_professionals frame. The FE Type characterizing a sub-are in a Specialty may also be
1406+
expressed. 'Ralph practices paediatric oncology.'"
14051407
14061408
:param fn_fid: The Framenet id number of the frame
14071409
:type fn_fid: int
@@ -1441,8 +1443,10 @@ def frame_by_name(self, fn_fname, ignorekeys=[], check_cache=True):
14411443
256
14421444
>>> f.name
14431445
'Medical_specialties'
1444-
>>> f.definition
1445-
"This frame includes words that name ..."
1446+
>>> f.definition # doctest: +NORMALIZE_WHITESPACE
1447+
"This frame includes words that name medical specialties and is closely related to the
1448+
Medical_professionals frame. The FE Type characterizing a sub-are in a Specialty may also be
1449+
expressed. 'Ralph practices paediatric oncology.'"
14461450
14471451
:param fn_fname: The name of the frame
14481452
:type fn_fname: str
@@ -1510,9 +1514,10 @@ def frame(self, fn_fid_or_fname, ignorekeys=[]):
15101514
>>> f.ID
15111515
256
15121516
>>> # ensure non-ASCII character in definition doesn't trigger an encoding error:
1513-
>>> fn.frame('Imposing_obligation')
1517+
>>> fn.frame('Imposing_obligation') # doctest: +ELLIPSIS
15141518
frame (1494): Imposing_obligation...
15151519
1520+
15161521
The dict that is returned from this function will contain the
15171522
following information about the Frame:
15181523
@@ -1649,10 +1654,10 @@ def lu(self, fn_luid, ignorekeys=[], luName=None, frameID=None, frameName=None):
16491654
'COD: be aware of beforehand; predict.'
16501655
>>> fn.lu(256).frame.name
16511656
'Expectation'
1652-
>>> pprint(list(map(PrettyDict, fn.lu(256).lexemes)))
1657+
>>> list(map(PrettyDict, fn.lu(256).lexemes))
16531658
[{'POS': 'V', 'breakBefore': 'false', 'headword': 'false', 'name': 'foresee', 'order': 1}]
16541659
1655-
>>> fn.lu(227).exemplars[23]
1660+
>>> fn.lu(227).exemplars[23] # doctest: +NORMALIZE_WHITESPACE
16561661
exemplar sentence (352962):
16571662
[sentNo] 0
16581663
[aPos] 59699508
@@ -2070,14 +2075,14 @@ def fes(self, name=None, frame=None):
20702075
>>> from nltk.corpus import framenet as fn
20712076
>>> fn.fes('Noise_maker')
20722077
[<fe ID=6043 name=Noise_maker>]
2073-
>>> sorted([(fe.frame.name,fe.name) for fe in fn.fes('sound')])
2078+
>>> sorted([(fe.frame.name,fe.name) for fe in fn.fes('sound')]) # doctest: +NORMALIZE_WHITESPACE
20742079
[('Cause_to_make_noise', 'Sound_maker'), ('Make_noise', 'Sound'),
20752080
('Make_noise', 'Sound_source'), ('Sound_movement', 'Location_of_sound_source'),
20762081
('Sound_movement', 'Sound'), ('Sound_movement', 'Sound_source'),
20772082
('Sounds', 'Component_sound'), ('Sounds', 'Location_of_sound_source'),
20782083
('Sounds', 'Sound_source'), ('Vocalizations', 'Location_of_sound_source'),
20792084
('Vocalizations', 'Sound_source')]
2080-
>>> sorted([(fe.frame.name,fe.name) for fe in fn.fes('sound',r'(?i)make_noise')])
2085+
>>> sorted([(fe.frame.name,fe.name) for fe in fn.fes('sound',r'(?i)make_noise')]) # doctest: +NORMALIZE_WHITESPACE
20812086
[('Cause_to_make_noise', 'Sound_maker'),
20822087
('Make_noise', 'Sound'),
20832088
('Make_noise', 'Sound_source')]
@@ -2550,7 +2555,7 @@ def frame_relations(self, frame=None, frame2=None, type=None):
25502555
<Parent=Apply_heat -- Using -> Child=Cooking_creation>, ...]
25512556
>>> PrettyList(fn.frame_relations('Cooking_creation', type='Inheritance'))
25522557
[<Parent=Intentionally_create -- Inheritance -> Child=Cooking_creation>]
2553-
>>> PrettyList(fn.frame_relations('Cooking_creation', 'Apply_heat'), breakLines=True)
2558+
>>> PrettyList(fn.frame_relations('Cooking_creation', 'Apply_heat'), breakLines=True) # doctest: +NORMALIZE_WHITESPACE
25542559
[<Parent=Apply_heat -- Using -> Child=Cooking_creation>,
25552560
<MainEntry=Apply_heat -- See_also -> ReferringEntry=Cooking_creation>]
25562561
"""
@@ -2625,7 +2630,7 @@ def fe_relations(self):
26252630
True
26262631
>>> len(ferels) in (10020, 12393) # FN 1.5 and 1.7, resp.
26272632
True
2628-
>>> PrettyDict(ferels[0], breakLines=True)
2633+
>>> PrettyDict(ferels[0], breakLines=True) # doctest: +NORMALIZE_WHITESPACE
26292634
{'ID': 14642,
26302635
'_type': 'ferelation',
26312636
'frameRelation': <Parent=Abounding_with -- Inheritance -> Child=Lively_place>,

nltk/corpus/reader/opinion_lexicon.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ class OpinionLexiconCorpusReader(WordListCorpusReader):
6666
6767
Note that words from `words()` method are sorted by file id, not alphabetically:
6868
69-
>>> opinion_lexicon.words()[0:10]
69+
>>> opinion_lexicon.words()[0:10] # doctest: +NORMALIZE_WHITESPACE
7070
['2-faced', '2-faces', 'abnormal', 'abolish', 'abominable', 'abominably',
7171
'abominate', 'abomination', 'abort', 'aborted']
72-
>>> sorted(opinion_lexicon.words())[0:10]
72+
>>> sorted(opinion_lexicon.words())[0:10] # doctest: +NORMALIZE_WHITESPACE
7373
['2-faced', '2-faces', 'a+', 'abnormal', 'abolish', 'abominable', 'abominably',
7474
'abominate', 'abomination', 'abort']
7575
"""

nltk/corpus/reader/pros_cons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ProsConsCorpusReader(CategorizedCorpusReader, CorpusReader):
3636
Reader for the Pros and Cons sentence dataset.
3737
3838
>>> from nltk.corpus import pros_cons
39-
>>> pros_cons.sents(categories='Cons')
39+
>>> pros_cons.sents(categories='Cons') # doctest: +NORMALIZE_WHITESPACE
4040
[['East', 'batteries', '!', 'On', '-', 'off', 'switch', 'too', 'easy',
4141
'to', 'maneuver', '.'], ['Eats', '...', 'no', ',', 'GULPS', 'batteries'],
4242
...]

nltk/corpus/reader/reviews.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ class ReviewsCorpusReader(CorpusReader):
160160
>>> from nltk.corpus import product_reviews_1
161161
>>> camera_reviews = product_reviews_1.reviews('Canon_G3.txt')
162162
>>> review = camera_reviews[0]
163-
>>> review.sents()[0]
163+
>>> review.sents()[0] # doctest: +NORMALIZE_WHITESPACE
164164
['i', 'recently', 'purchased', 'the', 'canon', 'powershot', 'g3', 'and', 'am',
165165
'extremely', 'satisfied', 'with', 'the', 'purchase', '.']
166-
>>> review.features()
166+
>>> review.features() # doctest: +NORMALIZE_WHITESPACE
167167
[('canon powershot g3', '+3'), ('use', '+2'), ('picture', '+2'),
168168
('picture quality', '+1'), ('picture quality', '+1'), ('camera', '+2'),
169169
('use', '+2'), ('feature', '+1'), ('picture quality', '+3'), ('use', '+1'),

nltk/draw/table.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,20 @@ def __init__(self, master, columns, column_weights=None, cnf={}, **kw):
6868
6969
:param columns: Specifies what columns should be included in
7070
the new multi-column listbox. If ``columns`` is an integer,
71-
the it is the number of columns to include. If it is
71+
then it is the number of columns to include. If it is
7272
a list, then its length indicates the number of columns
7373
to include; and each element of the list will be used as
7474
a label for the corresponding column.
7575
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-
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)
8085
>>> mlb = MultiListbox(master, 5, label_foreground='red')
8186
"""
8287
# If columns was specified as an int, convert it to a list.

0 commit comments

Comments
 (0)