本文整理汇总了Python中yap_ipython.get_ipython函数的典型用法代码示例。如果您正苦于以下问题:Python get_ipython函数的具体用法?Python get_ipython怎么用?Python get_ipython使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_ipython函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_quoted_file_completions
def test_quoted_file_completions():
ip = get_ipython()
with TemporaryWorkingDirectory():
name = "foo'bar"
open(name, 'w').close()
# Don't escape Windows
escaped = name if sys.platform == "win32" else "foo\\'bar"
# Single quote matches embedded single quote
text = "open('foo"
c = ip.Completer._complete(cursor_line=0,
cursor_pos=len(text),
full_text=text)[1]
nt.assert_equal(c, [escaped])
# Double quote requires no escape
text = 'open("foo'
c = ip.Completer._complete(cursor_line=0,
cursor_pos=len(text),
full_text=text)[1]
nt.assert_equal(c, [name])
# No quote requires an escape
text = '%ls foo'
c = ip.Completer._complete(cursor_line=0,
cursor_pos=len(text),
full_text=text)[1]
nt.assert_equal(c, [escaped])
开发者ID:vscosta,项目名称:yap-6.3,代码行数:29,代码来源:test_completer.py
示例2: test_jedi
def test_jedi():
"""
A couple of issue we had with Jedi
"""
ip = get_ipython()
def _test_complete(reason, s, comp, start=None, end=None):
l = len(s)
start = start if start is not None else l
end = end if end is not None else l
with provisionalcompleter():
completions = set(ip.Completer.completions(s, l))
assert_in(Completion(start, end, comp), completions, reason)
def _test_not_complete(reason, s, comp):
l = len(s)
with provisionalcompleter():
completions = set(ip.Completer.completions(s, l))
assert_not_in(Completion(l, l, comp), completions, reason)
import jedi
jedi_version = tuple(int(i) for i in jedi.__version__.split('.')[:3])
if jedi_version > (0, 10):
yield _test_complete, 'jedi >0.9 should complete and not crash', 'a=1;a.', 'real'
yield _test_complete, 'can infer first argument', 'a=(1,"foo");a[0].', 'real'
yield _test_complete, 'can infer second argument', 'a=(1,"foo");a[1].', 'capitalize'
yield _test_complete, 'cover duplicate completions', 'im', 'import', 0, 2
yield _test_not_complete, 'does not mix types', 'a=(1,"foo");a[0].', 'capitalize'
开发者ID:vscosta,项目名称:yap-6.3,代码行数:29,代码来源:test_completer.py
示例3: test_no_ascii_back_completion
def test_no_ascii_back_completion():
ip = get_ipython()
with TemporaryWorkingDirectory(): # Avoid any filename completions
# single ascii letter that don't have yet completions
for letter in 'jJ' :
name, matches = ip.complete('\\'+letter)
nt.assert_equal(matches, [])
开发者ID:vscosta,项目名称:yap-6.3,代码行数:7,代码来源:test_completer.py
示例4: test_object_key_completion
def test_object_key_completion():
ip = get_ipython()
ip.user_ns['key_completable'] = KeyCompletable(['qwerty', 'qwick'])
_, matches = ip.Completer.complete(line_buffer="key_completable['qw")
nt.assert_in('qwerty', matches)
nt.assert_in('qwick', matches)
开发者ID:vscosta,项目名称:yap-6.3,代码行数:7,代码来源:test_completer.py
示例5: test_snake_case_completion
def test_snake_case_completion():
ip = get_ipython()
ip.user_ns['some_three'] = 3
ip.user_ns['some_four'] = 4
_, matches = ip.complete("s_", "print(s_f")
nt.assert_in('some_three', matches)
nt.assert_in('some_four', matches)
开发者ID:vscosta,项目名称:yap-6.3,代码行数:7,代码来源:test_completer.py
示例6: test_ipython_display_formatter
def test_ipython_display_formatter():
"""Objects with _ipython_display_ defined bypass other formatters"""
f = get_ipython().display_formatter
catcher = []
class SelfDisplaying(object):
def _ipython_display_(self):
catcher.append(self)
class NotSelfDisplaying(object):
def __repr__(self):
return "NotSelfDisplaying"
def _ipython_display_(self):
raise NotImplementedError
save_enabled = f.ipython_display_formatter.enabled
f.ipython_display_formatter.enabled = True
yes = SelfDisplaying()
no = NotSelfDisplaying()
d, md = f.format(no)
nt.assert_equal(d, {'text/plain': repr(no)})
nt.assert_equal(md, {})
nt.assert_equal(catcher, [])
d, md = f.format(yes)
nt.assert_equal(d, {})
nt.assert_equal(md, {})
nt.assert_equal(catcher, [yes])
f.ipython_display_formatter.enabled = save_enabled
开发者ID:vscosta,项目名称:yap-6.3,代码行数:32,代码来源:test_formatters.py
示例7: test_dict_key_completion_bytes
def test_dict_key_completion_bytes():
"""Test handling of bytes in dict key completion"""
ip = get_ipython()
complete = ip.Completer.complete
ip.user_ns['d'] = {'abc': None, b'abd': None}
_, matches = complete(line_buffer="d[")
nt.assert_in("'abc'", matches)
nt.assert_in("b'abd'", matches)
if False: # not currently implemented
_, matches = complete(line_buffer="d[b")
nt.assert_in("b'abd'", matches)
nt.assert_not_in("b'abc'", matches)
_, matches = complete(line_buffer="d[b'")
nt.assert_in("abd", matches)
nt.assert_not_in("abc", matches)
_, matches = complete(line_buffer="d[B'")
nt.assert_in("abd", matches)
nt.assert_not_in("abc", matches)
_, matches = complete(line_buffer="d['")
nt.assert_in("abc", matches)
nt.assert_not_in("abd", matches)
开发者ID:vscosta,项目名称:yap-6.3,代码行数:27,代码来源:test_completer.py
示例8: test_dict_key_completion_unicode_py3
def test_dict_key_completion_unicode_py3():
"""Test handling of unicode in dict key completion"""
ip = get_ipython()
complete = ip.Completer.complete
ip.user_ns['d'] = {u'a\u05d0': None}
# query using escape
if sys.platform != 'win32':
# Known failure on Windows
_, matches = complete(line_buffer="d['a\\u05d0")
nt.assert_in("u05d0", matches) # tokenized after \\
# query using character
_, matches = complete(line_buffer="d['a\u05d0")
nt.assert_in(u"a\u05d0", matches)
with greedy_completion():
# query using escape
_, matches = complete(line_buffer="d['a\\u05d0")
nt.assert_in("d['a\\u05d0']", matches) # tokenized after \\
# query using character
_, matches = complete(line_buffer="d['a\u05d0")
nt.assert_in(u"d['a\u05d0']", matches)
开发者ID:vscosta,项目名称:yap-6.3,代码行数:25,代码来源:test_completer.py
示例9: test_magic_completion_order
def test_magic_completion_order():
ip = get_ipython()
c = ip.Completer
# Test ordering of line and cell magics.
text, matches = c.complete("timeit")
nt.assert_equal(matches, ["%timeit", "%%timeit"])
开发者ID:vscosta,项目名称:yap-6.3,代码行数:7,代码来源:test_completer.py
示例10: test_magic_config
def test_magic_config():
ip = get_ipython()
c = ip.Completer
s, matches = c.complete(None, 'conf')
nt.assert_in('%config', matches)
s, matches = c.complete(None, 'conf')
nt.assert_not_in('AliasManager', matches)
s, matches = c.complete(None, 'config ')
nt.assert_in('AliasManager', matches)
s, matches = c.complete(None, '%config ')
nt.assert_in('AliasManager', matches)
s, matches = c.complete(None, 'config Ali')
nt.assert_list_equal(['AliasManager'], matches)
s, matches = c.complete(None, '%config Ali')
nt.assert_list_equal(['AliasManager'], matches)
s, matches = c.complete(None, 'config AliasManager')
nt.assert_list_equal(['AliasManager'], matches)
s, matches = c.complete(None, '%config AliasManager')
nt.assert_list_equal(['AliasManager'], matches)
s, matches = c.complete(None, 'config AliasManager.')
nt.assert_in('AliasManager.default_aliases', matches)
s, matches = c.complete(None, '%config AliasManager.')
nt.assert_in('AliasManager.default_aliases', matches)
s, matches = c.complete(None, 'config AliasManager.de')
nt.assert_list_equal(['AliasManager.default_aliases'], matches)
s, matches = c.complete(None, 'config AliasManager.de')
nt.assert_list_equal(['AliasManager.default_aliases'], matches)
开发者ID:vscosta,项目名称:yap-6.3,代码行数:28,代码来源:test_completer.py
示例11: test_line_magics
def test_line_magics():
ip = get_ipython()
c = ip.Completer
s, matches = c.complete(None, 'lsmag')
nt.assert_in('%lsmagic', matches)
s, matches = c.complete(None, '%lsmag')
nt.assert_in('%lsmagic', matches)
开发者ID:vscosta,项目名称:yap-6.3,代码行数:7,代码来源:test_completer.py
示例12: test_repr_mime
def test_repr_mime():
class HasReprMime(object):
def _repr_mimebundle_(self, include=None, exclude=None):
return {
'application/json+test.v2': {
'x': 'y'
},
'plain/text' : '<HasReprMime>',
'image/png' : 'i-overwrite'
}
def _repr_png_(self):
return 'should-be-overwritten'
def _repr_html_(self):
return '<b>hi!</b>'
f = get_ipython().display_formatter
html_f = f.formatters['text/html']
save_enabled = html_f.enabled
html_f.enabled = True
obj = HasReprMime()
d, md = f.format(obj)
html_f.enabled = save_enabled
nt.assert_equal(sorted(d), ['application/json+test.v2',
'image/png',
'plain/text',
'text/html',
'text/plain'])
nt.assert_equal(md, {})
d, md = f.format(obj, include={'image/png'})
nt.assert_equal(list(d.keys()), ['image/png'],
'Include should filter out even things from repr_mimebundle')
nt.assert_equal(d['image/png'], 'i-overwrite', '_repr_mimebundle_ take precedence')
开发者ID:vscosta,项目名称:yap-6.3,代码行数:35,代码来源:test_formatters.py
示例13: test_greedy_completions
def test_greedy_completions():
"""
Test the capability of the Greedy completer.
Most of the test here do not really show off the greedy completer, for proof
each of the text bellow now pass with Jedi. The greedy completer is capable of more.
See the :any:`test_dict_key_completion_contexts`
"""
ip = get_ipython()
ip.ex('a=list(range(5))')
_,c = ip.complete('.',line='a[0].')
nt.assert_false('.real' in c,
"Shouldn't have completed on a[0]: %s"%c)
with greedy_completion(), provisionalcompleter():
def _(line, cursor_pos, expect, message, completion):
_,c = ip.complete('.', line=line, cursor_pos=cursor_pos)
with provisionalcompleter():
completions = ip.Completer.completions(line, cursor_pos)
nt.assert_in(expect, c, message%c)
nt.assert_in(completion, completions)
yield _, 'a[0].', 5, 'a[0].real', "Should have completed on a[0].: %s", Completion(5,5, 'real')
yield _, 'a[0].r', 6, 'a[0].real', "Should have completed on a[0].r: %s", Completion(5,6, 'real')
if sys.version_info > (3, 4):
yield _, 'a[0].from_', 10, 'a[0].from_bytes', "Should have completed on a[0].from_: %s", Completion(5, 10, 'from_bytes')
开发者ID:vscosta,项目名称:yap-6.3,代码行数:28,代码来源:test_completer.py
示例14: test_back_latex_completion
def test_back_latex_completion():
ip = get_ipython()
# do not return more than 1 matches fro \beta, only the latex one.
name, matches = ip.complete('\\β')
nt.assert_equal(len(matches), 1)
nt.assert_equal(matches[0], '\\beta')
开发者ID:vscosta,项目名称:yap-6.3,代码行数:7,代码来源:test_completer.py
示例15: greedy_completion
def greedy_completion():
ip = get_ipython()
greedy_original = ip.Completer.greedy
try:
ip.Completer.greedy = True
yield
finally:
ip.Completer.greedy = greedy_original
开发者ID:vscosta,项目名称:yap-6.3,代码行数:8,代码来源:test_completer.py
示例16: test_repr_mime_failure
def test_repr_mime_failure():
class BadReprMime(object):
def _repr_mimebundle_(self, include=None, exclude=None):
raise RuntimeError
f = get_ipython().display_formatter
obj = BadReprMime()
d, md = f.format(obj)
nt.assert_in('text/plain', d)
开发者ID:vscosta,项目名称:yap-6.3,代码行数:9,代码来源:test_formatters.py
示例17: test_dataframe_key_completion
def test_dataframe_key_completion():
"""Test dict key completion applies to pandas DataFrames"""
import pandas
ip = get_ipython()
complete = ip.Completer.complete
ip.user_ns['d'] = pandas.DataFrame({'hello': [1], 'world': [2]})
_, matches = complete(line_buffer="d['")
nt.assert_in("hello", matches)
nt.assert_in("world", matches)
开发者ID:vscosta,项目名称:yap-6.3,代码行数:9,代码来源:test_completer.py
示例18: test_class_key_completion
def test_class_key_completion():
ip = get_ipython()
NamedInstanceClass('qwerty')
NamedInstanceClass('qwick')
ip.user_ns['named_instance_class'] = NamedInstanceClass
_, matches = ip.Completer.complete(line_buffer="named_instance_class['qw")
nt.assert_in('qwerty', matches)
nt.assert_in('qwick', matches)
开发者ID:vscosta,项目名称:yap-6.3,代码行数:9,代码来源:test_completer.py
示例19: test_omit__names
def test_omit__names():
# also happens to test IPCompleter as a configurable
ip = get_ipython()
ip._hidden_attr = 1
ip._x = {}
c = ip.Completer
ip.ex('ip=get_ipython()')
cfg = Config()
cfg.IPCompleter.omit__names = 0
c.update_config(cfg)
with provisionalcompleter():
s,matches = c.complete('ip.')
completions = set(c.completions('ip.', 3))
nt.assert_in('ip.__str__', matches)
nt.assert_in(Completion(3, 3, '__str__'), completions)
nt.assert_in('ip._hidden_attr', matches)
nt.assert_in(Completion(3,3, "_hidden_attr"), completions)
cfg = Config()
cfg.IPCompleter.omit__names = 1
c.update_config(cfg)
with provisionalcompleter():
s,matches = c.complete('ip.')
completions = set(c.completions('ip.', 3))
nt.assert_not_in('ip.__str__', matches)
nt.assert_not_in(Completion(3,3,'__str__'), completions)
# nt.assert_in('ip._hidden_attr', matches)
nt.assert_in(Completion(3,3, "_hidden_attr"), completions)
cfg = Config()
cfg.IPCompleter.omit__names = 2
c.update_config(cfg)
with provisionalcompleter():
s,matches = c.complete('ip.')
completions = set(c.completions('ip.', 3))
nt.assert_not_in('ip.__str__', matches)
nt.assert_not_in(Completion(3,3,'__str__'), completions)
nt.assert_not_in('ip._hidden_attr', matches)
nt.assert_not_in(Completion(3,3, "_hidden_attr"), completions)
with provisionalcompleter():
s,matches = c.complete('ip._x.')
completions = set(c.completions('ip._x.', 6))
nt.assert_in('ip._x.keys', matches)
nt.assert_in(Completion(6,6, "keys"), completions)
del ip._hidden_attr
del ip._x
开发者ID:vscosta,项目名称:yap-6.3,代码行数:56,代码来源:test_completer.py
示例20: test_completion_have_signature
def test_completion_have_signature():
"""
Lets make sure jedi is capable of pulling out the signature of the function we are completing.
"""
ip = get_ipython()
with provisionalcompleter():
completions = ip.Completer.completions('ope', 3)
c = next(completions) # should be `open`
assert 'file' in c.signature, "Signature of function was not found by completer"
assert 'encoding' in c.signature, "Signature of function was not found by completer"
开发者ID:vscosta,项目名称:yap-6.3,代码行数:10,代码来源:test_completer.py
注:本文中的yap_ipython.get_ipython函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论