예제 #1
0
파일: test_basic.py 프로젝트: saxix/pip
def test_does_not_find_command_because_there_is_no_path():
    """
    Test calling `pip.utils.find_command` when there is no PATH env variable
    """
    environ_before = os.environ
    os.environ = {}
    try:
        try:
            find_command('anycommand')
        except BadCommand:
            e = sys.exc_info()[1]
            assert e.args == ("Cannot find command 'anycommand'",)
        else:
            raise AssertionError("`find_command` should raise `BadCommand`")
    finally:
        os.environ = environ_before
예제 #2
0
def test_does_not_find_command_because_there_is_no_path():
    """
    Test calling `pip.utils.find_command` when there is no PATH env variable
    """
    environ_before = os.environ
    os.environ = {}
    try:
        try:
            find_command('anycommand')
        except BadCommand:
            e = sys.exc_info()[1]
            assert e.args == ("Cannot find command 'anycommand'",)
        else:
            raise AssertionError("`find_command` should raise `BadCommand`")
    finally:
        os.environ = environ_before
예제 #3
0
 def cmd(self):
     if self._cmd is not None:
         return self._cmd
     command = find_command(self.name)
     logger.info('Found command %r at %r' % (self.name, command))
     self._cmd = command
     return command
예제 #4
0
 def cmd(self):
     if self._cmd is not None:
         return self._cmd
     command = find_command(self.name)
     logger.info('Found command {0!r} at {1!r}'.format(self.name, command))
     self._cmd = command
     return command
예제 #5
0
def test_find_command_trys_supplied_pathext(mock_isfile, getpath_mock):
    """
    If pathext supplied find_command should use all of its list of extensions to find file.
    """
    mock_isfile.return_value = False
    getpath_mock.return_value = ".FOO"

    pathext = os.pathsep.join([".RUN", ".CMD"])

    paths = [os.path.join('path_one', f)  for f in ['foo.run', 'foo.cmd', 'foo']]
    expected = [((p,),) for p in paths]

    with pytest.raises(BadCommand):
        find_command("foo", "path_one", pathext)

    assert mock_isfile.call_args_list == expected, "Actual: %s\nExpected %s" % (mock_isfile.call_args_list, expected)
    assert not getpath_mock.called, "Should not call get_pathext"
예제 #6
0
def test_find_command_trys_all_pathext(mock_isfile, getpath_mock):
    """
    If no pathext should check default list of extensions, if file does not
    exist.
    """
    mock_isfile.return_value = False

    getpath_mock.return_value = os.pathsep.join([".COM", ".EXE"])

    paths = [os.path.join('path_one', f)  for f in ['foo.com', 'foo.exe', 'foo']]
    expected = [((p,),) for p in paths]

    with pytest.raises(BadCommand):
        find_command("foo", "path_one")

    assert mock_isfile.call_args_list == expected, "Actual: %s\nExpected %s" % (mock_isfile.call_args_list, expected)
    assert getpath_mock.called, "Should call get_pathext"
예제 #7
0
 def cmd(self):
     if self._cmd is not None:
         return self._cmd
     command = find_command(self.name)
     if command is None:
         raise BadCommand('Cannot find command %r' % self.name)
     logger.info('Found command %r at %r' % (self.name, command))
     self._cmd = command
     return command
예제 #8
0
 def cmd(self):
     if self._cmd is not None:
         return self._cmd
     command = find_command(self.name)
     if command is None:
         raise BadCommand('Cannot find command %r' % self.name)
     logger.info('Found command %r at %r' % (self.name, command))
     self._cmd = command
     return command
예제 #9
0
파일: test_basic.py 프로젝트: PJMODOS/pip
def test_find_command_folder_in_path():
    """
    If a folder named e.g. 'git' is in PATH, and find_command is looking for
    the 'git' executable, it should not match the folder, but rather keep
    looking.
    """
    env = reset_env()
    mkdir('path_one'); path_one = env.scratch_path/'path_one'
    mkdir(path_one/'foo')
    mkdir('path_two'); path_two = env.scratch_path/'path_two'
    write_file(path_two/'foo', '# nothing')
    found_path = find_command('foo', map(str, [path_one, path_two]))
    assert found_path == path_two/'foo'
예제 #10
0
def test_find_command_folder_in_path(script):
    """
    If a folder named e.g. 'git' is in PATH, and find_command is looking for
    the 'git' executable, it should not match the folder, but rather keep
    looking.
    """
    script.scratch_path.join("path_one").mkdir()
    path_one = script.scratch_path/'path_one'
    path_one.join("foo").mkdir()
    script.scratch_path.join("path_two").mkdir()
    path_two = script.scratch_path/'path_two'
    path_two.join("foo").write("# nothing")
    found_path = find_command('foo', map(str, [path_one, path_two]))
    assert found_path == path_two/'foo'
