Пример #1
0
def get_parser():
    p = Parser()
    try:
        os.mkdir("/tmp/Test Dir")
    except OSError:
        pass  # dir exists
    open("/tmp/Test Dir/test.txt", "w").close()
    return p
Пример #2
0
def test_parser():
    p = Parser()

    info = p.parse_code('import nump')
    assert info['help_obj'] == info['obj'] == 'nump'

    assert p.parse_code('%python impor', 0, 10)['magic']['name'] == 'python'
    assert p.parse_code('oct(a,')['help_obj'] == 'oct'
    assert p.parse_code('! ls')['magic']['name'] == 'shell'

    info = p.parse_code('%help %lsmagic', 0, 10)
    assert info['help_obj'] == '%lsmagic'
    assert info['obj'] == '%lsm'

    info = p.parse_code('%%python\nprint("hello, world!",')
    assert info['help_obj'] == 'print'

    info = p.parse_code('%lsmagic')
    assert info['help_obj'] == '%lsmagic'

    info = p.parse_code('%')
    assert info['magic']['type'] == 'line'
Пример #3
0
    def __init__(self, **kwargs):

        MetaKernel.__init__(self, **kwargs)
        setStyle()
        self.ioHandler = GetIOHandler()
        self.Executor = GetExecutor()
        self.Declarer = GetDeclarer()  #required for %%cpp -d magic
        self.ACLiC = invokeAclic
        self.magicloader = MagicLoader(self)
        self.parser = Parser(self.identifier_regex, self.func_call_regex,
                             self.magic_prefixes, self.help_suffix)
        self.completer = CppCompleter()
        self.completer.activate()
Пример #4
0
def test_path_completions():
    p = Parser()

    if not os.name == 'nt':
        code = '/usr/bi'
        assert 'bin/' in p.parse_code(code)['path_matches']
    code = '~/.bashr'
    assert 'bashrc' in p.parse_code(code)['path_matches']

    for f in os.listdir('.'):
        if f.startswith('.'):
            if os.path.isdir(f):
                assert f[1:] + os.sep in p.parse_code('.')['path_matches'], f
            else:
                assert f[1:] in p.parse_code('.')['path_matches']
Пример #5
0
def test_complete0():
    p = Parser()
    info = p.parse_code('abcdefghijklmnop', 0, 4)
    assert info['obj'] == 'abcd', info
Пример #6
0
def test_scheme_parser():
    function_call_regex = r'\(([^\d\W][\w\.]*)[^\)\()]*\Z'
    p = Parser(function_call_regex=function_call_regex)

    info = p.parse_code('(oct a b ')
    assert info['help_obj'] == 'oct'