MCPcopy Index your code
hub / github.com/ipython/ipython / eval_formatter_check

Function eval_formatter_check

tests/test_text.py:37–56  ·  view source on GitHub ↗
(f)

Source from the content-addressed store, hash-verified

35
36
37def eval_formatter_check(f):
38 ns = dict(n=12, pi=math.pi, stuff="hello there", os=os, u="café", b="café")
39 s = f.format("{n} {n//4} {stuff.split()[0]}", **ns)
40 assert s == "12 3 hello"
41 s = f.format(" ".join(["{n//%i}" % i for i in range(1, 8)]), **ns)
42 assert s == "12 6 4 3 2 2 1"
43 s = f.format("{list(n//i for i in range(1,8))}", **ns)
44 assert s == "[12, 6, 4, 3, 2, 2, 1]"
45 s = f.format("{stuff!s}", **ns)
46 assert s == ns["stuff"]
47 s = f.format("{stuff!r}", **ns)
48 assert s == repr(ns["stuff"])
49
50 # Check with unicode:
51 s = f.format("{u}", **ns)
52 assert s == ns["u"]
53 # This decodes in a platform dependent manner, but it shouldn't error out
54 s = f.format("{b}", **ns)
55
56 pytest.raises(NameError, f.format, "{dne}", **ns)
57
58
59def eval_formatter_slicing_check(f):

Callers 3

test_eval_formatterFunction · 0.85
test_full_eval_formatterFunction · 0.85
test_dollar_formatterFunction · 0.85

Calls 1

formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…