예제 #11
0
파일: test_basic.py 프로젝트: qiemem/pip
def test_find_command_folder_in_path():
    """
    If a folder named e.g. 'git' is in PATH, and find_command is looking for
    the 'git' executable, it should not match the folder, but rather keep
    looking.
    """
    env = reset_env()
    mkdir('path_one')
    path_one = env.scratch_path / 'path_one'
    mkdir(path_one / 'foo')
    mkdir('path_two')
    path_two = env.scratch_path / 'path_two'
    write_file(path_two / 'foo', '# nothing')
    found_path = find_command('foo', map(str, [path_one, path_two]))
    assert found_path == path_two / 'foo'
예제 #12
0
def test_find_command_folder_in_path():
    """
    If a folder named e.g. 'git' is in PATH, and find_command is looking for
    the 'git' executable, it should not match the folder, but rather keep
    looking.
    """
    env = reset_env()
    mkdir("path_one")
    path_one = env.scratch_path / "path_one"
    mkdir(path_one / "foo")
    mkdir("path_two")
    path_two = env.scratch_path / "path_two"
    write_file(path_two / "foo", "# nothing")
    found_path = find_command("foo", map(str, [path_one, path_two]))
    assert found_path == path_two / "foo"
예제 #13
0
파일: test_basic.py 프로젝트: qiemem/pip
def test_find_command_trys_supplied_pathext(mock_isfile, getpath_mock):
    """
    If pathext supplied find_command should use all of its list of extensions to find file.
    """
    mock_isfile.return_value = False
    # Patching os.pathsep failed on type checking
    old_sep = os.pathsep
    os.pathsep = ':'
    getpath_mock.return_value = ".FOO"

    pathext = os.pathsep.join([".RUN", ".CMD"])
    found_path = find_command('foo', 'path_one', pathext)

    paths = [ os.path.join('path_one', f)  for f in ['foo.run', 'foo.cmd', 'foo'] ]
    expected = [ ((p,),) for p in paths ]
    assert found_path is None, "Should not find path"
    assert mock_isfile.call_args_list == expected, "Actual: %s\nExpected %s" % (mock_isfile.call_args_list, expected)
    assert not getpath_mock.called, "Should not call get_pathext"

    os.pathsep = old_sep
예제 #14
0
파일: test_basic.py 프로젝트: qiemem/pip
def test_find_command_trys_all_pathext(mock_isfile, getpath_mock):
    """
    If no pathext should check default list of extensions, if file does not
    exist.
    """
    mock_isfile.return_value = False
    # Patching os.pathsep failed on type checking
    old_sep = os.pathsep
    os.pathsep = ':'

    getpath_mock.return_value = os.pathsep.join([".COM", ".EXE"])

    found_path = find_command('foo', 'path_one')

    paths = [ os.path.join('path_one', f)  for f in ['foo.com', 'foo.exe', 'foo'] ]
    expected = [ ((p,),) for p in paths ]
    assert found_path is None, "Should not find path"
    assert mock_isfile.call_args_list == expected, "Actual: %s\nExpected %s" % (mock_isfile.call_args_list, expected)
    assert getpath_mock.called, "Should call get_pathext"

    os.pathsep = old_sep
예제 #15
0
파일: test_basic.py 프로젝트: qiemem/pip
def test_find_command_trys_supplied_pathext(mock_isfile, getpath_mock):
    """
    If pathext supplied find_command should use all of its list of extensions to find file.
    """
    mock_isfile.return_value = False
    # Patching os.pathsep failed on type checking
    old_sep = os.pathsep
    os.pathsep = ':'
    getpath_mock.return_value = ".FOO"

    pathext = os.pathsep.join([".RUN", ".CMD"])
    found_path = find_command('foo', 'path_one', pathext)

    paths = [
        os.path.join('path_one', f) for f in ['foo.run', 'foo.cmd', 'foo']
    ]
    expected = [((p, ), ) for p in paths]
    assert found_path is None, "Should not find path"
    assert mock_isfile.call_args_list == expected, "Actual: %s\nExpected %s" % (
        mock_isfile.call_args_list, expected)
    assert not getpath_mock.called, "Should not call get_pathext"

    os.pathsep = old_sep
예제 #16
0
파일: test_basic.py 프로젝트: qiemem/pip
def test_find_command_trys_all_pathext(mock_isfile, getpath_mock):
    """
    If no pathext should check default list of extensions, if file does not
    exist.
    """
    mock_isfile.return_value = False
    # Patching os.pathsep failed on type checking
    old_sep = os.pathsep
    os.pathsep = ':'

    getpath_mock.return_value = os.pathsep.join([".COM", ".EXE"])

    found_path = find_command('foo', 'path_one')

    paths = [
        os.path.join('path_one', f) for f in ['foo.com', 'foo.exe', 'foo']
    ]
    expected = [((p, ), ) for p in paths]
    assert found_path is None, "Should not find path"
    assert mock_isfile.call_args_list == expected, "Actual: %s\nExpected %s" % (
        mock_isfile.call_args_list, expected)
    assert getpath_mock.called, "Should call get_pathext"

    os.pathsep = old_sep