Skip to content

Commit

Permalink
Tests: Fix exception doctests for python 3.7
Browse files Browse the repository at this point in the history
Python's exception repr had the trailing comma cleaned up in
https://bugs.python.org/issue30399. This fixes the doctests to use
doctest's built-in support for expecting exceptions, which is less
brittle than checking literal repr output (and a little more readable).
  • Loading branch information
dbarnett committed Jan 20, 2020
1 parent 95c0b91 commit 379eefc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 30 deletions.
7 changes: 4 additions & 3 deletions vroom/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ def ActionLine(line, state=None):
('hijack', 'I say...', ...)
>>> ActionLine(' @clear')
('directive', 'clear', {})
>>> try: ActionLine(' @nope')
... except vroom.ParseError as e: e
ParseError('Unrecognized directive "nope"',)
>>> ActionLine(' @nope')
Traceback (most recent call last):
...
vroom.ParseError: Unrecognized directive "nope"
>>> state = ParseState([])
>>> ActionLine(' @macro (abc)', state)
('macro', None, None)
Expand Down
63 changes: 36 additions & 27 deletions vroom/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ def BufferWord(word):
>>> BufferWord('2')
2
>>> try: BufferWord('not-a-buffer')
... except UnrecognizedWord as e: e
UnrecognizedWord('Unrecognized control word "not-a-buffer"',)
>>> BufferWord('not-a-buffer')
Traceback (most recent call last):
...
vroom.controls.UnrecognizedWord: Unrecognized control word "not-a-buffer"
Args:
word: The control string.
Expand Down Expand Up @@ -106,9 +107,10 @@ def RangeWord(word):
>>> RangeWord('20,')[0]
20
>>> try: RangeWord('farts')
... except UnrecognizedWord as e: e
UnrecognizedWord('Unrecognized control word "farts"',)
>>> RangeWord('farts')
Traceback (most recent call last):
...
vroom.controls.UnrecognizedWord: Unrecognized control word "farts"
Args:
word: The word to parse.
Expand Down Expand Up @@ -143,9 +145,10 @@ def DelayWord(word):
4.0
>>> DelayWord('4.1s')
4.1
>>> try: DelayWord('nope')
... except UnrecognizedWord as e: e
UnrecognizedWord('Unrecognized control word "nope"',)
>>> DelayWord('nope')
Traceback (most recent call last):
...
vroom.controls.UnrecognizedWord: Unrecognized control word "nope"
Args:
word: The word to parse.
Expand All @@ -169,9 +172,10 @@ def ModeWord(word):
True
>>> ModeWord('verbatim') == MODE.VERBATIM
True
>>> try: ModeWord('nope')
... except UnrecognizedWord as e: e
UnrecognizedWord('Unrecognized control word "nope"',)
>>> ModeWord('nope')
Traceback (most recent call last):
...
vroom.controls.UnrecognizedWord: Unrecognized control word "nope"
Args:
word: The word to parse.
Expand All @@ -196,9 +200,10 @@ def MessageWord(word):
True
>>> MessageWord('GUESS-ERRORS') == vroom.messages.STRICTNESS.ERRORS
True
>>> try: MessageWord('nope')
... except UnrecognizedWord as e: e
UnrecognizedWord('Unrecognized control word "nope"',)
>>> MessageWord('nope')
Traceback (most recent call last):
...
vroom.controls.UnrecognizedWord: Unrecognized control word "nope"
Args:
word: The word to parse.
Expand Down Expand Up @@ -229,9 +234,10 @@ def SystemWord(word):
True
>>> SystemWord('RELAXED') == vroom.shell.STRICTNESS.RELAXED
True
>>> try: SystemWord('nope')
... except UnrecognizedWord as e: e
UnrecognizedWord('Unrecognized control word "nope"',)
>>> SystemWord('nope')
Traceback (most recent call last):
...
vroom.controls.UnrecognizedWord: Unrecognized control word "nope"
Args:
word: The word to parse.
Expand Down Expand Up @@ -266,9 +272,10 @@ def OutputChannelWord(word):
True
>>> OutputChannelWord('status') == vroom.shell.OUTCHANNEL.STATUS
True
>>> try: OutputChannelWord('nope')
... except UnrecognizedWord as e: e
UnrecognizedWord('Unrecognized control word "nope"',)
>>> OutputChannelWord('nope')
Traceback (most recent call last):
...
vroom.controls.UnrecognizedWord: Unrecognized control word "nope"
Args:
word: The word to parse.
Expand Down Expand Up @@ -319,13 +326,15 @@ def Parse(controls, *options):
>>> (controls['buffer'], controls['delay'])
(2, 1.0)
>>> try: Parse('1 2 3', OPTION.DELAY, OPTION.BUFFER)
... except DuplicatedControl as e: e
DuplicatedControl('Duplicated buffer control "3"',)
>>> Parse('1 2 3', OPTION.DELAY, OPTION.BUFFER)
Traceback (most recent call last):
...
vroom.controls.DuplicatedControl: Duplicated buffer control "3"
>>> try: Parse('regex 4.02s', OPTION.MODE)
... except UnrecognizedWord as e: e
UnrecognizedWord('Unrecognized control word "4.02s"',)
>>> Parse('regex 4.02s', OPTION.MODE)
Traceback (most recent call last):
...
vroom.controls.UnrecognizedWord: Unrecognized control word "4.02s"
>>> Parse('STRICT', OPTION.MESSAGE_STRICTNESS)
{'messages': 'STRICT'}
Expand Down

0 comments on commit 379eefc

Please sign in to comment.