Skip to content

Commit

Permalink
drop some unused cruft
Browse files Browse the repository at this point in the history
  • Loading branch information
trentm committed Sep 2, 2010
1 parent b2fa662 commit f87da7e
Showing 1 changed file with 1 addition and 89 deletions.
90 changes: 1 addition & 89 deletions test/test_eol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@
# Copyright (c) 2010 ActiveState Software Inc.
# License: MIT (http://www.opensource.org/licenses/mit-license.php)

"""Test eol.py."""

import os
import sys
from os.path import join, dirname, abspath, exists, splitext, basename
import re
from glob import glob
from pprint import pprint
import unittest
import codecs
import difflib
import doctest

from testlib import TestError, TestSkipped, tag


class DocTestsTestCase(unittest.TestCase):
def test_api(self):
if sys.version_info[:2] < (2,4):
Expand All @@ -28,85 +22,3 @@ def test_internal(self):
import eol
doctest.testmod(eol)



#---- internal support stuff


# Recipe: text_escape (0.1)
def _escaped_text_from_text(text, escapes="eol"):
r"""Return escaped version of text.
"escapes" is either a mapping of chars in the source text to
replacement text for each such char or one of a set of
strings identifying a particular escape style:
eol
replace EOL chars with '\r' and '\n', maintain the actual
EOLs though too
whitespace
replace EOL chars as above, tabs with '\t' and spaces
with periods ('.')
eol-one-line
replace EOL chars with '\r' and '\n'
whitespace-one-line
replace EOL chars as above, tabs with '\t' and spaces
with periods ('.')
"""
#TODO:
# - Add 'c-string' style.
# - Add _escaped_html_from_text() with a similar call sig.
import re

if isinstance(escapes, basestring):
if escapes == "eol":
escapes = {'\r\n': "\\r\\n\r\n", '\n': "\\n\n", '\r': "\\r\r"}
elif escapes == "whitespace":
escapes = {'\r\n': "\\r\\n\r\n", '\n': "\\n\n", '\r': "\\r\r",
'\t': "\\t", ' ': "."}
elif escapes == "eol-one-line":
escapes = {'\n': "\\n", '\r': "\\r"}
elif escapes == "whitespace-one-line":
escapes = {'\n': "\\n", '\r': "\\r", '\t': "\\t", ' ': '.'}
else:
raise ValueError("unknown text escape style: %r" % escapes)

# Sort longer replacements first to allow, e.g. '\r\n' to beat '\r' and
# '\n'.
escapes_keys = escapes.keys()
try:
escapes_keys.sort(key=lambda a: len(a), reverse=True)
except TypeError:
# Python 2.3 support: sort() takes no keyword arguments
escapes_keys.sort(lambda a,b: cmp(len(a), len(b)))
escapes_keys.reverse()
def repl(match):
val = escapes[match.group(0)]
return val
escaped = re.sub("(%s)" % '|'.join([re.escape(k) for k in escapes_keys]),
repl,
text)

return escaped

def _one_line_summary_from_text(text, length=78,
escapes={'\n':"\\n", '\r':"\\r", '\t':"\\t"}):
r"""Summarize the given text with one line of the given length.
"text" is the text to summarize
"length" (default 78) is the max length for the summary
"escapes" is a mapping of chars in the source text to
replacement text for each such char. By default '\r', '\n'
and '\t' are escaped with their '\'-escaped repr.
"""
if len(text) > length:
head = text[:length-3]
else:
head = text
escaped = _escaped_text_from_text(head, escapes)
if len(text) > length:
summary = escaped[:length-3] + "..."
else:
summary = escaped
return summary


0 comments on commit f87da7e

Please sign in to comment.