From 379eefc111209d0e1ac59815f2fde93715495879 Mon Sep 17 00:00:00 2001 From: David Barnett Date: Mon, 20 Jan 2020 14:55:08 -0800 Subject: [PATCH] Tests: Fix exception doctests for python 3.7 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). --- vroom/actions.py | 7 +++--- vroom/controls.py | 63 +++++++++++++++++++++++++++-------------------- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/vroom/actions.py b/vroom/actions.py index fca0d51..4920fe4 100644 --- a/vroom/actions.py +++ b/vroom/actions.py @@ -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) diff --git a/vroom/controls.py b/vroom/controls.py index 7776440..57301dd 100644 --- a/vroom/controls.py +++ b/vroom/controls.py @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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'}