##// END OF EJS Templates
Revert "added absolute_import to utils.text module + test"...
Marin Gilles -
Show More
@@ -80,13 +80,13 b' def eval_formatter_check(f):'
80 80 nt.assert_equal(s, ns['stuff'])
81 81 s = f.format("{stuff!r}", **ns)
82 82 nt.assert_equal(s, repr(ns['stuff']))
83
83
84 84 # Check with unicode:
85 85 s = f.format("{u}", **ns)
86 86 nt.assert_equal(s, ns['u'])
87 87 # This decodes in a platform dependent manner, but it shouldn't error out
88 88 s = f.format("{b}", **ns)
89
89
90 90 nt.assert_raises(NameError, f.format, '{dne}', **ns)
91 91
92 92 def eval_formatter_slicing_check(f):
@@ -97,18 +97,18 b' def eval_formatter_slicing_check(f):'
97 97 nt.assert_equal(s, " ['there', 'hello'] ")
98 98 s = f.format("{stuff[::2]}", **ns)
99 99 nt.assert_equal(s, ns['stuff'][::2])
100
100
101 101 nt.assert_raises(SyntaxError, f.format, "{n:x}", **ns)
102 102
103 103 def eval_formatter_no_slicing_check(f):
104 104 ns = dict(n=12, pi=math.pi, stuff='hello there', os=os)
105
105
106 106 s = f.format('{n:x} {pi**2:+f}', **ns)
107 107 nt.assert_equal(s, "c +9.869604")
108
108
109 109 s = f.format('{stuff[slice(1,4)]}', **ns)
110 110 nt.assert_equal(s, 'ell')
111
111
112 112 if sys.version_info >= (3, 4):
113 113 # String formatting has changed in Python 3.4, so this now works.
114 114 s = f.format("{a[:]}", a=[1, 2])
@@ -130,7 +130,7 b' def test_dollar_formatter():'
130 130 f = text.DollarFormatter()
131 131 eval_formatter_check(f)
132 132 eval_formatter_slicing_check(f)
133
133
134 134 ns = dict(n=12, pi=math.pi, stuff='hello there', os=os)
135 135 s = f.format("$n", **ns)
136 136 nt.assert_equal(s, "12")
@@ -161,12 +161,12 b' def test_strip_email():'
161 161 src = """\
162 162 >> >>> def f(x):
163 163 >> ... return x+1
164 >> ...
164 >> ...
165 165 >> >>> zz = f(2.5)"""
166 166 cln = """\
167 167 >>> def f(x):
168 168 ... return x+1
169 ...
169 ...
170 170 >>> zz = f(2.5)"""
171 171 nt.assert_equal(text.strip_email_quotes(src), cln)
172 172
@@ -187,7 +187,4 b' def test_SList():'
187 187 nt.assert_equal(sl.s, 'a 11 b 1 a 2')
188 188 nt.assert_equal(sl.grep(lambda x: x.startswith('a')), text.SList(['a 11', 'a 2']))
189 189 nt.assert_equal(sl.fields(0), text.SList(['a', 'b', 'a']))
190 nt.assert_equal(sl.sort(field=1, nums=True), text.SList(['b 1', 'a 2', 'a 11']))
191
192 def test_non_local_path_import():
193 nt.assert_in("path", sys.modules)
190 nt.assert_equal(sl.sort(field=1, nums=True), text.SList(['b 1', 'a 2', 'a 11'])) No newline at end of file
@@ -7,7 +7,6 b' Inheritance diagram:'
7 7 .. inheritance-diagram:: IPython.utils.text
8 8 :parts: 3
9 9 """
10 from __future__ import absolute_import
11 10
12 11 import os
13 12 import re
@@ -412,7 +411,7 b' def wrap_paragraphs(text, ncols=80):'
412 411
413 412 def long_substr(data):
414 413 """Return the longest common substring in a list of strings.
415
414
416 415 Credit: http://stackoverflow.com/questions/2892931/longest-common-substring-from-more-than-two-strings-python
417 416 """
418 417 substr = ''
@@ -454,7 +453,7 b' def strip_email_quotes(text):'
454 453
455 454 So if any line has no quote marks ('>') , then none are stripped from any
456 455 of them ::
457
456
458 457 In [5]: strip_email_quotes('> > text\\n> > more\\nlast different')
459 458 Out[5]: '> > text\\n> > more\\nlast different'
460 459 """
@@ -476,7 +475,7 b' def strip_email_quotes(text):'
476 475 def strip_ansi(source):
477 476 """
478 477 Remove ansi escape codes from text.
479
478
480 479 Parameters
481 480 ----------
482 481 source : str
@@ -487,11 +486,11 b' def strip_ansi(source):'
487 486
488 487 class EvalFormatter(Formatter):
489 488 """A String Formatter that allows evaluation of simple expressions.
490
489
491 490 Note that this version interprets a : as specifying a format string (as per
492 491 standard string formatting), so if slicing is required, you must explicitly
493 492 create a slice.
494
493
495 494 This is to be used in templating cases, such as the parallel batch
496 495 script templates, where simple arithmetic on arguments is useful.
497 496
@@ -517,13 +516,13 b' class EvalFormatter(Formatter):'
517 516 @skip_doctest_py3
518 517 class FullEvalFormatter(Formatter):
519 518 """A String Formatter that allows evaluation of simple expressions.
520
519
521 520 Any time a format key is not found in the kwargs,
522 521 it will be tried as an expression in the kwargs namespace.
523
522
524 523 Note that this version allows slicing using [1:2], so you cannot specify
525 524 a format string. Use :class:`EvalFormatter` to permit format strings.
526
525
527 526 Examples
528 527 --------
529 528 ::
@@ -597,7 +596,7 b' class DollarFormatter(FullEvalFormatter):'
597 596 def parse(self, fmt_string):
598 597 for literal_txt, field_name, format_spec, conversion \
599 598 in Formatter.parse(self, fmt_string):
600
599
601 600 # Find $foo patterns in the literal text.
602 601 continue_from = 0
603 602 txt = ""
@@ -610,7 +609,7 b' class DollarFormatter(FullEvalFormatter):'
610 609 yield (txt + new_txt, new_field, "", None)
611 610 txt = ""
612 611 continue_from = m.end()
613
612
614 613 # Re-yield the {foo} style pattern
615 614 yield (txt + literal_txt[continue_from:], field_name, format_spec, conversion)
616 615
@@ -762,4 +761,4 b' def get_text_list(list_, last_sep=\' and \', sep=", ", wrap_item_with=""):'
762 761 return list_[0]
763 762 return '%s%s%s' % (
764 763 sep.join(i for i in list_[:-1]),
765 last_sep, list_[-1])
764 last_sep, list_[-1]) No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now