Example #1
0
def test_virtualenv_executable_not_found(monkeypatch):
    def exists(path):
        return path not in [
            '/Users/fots/.virtualenvs/myenv/bin/pip',
            '/Users/fots/.virtualenvs/myenv/bin/pip3',
            '/Users/fots/.virtualenvs/myenv/bin/pip2'
        ]

    monkeypatch.setattr('os.path.exists', exists)
    monkeypatch.setattr(
        Pip, 'run',
        build_run(fixture_subpath='pip',
                  command_mappings=[
                      CommandMapping(
                          command=[
                              '/Users/fots/.virtualenvs/myenv/bin/pip', 'list',
                              '--format', 'json'
                          ],
                          stdout_filename='pip_list_installed.stdout')
                  ]))

    pip = Pip(name='pycodestyle',
              state='present',
              virtualenv='/Users/fots/.virtualenvs/myenv')
    with pytest.raises(ActionError):
        pip.process()
Example #2
0
def test_absent_not_installed(monkeypatch):
    monkeypatch.setattr(
        Pip, 'run',
        build_run(fixture_subpath='pip',
                  command_mappings=[
                      CommandMapping(
                          command=['pip', 'list', '--format', 'json'],
                          stdout_filename='pip_list_not_installed.stdout')
                  ]))

    pip = Pip(name='pycodestyle', state='absent', executable='pip')
    assert pip.process() == ActionResponse(changed=False)
Example #3
0
def test_list_output_invalid(monkeypatch):
    monkeypatch.setattr(
        Pip, 'run',
        build_run(fixture_subpath='pip',
                  command_mappings=[
                      CommandMapping(
                          command=['pip', 'list', '--format', 'json'],
                          stdout_filename='pip_list_invalid_output.stdout')
                  ]))

    pip = Pip(name='pycodestyle', state='present', executable='pip')
    with pytest.raises(ActionError):
        pip.process()
Example #4
0
def test_find_executable_not_found(monkeypatch):
    monkeypatch.setattr('shutil.which', lambda cmd: None)
    monkeypatch.setattr(
        Pip, 'run',
        build_run(fixture_subpath='pip',
                  command_mappings=[
                      CommandMapping(
                          command=[
                              '/opt/python/bin/pip', 'list', '--format', 'json'
                          ],
                          stdout_filename='pip_list_installed.stdout')
                  ]))

    pip = Pip(name='pycodestyle', state='present')
    with pytest.raises(ActionError):
        pip.process()
Example #5
0
def test_present_with_version_not_installed(monkeypatch):
    monkeypatch.setattr(
        Pip, 'run',
        build_run(fixture_subpath='pip',
                  command_mappings=[
                      CommandMapping(
                          command=['pip', 'list', '--format', 'json'],
                          stdout_filename='pip_list_not_installed.stdout'),
                      CommandMapping(
                          command=['pip', 'install', 'pycodestyle==2.4.0'])
                  ]))

    pip = Pip(name='pycodestyle',
              version='2.4.0',
              state='present',
              executable='pip')
    assert pip.process() == ActionResponse(changed=True)
Example #6
0
def test_find_executable_found(monkeypatch):
    monkeypatch.setattr(
        'shutil.which', lambda cmd: '/opt/python/bin/pip'
        if cmd == 'pip' else None)
    monkeypatch.setattr(
        Pip, 'run',
        build_run(fixture_subpath='pip',
                  command_mappings=[
                      CommandMapping(
                          command=[
                              '/opt/python/bin/pip', 'list', '--format', 'json'
                          ],
                          stdout_filename='pip_list_installed.stdout')
                  ]))

    pip = Pip(name='pycodestyle', state='present')
    assert pip.process() == ActionResponse(changed=False)
Example #7
0
def test_latest_installed_but_outdated(monkeypatch):
    monkeypatch.setattr(
        Pip, 'run',
        build_run(
            fixture_subpath='pip',
            command_mappings=[
                CommandMapping(
                    command=['pip', 'list', '--format', 'json'],
                    stdout_filename='pip_list_installed_but_outdated.stdout'),
                CommandMapping(
                    command=['pip', 'list', '--format', 'json', '--outdated'],
                    stdout_filename=
                    'pip_list_outdated_installed_but_outdated.stdout'),
                CommandMapping(
                    command=['pip', 'install', '--upgrade', 'pycodestyle'])
            ]))

    pip = Pip(name='pycodestyle', state='latest', executable='pip')
    assert pip.process() == ActionResponse(changed=True)
Example #8
0
def test_virtualenv_executable_found(monkeypatch):
    monkeypatch.setattr(
        'os.path.exists',
        lambda path: path == '/Users/fots/.virtualenvs/myenv/bin/pip3')
    monkeypatch.setattr(
        Pip, 'run',
        build_run(
            fixture_subpath='pip',
            command_mappings=[
                CommandMapping(command=[
                    '/Users/fots/.virtualenvs/myenv/bin/pip3', 'list',
                    '--format', 'json'
                ],
                               stdout_filename='pip_list_installed.stdout')
            ]))

    pip = Pip(name='pycodestyle',
              state='present',
              virtualenv='/Users/fots/.virtualenvs/myenv')
    assert pip.process() == ActionResponse(changed=False)
Example #9
0
def test_argument_state_invalid():
    with pytest.raises(ValueError):
        Pip(name='pycodestyle', state='hmmm')
Example #10
0
def test_argument_executable_after_init_invalid():
    pip = Pip(name='pycodestyle', virtualenv='/Users/fots/.virtualenvs/myenv')
    with pytest.raises(ValueError):
        pip.executable = 'pip3.6'
Example #11
0
def test_argument_virtualenv_executable_combination_invalid():
    with pytest.raises(ValueError):
        Pip(name='pycodestyle',
            executable='pip3.6',
            virtualenv='/Users/fots/.virtualenvs/myenv')
Example #12
0
def test_argument_state_after_init_invalid():
    pip = Pip(name='pycodestyle', version='2.3.1')
    with pytest.raises(ValueError):
        pip.state = 'latest'
Example #13
0
def test_argument_version_state_combination_invalid():
    with pytest.raises(ValueError):
        Pip(name='pycodestyle', state='latest', version='2.3.1')