def test_path_ext(self): class MockInfo: has_path_ext = True env = {'PATH': '/usr/bin', 'PATHEXT': '.exe'} with mock.patch('bfg9000.shell.platform_info', MockInfo), \ mock.patch('os.path.exists', side_effect=[False, True]): self.assertEqual(which('python', env=env), ['python']) with mock.patch('bfg9000.shell.platform_info', MockInfo), \ mock.patch('os.path.exists', side_effect=[False, True]): self.assertEqual(which('python', env=env, resolve=True), [os.path.normpath('/usr/bin/python.exe')]) with mock.patch('bfg9000.shell.platform_info', MockInfo), \ mock.patch('os.path.exists', side_effect=[False, True]): self.assertEqual( which([['python', '--foo']], env=env, resolve=True), [os.path.normpath('/usr/bin/python.exe'), '--foo'])
def test_resolve(self): with mock.patch('os.path.exists', side_effect=[False, True]): self.assertEqual(which('python', env=self.env, resolve=True), [os.path.normpath('/usr/local/bin/python')])
def test_multiple_args(self): with mock.patch('os.path.exists', side_effect=[False, False, True]): self.assertEqual(which(['python', ['python3', '--foo']], env=self.env), ['python3', '--foo'])
def test_abs(self): with mock.patch('os.path.exists', return_value=True): self.assertEqual(which('/path/to/python', env=self.env), ['/path/to/python'])
def test_simple(self): with mock.patch('os.path.exists', return_value=True): self.assertEqual(which('python', env=self.env), ['python'])
def test_multiword(self): with mock.patch('os.path.exists', return_value=True): self.assertEqual(which('python --foo', env=self.env), ['python', '--foo'])