From 55c0cb15b8543a0079017e8f554538fda6037063 2015-07-24 20:42:17 From: Marin Gilles Date: 2015-07-24 20:42:17 Subject: [PATCH] Revert "added absolute_import to utils.text module + test" This reverts commit 20d56660bb155da29a927b94f3bdb15648bda36f. --- diff --git a/IPython/utils/tests/test_text.py b/IPython/utils/tests/test_text.py index 05cde06..b3ba76b 100644 --- a/IPython/utils/tests/test_text.py +++ b/IPython/utils/tests/test_text.py @@ -80,13 +80,13 @@ def eval_formatter_check(f): nt.assert_equal(s, ns['stuff']) s = f.format("{stuff!r}", **ns) nt.assert_equal(s, repr(ns['stuff'])) - + # Check with unicode: s = f.format("{u}", **ns) nt.assert_equal(s, ns['u']) # This decodes in a platform dependent manner, but it shouldn't error out s = f.format("{b}", **ns) - + nt.assert_raises(NameError, f.format, '{dne}', **ns) def eval_formatter_slicing_check(f): @@ -97,18 +97,18 @@ def eval_formatter_slicing_check(f): nt.assert_equal(s, " ['there', 'hello'] ") s = f.format("{stuff[::2]}", **ns) nt.assert_equal(s, ns['stuff'][::2]) - + nt.assert_raises(SyntaxError, f.format, "{n:x}", **ns) def eval_formatter_no_slicing_check(f): ns = dict(n=12, pi=math.pi, stuff='hello there', os=os) - + s = f.format('{n:x} {pi**2:+f}', **ns) nt.assert_equal(s, "c +9.869604") - + s = f.format('{stuff[slice(1,4)]}', **ns) nt.assert_equal(s, 'ell') - + if sys.version_info >= (3, 4): # String formatting has changed in Python 3.4, so this now works. s = f.format("{a[:]}", a=[1, 2]) @@ -130,7 +130,7 @@ def test_dollar_formatter(): f = text.DollarFormatter() eval_formatter_check(f) eval_formatter_slicing_check(f) - + ns = dict(n=12, pi=math.pi, stuff='hello there', os=os) s = f.format("$n", **ns) nt.assert_equal(s, "12") @@ -161,12 +161,12 @@ def test_strip_email(): src = """\ >> >>> def f(x): >> ... return x+1 - >> ... + >> ... >> >>> zz = f(2.5)""" cln = """\ >>> def f(x): ... return x+1 -... +... >>> zz = f(2.5)""" nt.assert_equal(text.strip_email_quotes(src), cln) @@ -187,7 +187,4 @@ def test_SList(): nt.assert_equal(sl.s, 'a 11 b 1 a 2') nt.assert_equal(sl.grep(lambda x: x.startswith('a')), text.SList(['a 11', 'a 2'])) nt.assert_equal(sl.fields(0), text.SList(['a', 'b', 'a'])) - nt.assert_equal(sl.sort(field=1, nums=True), text.SList(['b 1', 'a 2', 'a 11'])) - -def test_non_local_path_import(): - nt.assert_in("path", sys.modules) + nt.assert_equal(sl.sort(field=1, nums=True), text.SList(['b 1', 'a 2', 'a 11'])) \ No newline at end of file diff --git a/IPython/utils/text.py b/IPython/utils/text.py index 40ba281..1a08162 100644 --- a/IPython/utils/text.py +++ b/IPython/utils/text.py @@ -7,7 +7,6 @@ Inheritance diagram: .. inheritance-diagram:: IPython.utils.text :parts: 3 """ -from __future__ import absolute_import import os import re @@ -412,7 +411,7 @@ def wrap_paragraphs(text, ncols=80): def long_substr(data): """Return the longest common substring in a list of strings. - + Credit: http://stackoverflow.com/questions/2892931/longest-common-substring-from-more-than-two-strings-python """ substr = '' @@ -454,7 +453,7 @@ def strip_email_quotes(text): So if any line has no quote marks ('>') , then none are stripped from any of them :: - + In [5]: strip_email_quotes('> > text\\n> > more\\nlast different') Out[5]: '> > text\\n> > more\\nlast different' """ @@ -476,7 +475,7 @@ def strip_email_quotes(text): def strip_ansi(source): """ Remove ansi escape codes from text. - + Parameters ---------- source : str @@ -487,11 +486,11 @@ def strip_ansi(source): class EvalFormatter(Formatter): """A String Formatter that allows evaluation of simple expressions. - + Note that this version interprets a : as specifying a format string (as per standard string formatting), so if slicing is required, you must explicitly create a slice. - + This is to be used in templating cases, such as the parallel batch script templates, where simple arithmetic on arguments is useful. @@ -517,13 +516,13 @@ class EvalFormatter(Formatter): @skip_doctest_py3 class FullEvalFormatter(Formatter): """A String Formatter that allows evaluation of simple expressions. - + Any time a format key is not found in the kwargs, it will be tried as an expression in the kwargs namespace. - + Note that this version allows slicing using [1:2], so you cannot specify a format string. Use :class:`EvalFormatter` to permit format strings. - + Examples -------- :: @@ -597,7 +596,7 @@ class DollarFormatter(FullEvalFormatter): def parse(self, fmt_string): for literal_txt, field_name, format_spec, conversion \ in Formatter.parse(self, fmt_string): - + # Find $foo patterns in the literal text. continue_from = 0 txt = "" @@ -610,7 +609,7 @@ class DollarFormatter(FullEvalFormatter): yield (txt + new_txt, new_field, "", None) txt = "" continue_from = m.end() - + # Re-yield the {foo} style pattern yield (txt + literal_txt[continue_from:], field_name, format_spec, conversion) @@ -762,4 +761,4 @@ def get_text_list(list_, last_sep=' and ', sep=", ", wrap_item_with=""): return list_[0] return '%s%s%s' % ( sep.join(i for i in list_[:-1]), - last_sep, list_[-1]) + last_sep, list_[-1]) \ No newline at end of file