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
def cmd(self): if self._cmd is not None: return self._cmd command = find_command(self.name) logger.debug('Found command %r at %r', self.name, command) self._cmd = command return command
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
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"
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"
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"
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"
def test_find_command_folder_in_path(tmpdir): """ 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. """ tmpdir.join("path_one").mkdir() path_one = tmpdir / 'path_one' path_one.join("foo").mkdir() tmpdir.join("path_two").mkdir() path_two = tmpdir / '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'
def _is_local_repository(self, repo): """ posix absolute paths start with os.path.sep, win32 ones ones start with drive (like c:\\folder) """ drive, tail = os.path.splitdrive(repo) return repo.startswith(os.path.sep) or drive <<<<<<< HEAD ======= @property def cmd(self): if self._cmd is not None: return self._cmd command = find_command(self.name) logger.debug('Found command %r at %r', self.name, command) self._cmd = command return command >>>>>>> bde4533e29dfedadf6bcf9d451baa615bc828a59 # See issue #1083 for why this method was introduced: # https://github.com/pypa/pip/issues/1083 def translate_egg_surname(self, surname): # For example, Django has branches of the form "stable/1.7.x". return surname.replace('/', '_') def export(self, location): """ Export the repository at the url to the destination location i.e. only download the files, without vcs informations