Python os.get_exec_path() Examples
The following are 6
code examples of os.get_exec_path().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
os
, or try the search function
.
Example #1
Source File: test_os.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_get_exec_path(self): defpath_list = os.defpath.split(os.pathsep) test_path = ['/monty', '/python', '', '/flying/circus'] test_env = {'PATH': os.pathsep.join(test_path)} saved_environ = os.environ try: os.environ = dict(test_env) # Test that defaulting to os.environ works. self.assertSequenceEqual(test_path, os.get_exec_path()) self.assertSequenceEqual(test_path, os.get_exec_path(env=None)) finally: os.environ = saved_environ # No PATH environment variable self.assertSequenceEqual(defpath_list, os.get_exec_path({})) # Empty PATH environment variable self.assertSequenceEqual(('',), os.get_exec_path({'PATH':''})) # Supplied PATH environment variable self.assertSequenceEqual(test_path, os.get_exec_path(test_env)) if os.supports_bytes_environ: # env cannot contain 'PATH' and b'PATH' keys try: # ignore BytesWarning warning with warnings.catch_warnings(record=True): mixed_env = {'PATH': '1', b'PATH': b'2'} except BytesWarning: # mixed_env cannot be created with python -bb pass else: self.assertRaises(ValueError, os.get_exec_path, mixed_env) # bytes key and/or value self.assertSequenceEqual(os.get_exec_path({b'PATH': b'abc'}), ['abc']) self.assertSequenceEqual(os.get_exec_path({b'PATH': 'abc'}), ['abc']) self.assertSequenceEqual(os.get_exec_path({'PATH': b'abc'}), ['abc'])
Example #2
Source File: test_os.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_get_exec_path(self): defpath_list = os.defpath.split(os.pathsep) test_path = ['/monty', '/python', '', '/flying/circus'] test_env = {'PATH': os.pathsep.join(test_path)} saved_environ = os.environ try: os.environ = dict(test_env) # Test that defaulting to os.environ works. self.assertSequenceEqual(test_path, os.get_exec_path()) self.assertSequenceEqual(test_path, os.get_exec_path(env=None)) finally: os.environ = saved_environ # No PATH environment variable self.assertSequenceEqual(defpath_list, os.get_exec_path({})) # Empty PATH environment variable self.assertSequenceEqual(('',), os.get_exec_path({'PATH':''})) # Supplied PATH environment variable self.assertSequenceEqual(test_path, os.get_exec_path(test_env)) if os.supports_bytes_environ: # env cannot contain 'PATH' and b'PATH' keys try: # ignore BytesWarning warning with warnings.catch_warnings(record=True): mixed_env = {'PATH': '1', b'PATH': b'2'} except BytesWarning: # mixed_env cannot be created with python -bb pass else: self.assertRaises(ValueError, os.get_exec_path, mixed_env) # bytes key and/or value self.assertSequenceEqual(os.get_exec_path({b'PATH': b'abc'}), ['abc']) self.assertSequenceEqual(os.get_exec_path({b'PATH': 'abc'}), ['abc']) self.assertSequenceEqual(os.get_exec_path({'PATH': b'abc'}), ['abc'])
Example #3
Source File: test_os.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_get_exec_path(self): defpath_list = os.defpath.split(os.pathsep) test_path = ['/monty', '/python', '', '/flying/circus'] test_env = {'PATH': os.pathsep.join(test_path)} saved_environ = os.environ try: os.environ = dict(test_env) # Test that defaulting to os.environ works. self.assertSequenceEqual(test_path, os.get_exec_path()) self.assertSequenceEqual(test_path, os.get_exec_path(env=None)) finally: os.environ = saved_environ # No PATH environment variable self.assertSequenceEqual(defpath_list, os.get_exec_path({})) # Empty PATH environment variable self.assertSequenceEqual(('',), os.get_exec_path({'PATH':''})) # Supplied PATH environment variable self.assertSequenceEqual(test_path, os.get_exec_path(test_env)) if os.supports_bytes_environ: # env cannot contain 'PATH' and b'PATH' keys try: # ignore BytesWarning warning with warnings.catch_warnings(record=True): mixed_env = {'PATH': '1', b'PATH': b'2'} except BytesWarning: # mixed_env cannot be created with python -bb pass else: self.assertRaises(ValueError, os.get_exec_path, mixed_env) # bytes key and/or value self.assertSequenceEqual(os.get_exec_path({b'PATH': b'abc'}), ['abc']) self.assertSequenceEqual(os.get_exec_path({b'PATH': 'abc'}), ['abc']) self.assertSequenceEqual(os.get_exec_path({'PATH': b'abc'}), ['abc'])
Example #4
Source File: test_os.py From Fluid-Designer with GNU General Public License v3.0 | 4 votes |
def _test_internal_execvpe(self, test_type): program_path = os.sep + 'absolutepath' if test_type is bytes: program = b'executable' fullpath = os.path.join(os.fsencode(program_path), program) native_fullpath = fullpath arguments = [b'progname', 'arg1', 'arg2'] else: program = 'executable' arguments = ['progname', 'arg1', 'arg2'] fullpath = os.path.join(program_path, program) if os.name != "nt": native_fullpath = os.fsencode(fullpath) else: native_fullpath = fullpath env = {'spam': 'beans'} # test os._execvpe() with an absolute path with _execvpe_mockup() as calls: self.assertRaises(RuntimeError, os._execvpe, fullpath, arguments) self.assertEqual(len(calls), 1) self.assertEqual(calls[0], ('execv', fullpath, (arguments,))) # test os._execvpe() with a relative path: # os.get_exec_path() returns defpath with _execvpe_mockup(defpath=program_path) as calls: self.assertRaises(OSError, os._execvpe, program, arguments, env=env) self.assertEqual(len(calls), 1) self.assertSequenceEqual(calls[0], ('execve', native_fullpath, (arguments, env))) # test os._execvpe() with a relative path: # os.get_exec_path() reads the 'PATH' variable with _execvpe_mockup() as calls: env_path = env.copy() if test_type is bytes: env_path[b'PATH'] = program_path else: env_path['PATH'] = program_path self.assertRaises(OSError, os._execvpe, program, arguments, env=env_path) self.assertEqual(len(calls), 1) self.assertSequenceEqual(calls[0], ('execve', native_fullpath, (arguments, env_path)))
Example #5
Source File: test_os.py From ironpython3 with Apache License 2.0 | 4 votes |
def _test_internal_execvpe(self, test_type): program_path = os.sep + 'absolutepath' if test_type is bytes: program = b'executable' fullpath = os.path.join(os.fsencode(program_path), program) native_fullpath = fullpath arguments = [b'progname', 'arg1', 'arg2'] else: program = 'executable' arguments = ['progname', 'arg1', 'arg2'] fullpath = os.path.join(program_path, program) if os.name != "nt": native_fullpath = os.fsencode(fullpath) else: native_fullpath = fullpath env = {'spam': 'beans'} # test os._execvpe() with an absolute path with _execvpe_mockup() as calls: self.assertRaises(RuntimeError, os._execvpe, fullpath, arguments) self.assertEqual(len(calls), 1) self.assertEqual(calls[0], ('execv', fullpath, (arguments,))) # test os._execvpe() with a relative path: # os.get_exec_path() returns defpath with _execvpe_mockup(defpath=program_path) as calls: self.assertRaises(OSError, os._execvpe, program, arguments, env=env) self.assertEqual(len(calls), 1) self.assertSequenceEqual(calls[0], ('execve', native_fullpath, (arguments, env))) # test os._execvpe() with a relative path: # os.get_exec_path() reads the 'PATH' variable with _execvpe_mockup() as calls: env_path = env.copy() if test_type is bytes: env_path[b'PATH'] = program_path else: env_path['PATH'] = program_path self.assertRaises(OSError, os._execvpe, program, arguments, env=env_path) self.assertEqual(len(calls), 1) self.assertSequenceEqual(calls[0], ('execve', native_fullpath, (arguments, env_path)))
Example #6
Source File: test_os.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 4 votes |
def _test_internal_execvpe(self, test_type): program_path = os.sep + 'absolutepath' if test_type is bytes: program = b'executable' fullpath = os.path.join(os.fsencode(program_path), program) native_fullpath = fullpath arguments = [b'progname', 'arg1', 'arg2'] else: program = 'executable' arguments = ['progname', 'arg1', 'arg2'] fullpath = os.path.join(program_path, program) if os.name != "nt": native_fullpath = os.fsencode(fullpath) else: native_fullpath = fullpath env = {'spam': 'beans'} # test os._execvpe() with an absolute path with _execvpe_mockup() as calls: self.assertRaises(RuntimeError, os._execvpe, fullpath, arguments) self.assertEqual(len(calls), 1) self.assertEqual(calls[0], ('execv', fullpath, (arguments,))) # test os._execvpe() with a relative path: # os.get_exec_path() returns defpath with _execvpe_mockup(defpath=program_path) as calls: self.assertRaises(OSError, os._execvpe, program, arguments, env=env) self.assertEqual(len(calls), 1) self.assertSequenceEqual(calls[0], ('execve', native_fullpath, (arguments, env))) # test os._execvpe() with a relative path: # os.get_exec_path() reads the 'PATH' variable with _execvpe_mockup() as calls: env_path = env.copy() if test_type is bytes: env_path[b'PATH'] = program_path else: env_path['PATH'] = program_path self.assertRaises(OSError, os._execvpe, program, arguments, env=env_path) self.assertEqual(len(calls), 1) self.assertSequenceEqual(calls[0], ('execve', native_fullpath, (arguments, env_path)))