Ejemplo n.º 1
0
def build_facade(source, line, column):
    env = environment.get_default_environment()
    return facade.JediFacade(env,
                             'complete',
                             source,
                             line,
                             column,
                             sys_path=env.get_sys_path)
Ejemplo n.º 2
0
def test_get_default_environment_when_embedded(monkeypatch, virtualenv):
    # When using Python embedded, sometimes the executable is not a Python
    # executable.
    executable_name = 'RANDOM_EXE'
    monkeypatch.setattr(sys, 'executable', executable_name)
    monkeypatch.setenv('VIRTUAL_ENV', virtualenv)
    env = get_default_environment()
    assert env.executable != executable_name
Ejemplo n.º 3
0
def environment(request):
    version = request.config.option.env
    if version is None:
        version = os.environ.get('JEDI_TEST_ENVIRONMENT', str(py_version))

    if int(version) == py_version:
        return get_default_environment()

    return get_python_environment('python%s.%s' % tuple(version))
Ejemplo n.º 4
0
def build_facade(source, line, column):
    env = environment.get_default_environment()
    return facade.JediFacade(
        env,
        'complete',
        source,
        line,
        column,
        sys_path=env.get_sys_path)
Ejemplo n.º 5
0
def environment(request):
    version = request.config.option.env
    if version is None:
        version = os.environ.get('JEDI_TEST_ENVIRONMENT', str(py_version))

    if int(version) == py_version:
        return get_default_environment()

    return get_system_environment(version[0] + '.' + version[1:])
Ejemplo n.º 6
0
def environment(request):
    version = request.config.option.env
    if version is None:
        version = os.environ.get('JEDI_TEST_ENVIRONMENT', str(py_version))

    if int(version) == py_version:
        return get_default_environment()

    return get_system_environment(version[0] + '.' + version[1:])
Ejemplo n.º 7
0
    def test_should_return_function_parameters_also(self):
        env = environment.get_default_environment()
        f = facade.JediFacade(
            env,
            'complete',
            COMPLETION_TEST,
            3, 6,
            sys_path=env.get_sys_path)

        completions = f.get_autocomplete()
        assert completions

        self.assertIn(('var1\tparam', 'var1'), completions)
        self.assertIn(('var2\tparam', 'var2'), completions)
Ejemplo n.º 8
0
    def test_should_return_function_parameters_also(self):
        env = environment.get_default_environment()
        f = facade.JediFacade(env,
                              'complete',
                              COMPLETION_TEST,
                              3,
                              6,
                              sys_path=env.get_sys_path)

        completions = f.get_autocomplete()
        assert completions

        self.assertIn(('var1\tparam', 'var1'), completions)
        self.assertIn(('var2\tparam', 'var2'), completions)
Ejemplo n.º 9
0
def test_get_default_environment_from_env_does_not_use_safe(tmpdir, monkeypatch):
    fake_python = os.path.join(str(tmpdir), 'fake_python')
    with open(fake_python, 'w') as f:
        f.write('')

    def _get_subprocess(self):
        if self._start_executable != fake_python:
            raise RuntimeError('Should not get called!')
        self.executable = fake_python
        self.path = 'fake'

    monkeypatch.setattr('jedi.api.environment.Environment._get_subprocess',
                        _get_subprocess)

    monkeypatch.setenv('VIRTUAL_ENV', fake_python)
    env = get_default_environment()
    assert env.path == 'fake'
Ejemplo n.º 10
0
def test_get_default_environment_from_env_does_not_use_safe(tmpdir, monkeypatch):
    fake_python = os.path.join(str(tmpdir), 'fake_python')
    with open(fake_python, 'w') as f:
        f.write('')

    def _get_subprocess(self):
        if self._start_executable != fake_python:
            raise RuntimeError('Should not get called!')
        self.executable = fake_python
        self.path = 'fake'

    monkeypatch.setattr('jedi.api.environment.Environment._get_subprocess',
                        _get_subprocess)

    monkeypatch.setenv('VIRTUAL_ENV', fake_python)
    env = get_default_environment()
    assert env.path == 'fake'
Ejemplo n.º 11
0
def test_not_existing_virtualenv():
    """Should not match the path that was given"""
    path = '/foo/bar/jedi_baz'
    with set_environment_variable('VIRTUAL_ENV', path):
        assert get_default_environment().executable != path
Ejemplo n.º 12
0
            current = os.path.basename(current)
        print('{:25} {} tests and {} fails.'.format(current, tests, fails))

    def report(case, actual, desired):
        if actual == desired:
            return 0
        else:
            print("\ttest fail @%d, actual = %s, desired = %s"
                  % (case.line_nr - 1, actual, desired))
            return 1

    if arguments['--env']:
        environment = get_system_environment(arguments['--env'])
    else:
        # Will be 3.6.
        environment = get_default_environment()

    import traceback
    current = cases[0].path if cases else None
    count = fails = 0
    for c in cases:
        if c.get_skip_reason(environment):
            continue
        if current != c.path:
            file_change(current, count, fails)
            current = c.path
            count = fails = 0

        try:
            if c.run(report, environment):
                tests_fail += 1
Ejemplo n.º 13
0
            current = os.path.basename(current)
        print('%s \t\t %s tests and %s fails.' % (current, tests, fails))

    def report(case, actual, desired):
        if actual == desired:
            return 0
        else:
            print("\ttest fail @%d, actual = %s, desired = %s"
                  % (case.line_nr - 1, actual, desired))
            return 1

    if arguments['--env']:
        environment = get_system_environment(arguments['--env'])
    else:
        # Will be 3.6.
        environment = get_default_environment()

    import traceback
    current = cases[0].path if cases else None
    count = fails = 0
    for c in cases:
        if c.get_skip_reason(environment):
            continue
        if current != c.path:
            file_change(current, count, fails)
            current = c.path
            count = fails = 0

        try:
            if c.run(report, environment):
                tests_fail += 1
Ejemplo n.º 14
0
    def get_environment(self):
        if self._environment is None:
            return get_default_environment()

        return self._environment
Ejemplo n.º 15
0
def test_working_venv(venv_path, monkeypatch):
    monkeypatch.setenv('VIRTUAL_ENV', venv_path)
    assert get_default_environment().path == venv_path
Ejemplo n.º 16
0
def test_not_existing_virtualenv(monkeypatch):
    """Should not match the path that was given"""
    path = '/foo/bar/jedi_baz'
    monkeypatch.setenv('VIRTUAL_ENV', path)
    assert get_default_environment().executable != path
Ejemplo n.º 17
0
def test_virtualenv():
    with set_environment_variable('VIRTUAL_ENV', '/foo/bar/jedi_baz'):
        assert get_default_environment()._executable == sys.executable
Ejemplo n.º 18
0
def test_working_venv(venv_path, monkeypatch):
    monkeypatch.setenv('VIRTUAL_ENV', venv_path)
    assert get_default_environment().path == venv_path
Ejemplo n.º 19
0
def test_working_venv(venv_path):
    with set_environment_variable('VIRTUAL_ENV', venv_path):
        assert get_default_environment().path == venv_path
Ejemplo n.º 20
0
def test_sys_path():
    assert get_default_environment().get_sys_path()
Ejemplo n.º 21
0
def test_not_existing_virtualenv(monkeypatch):
    """Should not match the path that was given"""
    path = '/foo/bar/jedi_baz'
    monkeypatch.setenv('VIRTUAL_ENV', path)
    assert get_default_environment().executable != path