Exemplo n.º 1
0
def test_preload_modules():
    def check_loaded(*modules):
        # +1 for None module (currently used)
        assert len(parser_cache) == len(modules) + 1
        for i in modules:
            assert [i in k for k in parser_cache.keys() if k is not None]

    temp_cache, utils.parser_cache = utils.parser_cache, {}
    parser_cache = utils.parser_cache

    api.preload_module('sys')
    check_loaded()  # compiled (c_builtin) modules shouldn't be in the cache.
    api.preload_module('json', 'token')
    check_loaded('json', 'token')

    utils.parser_cache = temp_cache
Exemplo n.º 2
0
def test_preload_modules():
    def check_loaded(*modules):
        # +1 for None module (currently used)
        assert len(parser_cache) == len(modules) + 1
        for i in modules:
            assert [i in k for k in parser_cache.keys() if k is not None]

    temp_cache, utils.parser_cache = utils.parser_cache, {}
    parser_cache = utils.parser_cache

    api.preload_module('sys')
    check_loaded()  # compiled (c_builtin) modules shouldn't be in the cache.
    api.preload_module('json', 'token')
    check_loaded('json', 'token')

    utils.parser_cache = temp_cache
Exemplo n.º 3
0
def test_preload_modules():
    def check_loaded(*modules):
        # +1 for None module (currently used)
        grammar_cache = next(iter(cache.parser_cache.values()))
        assert len(grammar_cache) == len(modules) + 1
        for i in modules:
            assert [i in k for k in grammar_cache.keys() if k is not None]

    old_cache = cache.parser_cache.copy()
    cache.parser_cache.clear()

    try:
        api.preload_module('sys')
        check_loaded()  # compiled (c_builtin) modules shouldn't be in the cache.
        api.preload_module('types', 'token')
        check_loaded('types', 'token')
    finally:
        cache.parser_cache.update(old_cache)
Exemplo n.º 4
0
def test_preload_modules():
    def check_loaded(*modules):
        # +1 for None module (currently used)
        grammar_cache = next(iter(cache.parser_cache.values()))
        assert len(grammar_cache) == len(modules) + 1
        for i in modules:
            assert [i in k for k in grammar_cache.keys() if k is not None]

    old_cache = cache.parser_cache.copy()
    cache.parser_cache.clear()

    try:
        api.preload_module('sys')
        check_loaded()  # compiled (c_builtin) modules shouldn't be in the cache.
        api.preload_module('types', 'token')
        check_loaded('types', 'token')
    finally:
        cache.parser_cache.update(old_cache)
Exemplo n.º 5
0
def test_preload_modules():
    def check_loaded(*modules):
        # + 1 for builtin, +1 for None module (currently used)
        assert len(new) == len(modules) + 2
        for i in modules + ('__builtin__', ):
            assert [i in k for k in new.keys() if k is not None]

    from jedi import cache
    temp_cache, cache.parser_cache = cache.parser_cache, {}
    new = cache.parser_cache
    with common.ignored(KeyError):  # performance of tests -> no reload
        new['__builtin__'] = temp_cache['__builtin__']

    api.preload_module('datetime')
    check_loaded('datetime')
    api.preload_module('json', 'token')
    check_loaded('datetime', 'json', 'token')

    cache.parser_cache = temp_cache
Exemplo n.º 6
0
def test_preload_modules():
    def check_loaded(*modules):
        # + 1 for builtin, +1 for None module (currently used)
        assert len(new) == len(modules) + 2
        for i in modules + ('__builtin__',):
            assert [i in k for k in new.keys() if k is not None]

    from jedi import cache
    temp_cache, cache.parser_cache = cache.parser_cache, {}
    new = cache.parser_cache
    with common.ignored(KeyError): # performance of tests -> no reload
        new['__builtin__'] = temp_cache['__builtin__']

    api.preload_module('datetime')
    check_loaded('datetime')
    api.preload_module('json', 'token')
    check_loaded('datetime', 'json', 'token')

    cache.parser_cache = temp_cache