From 5d6b4683b7a4058b7f12dcc294eec5e2f41cda6f Mon Sep 17 00:00:00 2001 From: Martin Vilcans Date: Wed, 12 Feb 2020 23:17:19 +0100 Subject: Remove Python 2 support for doctests #54 --- bin/test | 11 +++-------- screenplain/richstring.py | 34 +++++++++++++++++----------------- test.py | 24 ------------------------ 3 files changed, 20 insertions(+), 49 deletions(-) delete mode 100644 test.py diff --git a/bin/test b/bin/test index 4ffcb17..5379c1b 100755 --- a/bin/test +++ b/bin/test @@ -1,8 +1,3 @@ -#!/bin/bash -if [[ $(python -V 2>&1) =~ "Python 2" ]] -then - nosetests --nocapture --with-doctest --doctest-tests -I ^test.py $* && \ - pycodestyle --ignore=E402,W504 screenplain tests -else - python test.py && pycodestyle --ignore=E402,W504 screenplain tests -fi +#!/bin/bash -e +nosetests --nocapture --with-doctest --doctest-tests +pycodestyle --ignore=E402,W504 screenplain tests diff --git a/screenplain/richstring.py b/screenplain/richstring.py index 2fafd9b..75426e4 100644 --- a/screenplain/richstring.py +++ b/screenplain/richstring.py @@ -10,7 +10,7 @@ try: except ImportError: from cgi import escape as html_escape -_magic_re = re.compile(u'[\ue700-\ue705]') +_magic_re = re.compile('[\ue700-\ue705]') def _escape(s): @@ -169,8 +169,8 @@ class Italic(Style): r'(?!\*)' ) - start_magic = u'\ue700' - end_magic = u'\ue701' + start_magic = '\ue700' + end_magic = '\ue701' start_html = '' end_html = '' @@ -189,8 +189,8 @@ class Bold(Style): r'(?<=\S)\*\*' ) - start_magic = u'\ue702' - end_magic = u'\ue703' + start_magic = '\ue702' + end_magic = '\ue703' start_html = '' end_html = '' @@ -209,8 +209,8 @@ class Underline(Style): r'(?<=\S)_' ) - start_magic = u'\ue704' - end_magic = u'\ue705' + start_magic = '\ue704' + end_magic = '\ue705' start_html = '' # TODO: use an actual html5 tag end_html = '' @@ -238,7 +238,7 @@ underline = _CreateStyledString((Underline,)) empty_string = RichString() # A special unicode character to use for a literal '*' -literal_star = u'\ue706' +literal_star = '\ue706' # All styles. Note: order matters! This is the order they are parsed. all_styles = (Bold, Italic, Underline) @@ -249,7 +249,7 @@ def _unescape(source): "literal star" character. >>> _unescape(r'\*hello\*') - u'\ue706hello\ue706' + '\ue706hello\ue706' """ return source.replace('\\*', literal_star) @@ -258,8 +258,8 @@ def _unescape(source): def _demagic_literals(text): r"""Converts "literal star" characters to actual stars: "*" - >>> _demagic_literals(u'\ue706hello\ue706') - u'*hello*' + >>> _demagic_literals('\ue706hello\ue706') + '*hello*' """ return text.replace(literal_star, '*') @@ -268,12 +268,12 @@ def parse_emphasis(source): """Parses emphasis markers like * and ** in a string and returns a RichString object. - >>> parse_emphasis(u'**hello**') - (bold)(u'hello') - >>> parse_emphasis(u'plain') - (plain)(u'plain') - >>> parse_emphasis(u'**hello** there') - (bold)(u'hello') + (plain)(u' there') + >>> parse_emphasis('**hello**') + (bold)('hello') + >>> parse_emphasis('plain') + (plain)('plain') + >>> parse_emphasis('**hello** there') + (bold)('hello') + (plain)(' there') """ # Convert escaped characters to magic characters so they aren't parsed diff --git a/test.py b/test.py deleted file mode 100644 index c4e5887..0000000 --- a/test.py +++ /dev/null @@ -1,24 +0,0 @@ -"""Runs nosetest after preparing the test cases. - -Removes the leading u from unicode literals so -Python 3 doctests won't fail. - -""" - -from screenplain import richstring -import re - -unicode_literal = re.compile(r'u([\'"])') - -for n in ( - 'parse_emphasis', - '_unescape', - '_demagic_literals', -): - attr = getattr(richstring, n) - old_doc = getattr(attr, '__doc__') - new_doc = unicode_literal.sub(r'\1', old_doc) - setattr(attr, '__doc__', new_doc) - -import nose -nose.main(argv='nosetests --nocapture --with-doctest --doctest-tests'.split()) -- cgit