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 From eb73207913915be7131256a1ed80d2402ecf6ad6 Mon Sep 17 00:00:00 2001 From: Martin Vilcans Date: Wed, 12 Feb 2020 23:21:51 +0100 Subject: Removing Python 2 support - no need for six #54 --- requirements.txt | 1 - screenplain/parsers/fountain.py | 1 - screenplain/richstring.py | 3 +-- setup.py | 1 - tests/fdx_test.py | 2 +- tests/fountain_test.py | 2 +- tests/richstring_test.py | 3 +-- 7 files changed, 4 insertions(+), 9 deletions(-) diff --git a/requirements.txt b/requirements.txt index 97231be..a818b80 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,3 @@ reportlab unittest2 nose pycodestyle -six diff --git a/screenplain/parsers/fountain.py b/screenplain/parsers/fountain.py index c2f6d71..7f367aa 100644 --- a/screenplain/parsers/fountain.py +++ b/screenplain/parsers/fountain.py @@ -5,7 +5,6 @@ import itertools from itertools import takewhile import re -from six import next from screenplain.types import ( Slug, Action, Dialog, DualDialog, Transition, Section, PageBreak, diff --git a/screenplain/richstring.py b/screenplain/richstring.py index 75426e4..3890ecd 100644 --- a/screenplain/richstring.py +++ b/screenplain/richstring.py @@ -3,7 +3,6 @@ # http://www.opensource.org/licenses/mit-license.php import re -import six try: from html import escape as html_escape @@ -35,7 +34,7 @@ class RichString(object): return ' + '.join(repr(s) for s in self.segments) def __unicode__(self): - return ''.join(six.text_type(s) for s in self.segments) + return ''.join(str(s) for s in self.segments) def __str__(self): return self.__unicode__() diff --git a/setup.py b/setup.py index 68ad1c5..1b16e9f 100755 --- a/setup.py +++ b/setup.py @@ -15,7 +15,6 @@ setup( }, license='MIT', install_requires=[ - 'six', ], extras_require={ 'PDF': 'reportlab' diff --git a/tests/fdx_test.py b/tests/fdx_test.py index 497f908..3a3c8f7 100644 --- a/tests/fdx_test.py +++ b/tests/fdx_test.py @@ -3,7 +3,7 @@ # http://www.opensource.org/licenses/mit-license.php from testcompat import TestCase -from six import StringIO +from io import StringIO from screenplain.export.fdx import write_text from screenplain.richstring import plain, bold, italic diff --git a/tests/fountain_test.py b/tests/fountain_test.py index c31cc66..141772a 100644 --- a/tests/fountain_test.py +++ b/tests/fountain_test.py @@ -9,7 +9,7 @@ from screenplain.types import ( Slug, Action, Dialog, DualDialog, Transition, Section, PageBreak ) from screenplain.richstring import plain, italic, empty_string -from six import StringIO +from io import StringIO def parse(lines): diff --git a/tests/richstring_test.py b/tests/richstring_test.py index ee42087..82b2af0 100644 --- a/tests/richstring_test.py +++ b/tests/richstring_test.py @@ -3,7 +3,6 @@ # http://www.opensource.org/licenses/mit-license.php from testcompat import TestCase -import six from screenplain.richstring import ( RichString, Segment, Bold, Italic, @@ -39,7 +38,7 @@ class RichStringOperatorTests(TestCase): s = bold('Hello') + plain(' there ') + bold('folks') self.assertEquals( u'Hello there folks', - six.text_type(s) + str(s) ) def test_eq(self): -- cgit