def match_filter_xcode(actual, expected): if actual: if not TestCmd.is_List(actual): actual = actual.split('\n') if not TestCmd.is_List(expected): expected = expected.split('\n') actual = [a for a in actual if 'No recorder, buildTask: <Xcode3BuildTask:' not in a] return match(actual, expected)
def match(a, b): if a == b: return True if not TestCmd.is_List(a): a = a.split('\n') if not TestCmd.is_List(b): b = b.split('\n') if expected_error in '\n'.join(a) + '\n'.join(b): saw_expected_error[0] = True return True return False
def match_filter_xcode(actual, expected): if actual: if not TestCmd.is_List(actual): actual = actual.split('\n') if not TestCmd.is_List(expected): expected = expected.split('\n') actual = [a for a in actual if 'No recorder, buildTask: <Xcode3BuildTask:' not in a and 'Beginning test session' not in a and 'Writing diagnostic log' not in a and 'Logs/Test/' not in a] return match(actual, expected)
def test_validator(self): """Test the PackageVariable validator""" opts = SCons.Variables.Variables() opts.Add(SCons.Variables.PackageVariable('test', 'test option help', '/default/path')) test = TestCmd.TestCmd(workdir='') test.write('exists', 'exists\n') o = opts.options[0] env = {'F':False, 'T':True, 'X':'x'} exists = test.workpath('exists') does_not_exist = test.workpath('does_not_exist') o.validator('F', '/path', env) o.validator('T', '/path', env) o.validator('X', exists, env) caught = None try: o.validator('X', does_not_exist, env) except SCons.Errors.UserError: caught = 1 assert caught, "did not catch expected UserError"
def fail_test(self, condition, dump_stdio=True, *args): if not condition: return if hasattr(self, 'difference'): f = StringIO.StringIO() self.difference.pprint(f) annotation("changes caused by the last build command", f.getvalue()) if dump_stdio: self.dump_stdio() if '--preserve' in sys.argv: print print "*** Copying the state of working dir into 'failed_test' ***" print path = os.path.join(self.original_workdir, "failed_test") if os.path.isdir(path): shutil.rmtree(path, ignore_errors=False) elif os.path.exists(path): raise "Path " + path + " already exists and is not a directory"; shutil.copytree(self.workdir, path) at = TestCmd.caller(traceback.extract_stack(), 0) annotation("stacktrace", at) sys.exit(1)
def match_custom(lines, expect): if expect != expect_stdout: # stderr if lines == expect: return 1 return None # taken directly from TestCmd if not TestCmd.is_List(lines): # CRs mess up matching (Windows) so split carefully lines = re.split('\r?\n', lines) # record number of matches for each regex n_actual = [0] * len(expected_patterns) for line in lines: for i, regex in enumerate(expected_patterns): if regex.search(line): n_actual[i] += 1 break # compare actual counts to expected counts for n_expect in expected_counts: if n_actual == n_expect: return 1 return None
def test_PathIsDirCreate(self): """Test the PathIsDirCreate validator""" opts = SCons.Variables.Variables() opts.Add( SCons.Variables.PathVariable( 'test', 'test option help', '/default/path', SCons.Variables.PathVariable.PathIsDirCreate)) test = TestCmd.TestCmd(workdir='') test.write('file', "file\n") o = opts.options[0] d = test.workpath('dir') o.validator('X', d, {}) assert os.path.isdir(d) f = test.workpath('file') try: o.validator('X', f, {}) except SCons.Errors.UserError as e: assert str( e) == 'Path for option X is a file, not a directory: %s' % f, e except: raise Exception("did not catch expected UserError")
def end_scons_output(self): o = self.o e = o.e t = TestCmd.TestCmd(workdir='', combine=1) t.subdir('ROOT', 'WORK') for d in e.dirs: dir = t.workpath('WORK', d.name) if not os.path.exists(dir): os.makedirs(dir) for f in e.files: i = 0 while f.data[i] == '\n': i = i + 1 lines = string.split(f.data[i:], '\n') i = 0 while lines[0][i] == ' ': i = i + 1 lines = map(lambda l, i=i: l[i:], lines) path = string.replace(f.name, '__ROOT__', t.workpath('ROOT')) dir, name = os.path.split(f.name) if dir: dir = t.workpath('WORK', dir) if not os.path.exists(dir): os.makedirs(dir) content = string.join(lines, '\n') content = string.replace(content, '__ROOT__', t.workpath('ROOT')) t.write(t.workpath('WORK', f.name), content) i = len(o.prefix) while o.prefix[i - 1] != '\n': i = i - 1 sys.stdout.write('<literallayout>' + o.prefix[:i]) p = o.prefix[i:] for c in o.commandlist: sys.stdout.write(p + Prompt[o.os]) d = string.replace(c.data, '__ROOT__', '') sys.stdout.write('<userinput>' + d + '</userinput>\n') e = string.replace(c.data, '__ROOT__', t.workpath('ROOT')) args = string.split(e)[1:] os.environ['SCONS_LIB_DIR'] = scons_lib_dir t.run(interpreter=sys.executable, program=scons_py, arguments='-f - ' + string.join(args), chdir=t.workpath('WORK'), stdin=Stdin % o.os) out = string.replace(t.stdout(), t.workpath('ROOT'), '') if out: lines = string.split(out, '\n') if lines: while lines[-1] == '': lines = lines[:-1] for l in lines: sys.stdout.write(p + l + '\n') #err = t.stderr() #if err: # sys.stderr.write(err) if o.data[0] == '\n': o.data = o.data[1:] sys.stdout.write(o.data + '</literallayout>') delattr(self, 'o') self.afunclist = self.afunclist[:-1]
def test_PathIsDir(self): """Test the PathIsDir validator""" opts = SCons.Variables.Variables() opts.Add( SCons.Variables.PathVariable( 'test', 'test option help', '/default/path', SCons.Variables.PathVariable.PathIsDir)) test = TestCmd.TestCmd(workdir='') test.subdir('dir') test.write('file', "file\n") o = opts.options[0] o.validator('X', test.workpath('dir'), {}) f = test.workpath('file') try: o.validator('X', f, {}) except SCons.Errors.UserError as e: assert str(e) == 'Directory path for option X is a file: %s' % f, e except: raise Exception("did not catch expected UserError") dne = test.workpath('does_not_exist') try: o.validator('X', dne, {}) except SCons.Errors.UserError as e: assert str( e) == 'Directory path for option X does not exist: %s' % dne, e except: raise Exception("did not catch expected UserError")
def test_mkdir_func0(self): test = TestCmd.TestCmd(workdir = '') test.subdir('sub') subdir2 = test.workpath('sub', 'dir1', 'dir2') # Simple smoke test mkdir_func(subdir2) mkdir_func(subdir2) # 2nd time should be OK too
def test_mkdir_func1(self): test = TestCmd.TestCmd(workdir = '') test.subdir('sub') subdir1 = test.workpath('sub', 'dir1') subdir2 = test.workpath('sub', 'dir1', 'dir2') # No error if asked to create existing dir os.makedirs(subdir2) mkdir_func(subdir2) mkdir_func(subdir1)
def setUp(self): debug("THIS TYPE :%s"%self) global registry registry = self.registry from SCons.Tool.MSCommon.vs import reset_installed_visual_studios reset_installed_visual_studios() self.test = TestCmd.TestCmd(workdir='') # FS doesn't like the cwd to be something other than its root. os.chdir(self.test.workpath("")) self.fs = SCons.Node.FS.FS()
def test_mkdir_func2(self): test = TestCmd.TestCmd(workdir = '') test.subdir('sub') subdir1 = test.workpath('sub', 'dir1') subdir2 = test.workpath('sub', 'dir1', 'dir2') file = test.workpath('sub', 'dir1', 'dir2', 'file') # make sure it does error if asked to create a dir # where there's already a file os.makedirs(subdir2) test.write(file, "test\n") try: mkdir_func(file) except os.error, e: pass
def test_validator(self): """Test the PathOption validator argument""" opts = SCons.Options.Options() opts.Add(SCons.Options.PathOption('test', 'test option help', '/default/path')) test = TestCmd.TestCmd(workdir='') test.write('exists', 'exists\n') o = opts.options[0] o.validator('X', test.workpath('exists'), {}) dne = test.workpath('does_not_exist') try: o.validator('X', dne, {}) except SCons.Errors.UserError, e: expect = 'Path for option X does not exist: %s' % dne assert str(e) == expect, e
def test_PathExists(self): """Test the PathExists validator""" opts = SCons.Variables.Variables() opts.Add( SCons.Variables.PathVariable( 'test', 'test option help', '/default/path', SCons.Variables.PathVariable.PathExists)) test = TestCmd.TestCmd(workdir='') test.write('exists', 'exists\n') o = opts.options[0] o.validator('X', test.workpath('exists'), {}) dne = test.workpath('does_not_exist') try: o.validator('X', dne, {}) except SCons.Errors.UserError, e: assert str(e) == 'Path for option X does not exist: %s' % dne, e
def test_validator(self): """Test the PathVariable validator argument""" opts = SCons.Variables.Variables() opts.Add( SCons.Variables.PathVariable('test', 'test option help', '/default/path')) test = TestCmd.TestCmd(workdir='') test.write('exists', 'exists\n') o = opts.options[0] o.validator('X', test.workpath('exists'), {}) dne = test.workpath('does_not_exist') try: o.validator('X', dne, {}) except SCons.Errors.UserError as e: expect = 'Path for option X does not exist: %s' % dne assert str(e) == expect, e else: raise Exception("did not catch expected UserError") def my_validator(key, val, env): raise Exception("my_validator() got called for %s, %s!" % (key, val)) opts = SCons.Variables.Variables() opts.Add( SCons.Variables.PathVariable('test2', 'more help', '/default/path/again', my_validator)) o = opts.options[0] try: o.validator('Y', 'value', {}) except Exception as e: assert str(e) == 'my_validator() got called for Y, value!', e else: raise Exception( "did not catch expected exception from my_validator()")
def test_PathIsFile(self): """Test the PathIsFile validator""" opts = SCons.Variables.Variables() opts.Add( SCons.Variables.PathVariable( 'test', 'test option help', '/default/path', SCons.Variables.PathVariable.PathIsFile)) test = TestCmd.TestCmd(workdir='') test.subdir('dir') test.write('file', "file\n") o = opts.options[0] o.validator('X', test.workpath('file'), {}) d = test.workpath('d') try: o.validator('X', d, {}) except SCons.Errors.UserError, e: assert str(e) == 'File path for option X does not exist: %s' % d, e
def test_PathAccept(self): """Test the PathAccept validator""" opts = SCons.Variables.Variables() opts.Add( SCons.Variables.PathVariable( 'test', 'test option help', '/default/path', SCons.Variables.PathVariable.PathAccept)) test = TestCmd.TestCmd(workdir='') test.subdir('dir') test.write('file', "file\n") o = opts.options[0] o.validator('X', test.workpath('file'), {}) d = test.workpath('d') o.validator('X', d, {}) dne = test.workpath('does_not_exist') o.validator('X', dne, {})
def test_PathIsDir(self): """Test the PathIsDir validator""" opts = SCons.Variables.Variables() opts.Add( SCons.Variables.PathVariable( 'test', 'test option help', '/default/path', SCons.Variables.PathVariable.PathIsDir)) test = TestCmd.TestCmd(workdir='') test.subdir('dir') test.write('file', "file\n") o = opts.options[0] o.validator('X', test.workpath('dir'), {}) f = test.workpath('file') try: o.validator('X', f, {}) except SCons.Errors.UserError, e: assert str(e) == 'Directory path for option X is a file: %s' % f, e
def setUp(self): self.test = TestCmd.TestCmd(workdir = '') self.test.subdir('dir', ['dir', 'sub']) self.test.write(['dir', 'f1'], "dir/f1\n") self.test.write(['dir', 'f2'], "dir/f2\n") self.test.write(['dir', '.sconsign'], "dir/.sconsign\n") self.test.write(['dir', '.sconsign.bak'], "dir/.sconsign.bak\n") self.test.write(['dir', '.sconsign.dat'], "dir/.sconsign.dat\n") self.test.write(['dir', '.sconsign.db'], "dir/.sconsign.db\n") self.test.write(['dir', '.sconsign.dblite'], "dir/.sconsign.dblite\n") self.test.write(['dir', '.sconsign.dir'], "dir/.sconsign.dir\n") self.test.write(['dir', '.sconsign.pag'], "dir/.sconsign.pag\n") self.test.write(['dir', 'sub', 'f3'], "dir/sub/f3\n") self.test.write(['dir', 'sub', 'f4'], "dir/sub/f4\n") self.test.write(['dir', 'sub', '.sconsign'], "dir/.sconsign\n") self.test.write(['dir', 'sub', '.sconsign.bak'], "dir/.sconsign.bak\n") self.test.write(['dir', 'sub', '.sconsign.dat'], "dir/.sconsign.dat\n") self.test.write(['dir', 'sub', '.sconsign.dblite'], "dir/.sconsign.dblite\n") self.test.write(['dir', 'sub', '.sconsign.dir'], "dir/.sconsign.dir\n") self.test.write(['dir', 'sub', '.sconsign.pag'], "dir/.sconsign.pag\n")
right files in our distributions. Note that this is a source file and packaging test, not a functional test, so the name of this script doesn't end in *Tests.py. """ import fnmatch import os import os.path import re import TestCmd import TestSCons # Use TestCmd, not TestSCons, so we don't chdir to a temporary directory. test = TestCmd.TestCmd() scons_version = TestSCons.SConsVersion def build_path(*args): return os.path.join('build', *args) build_scons = build_path('scons') build_local = build_path('scons-local', 'scons-local-' + scons_version) build_src = build_path('scons-src') class Checker(object): def __init__(self,
def end_scons_output(self): # The real raison d'etre for this script, this is where we # actually execute SCons to fetch the output. o = self.o e = o.e t = TestCmd.TestCmd(workdir='', combine=1) if o.preserve: t.preserve() t.subdir('ROOT', 'WORK') t.rootpath = string.replace(t.workpath('ROOT'), '\\', '\\\\') for d in e.dirs: dir = t.workpath('WORK', d.name) if not os.path.exists(dir): os.makedirs(dir) for f in e.files: i = 0 while f.data[i] == '\n': i = i + 1 lines = string.split(f.data[i:], '\n') i = 0 while lines[0][i] == ' ': i = i + 1 lines = map(lambda l, i=i: l[i:], lines) path = string.replace(f.name, '__ROOT__', t.rootpath) if not os.path.isabs(path): path = t.workpath('WORK', path) dir, name = os.path.split(path) if dir and not os.path.exists(dir): os.makedirs(dir) content = string.join(lines, '\n') content = string.replace(content, '__ROOT__', t.rootpath) path = t.workpath('WORK', path) t.write(path, content) if hasattr(f, 'chmod'): os.chmod(path, int(f.chmod, 0)) i = len(o.prefix) while o.prefix[i-1] != '\n': i = i - 1 sys.stdout.write('<screen>' + o.prefix[:i]) p = o.prefix[i:] for c in o.commandlist: sys.stdout.write(p + Prompt[o.os]) d = string.replace(c.data, '__ROOT__', '') sys.stdout.write('<userinput>' + d + '</userinput>\n') e = string.replace(c.data, '__ROOT__', t.workpath('ROOT')) args = string.split(e) lines = ExecuteCommand(args, c, t, {'osname':o.os, 'tools':o.tools}) content = None if c.output: content = c.output elif lines: content = string.join(lines, '\n' + p) if content: content = string.replace(content, '<', '<') content = string.replace(content, '>', '>') sys.stdout.write(p + content + '\n') if o.data[0] == '\n': o.data = o.data[1:] sys.stdout.write(o.data + '</screen>') delattr(self, 'o') self.afunclist = self.afunclist[:-1]
def create_scons_output(e): """ The real raison d'etre for this script, this is where we actually execute SCons to fetch the output. """ # Loop over all outputs for the example for o in e.outputs: # Create new test directory t = TestCmd.TestCmd(workdir='', combine=1) if o.preserve: t.preserve() t.subdir('ROOT', 'WORK') t.rootpath = t.workpath('ROOT').replace('\\', '\\\\') for d in e.folders: dir = t.workpath('WORK', d.name) if not os.path.exists(dir): os.makedirs(dir) for f in e.files: if f.isFileRef(): continue # # Left-align file's contents, starting on the first # non-empty line # data = f.content.split('\n') i = 0 # Skip empty lines while data[i] == '': i = i + 1 lines = data[i:] i = 0 # Scan first line for the number of spaces # that this block is indented while lines[0][i] == ' ': i = i + 1 # Left-align block lines = [l[i:] for l in lines] path = f.name.replace('__ROOT__', t.rootpath) if not os.path.isabs(path): path = t.workpath('WORK', path) dir, name = os.path.split(path) if dir and not os.path.exists(dir): os.makedirs(dir) content = '\n'.join(lines) content = content.replace('__ROOT__', t.rootpath) path = t.workpath('WORK', path) t.write(path, content) if hasattr(f, 'chmod'): if len(f.chmod): os.chmod(path, int(f.chmod, base=8)) # Regular expressions for making the doc output consistent, # regardless of reported addresses or Python version. # Massage addresses in object repr strings to a constant. address_re = re.compile(r' at 0x[0-9a-fA-F]*>') # Massage file names in stack traces (sometimes reported as absolute # paths) to a consistent relative path. engine_re = re.compile(r' File ".*/src/engine/SCons/') # Python 2.5 changed the stack trace when the module is read # from standard input from read "... line 7, in ?" to # "... line 7, in <module>". file_re = re.compile(r'^( *File ".*", line \d+, in) \?$', re.M) # Python 2.6 made UserList a new-style class, which changes the # AttributeError message generated by our NodeList subclass. nodelist_re = re.compile(r'(AttributeError:) NodeList instance (has no attribute \S+)') # Root element for our subtree sroot = stf.newEtreeNode("screen", True) curchild = None content = "" for command in o.commands: content += Prompt[o.os] if curchild is not None: if not command.output: # Append content as tail curchild.tail = content content = "\n" # Add new child for userinput tag curchild = stf.newEtreeNode("userinput") d = command.cmd.replace('__ROOT__', '') curchild.text = d sroot.append(curchild) else: content += command.output + '\n' else: if not command.output: # Add first text to root sroot.text = content content = "\n" # Add new child for userinput tag curchild = stf.newEtreeNode("userinput") d = command.cmd.replace('__ROOT__', '') curchild.text = d sroot.append(curchild) else: content += command.output + '\n' # Execute command and capture its output cmd_work = command.cmd.replace('__ROOT__', t.workpath('ROOT')) args = cmd_work.split() lines = ExecuteCommand(args, command, t, {'osname':o.os, 'tools':o.tools}) if not command.output and lines: ncontent = '\n'.join(lines) ncontent = address_re.sub(r' at 0x700000>', ncontent) ncontent = engine_re.sub(r' File "bootstrap/src/engine/SCons/', ncontent) ncontent = file_re.sub(r'\1 <module>', ncontent) ncontent = nodelist_re.sub(r"\1 'NodeList' object \2", ncontent) ncontent = ncontent.replace('__ROOT__', '') content += ncontent + '\n' # Add last piece of content if len(content): if curchild is not None: curchild.tail = content else: sroot.text = content # Construct filename fpath = os.path.join(generated_examples, e.name + '_' + o.suffix + '.xml') # Expand Element tree s = stf.decorateWithHeader(stf.convertElementTree(sroot)[0]) # Write it to file stf.writeTree(s, fpath)
def setUp(self): # we always want to start with a clean directory self.save_cwd = os.getcwd() self.test = TestCmd.TestCmd(workdir='') os.chdir(self.test.workpath(''))
def setUp(self): self.save_cwd = os.getcwd() self.test = TestCmd.TestCmd(workdir='') os.chdir(self.test.workpath(''))
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import SCons.compat import collections import os import sys import unittest import TestCmd import SCons.Node.FS import SCons.Scanner.LaTeX test = TestCmd.TestCmd(workdir = '') test.write('test1.latex',r""" \include{inc1} \input{inc2} include{incNO} %\include{incNO} xyzzy \include{inc6} \subimport{subdir}{inc3} \import{subdir}{inc3a} \includefrom{subdir}{inc3b} \subincludefrom{subdir}{inc3c} \inputfrom{subdir}{inc3d} \subinputfrom{subdir}{inc3e} """)
def end_scons_output(self): # The real raison d'etre for this script, this is where we # actually execute SCons to fetch the output. o = self.o e = o.e t = TestCmd.TestCmd(workdir='', combine=1) if o.preserve: t.preserve() t.subdir('ROOT', 'WORK') t.rootpath = t.workpath('ROOT').replace('\\', '\\\\') for d in e.dirs: dir = t.workpath('WORK', d.name) if not os.path.exists(dir): os.makedirs(dir) for f in e.files: i = 0 while f.data[i] == '\n': i = i + 1 lines = f.data[i:].split('\n') i = 0 while lines[0][i] == ' ': i = i + 1 lines = [l[i:] for l in lines] path = f.name.replace('__ROOT__', t.rootpath) if not os.path.isabs(path): path = t.workpath('WORK', path) dir, name = os.path.split(path) if dir and not os.path.exists(dir): os.makedirs(dir) content = '\n'.join(lines) content = content.replace('__ROOT__', t.rootpath) path = t.workpath('WORK', path) t.write(path, content) if hasattr(f, 'chmod'): os.chmod(path, int(f.chmod, 0)) i = len(o.prefix) while o.prefix[i - 1] != '\n': i = i - 1 self.outfp.write('<screen>' + o.prefix[:i]) p = o.prefix[i:] # Regular expressions for making the doc output consistent, # regardless of reported addresses or Python version. # Massage addresses in object repr strings to a constant. address_re = re.compile(r' at 0x[0-9a-fA-F]*\>') # Massage file names in stack traces (sometimes reported as absolute # paths) to a consistent relative path. engine_re = re.compile(r' File ".*/src/engine/SCons/') # Python 2.5 changed the stack trace when the module is read # from standard input from read "... line 7, in ?" to # "... line 7, in <module>". file_re = re.compile(r'^( *File ".*", line \d+, in) \?$', re.M) # Python 2.6 made UserList a new-style class, which changes the # AttributeError message generated by our NodeList subclass. nodelist_re = re.compile( r'(AttributeError:) NodeList instance (has no attribute \S+)') for c in o.commandlist: self.outfp.write(p + Prompt[o.os]) d = c.data.replace('__ROOT__', '') self.outfp.write('<userinput>' + d + '</userinput>\n') e = c.data.replace('__ROOT__', t.workpath('ROOT')) args = e.split() lines = ExecuteCommand(args, c, t, { 'osname': o.os, 'tools': o.tools }) content = None if c.output: content = c.output elif lines: content = ('\n' + p).join(lines) if content: content = address_re.sub(r' at 0x700000>', content) content = engine_re.sub(r' File "bootstrap/src/engine/SCons/', content) content = file_re.sub(r'\1 <module>', content) content = nodelist_re.sub(r"\1 'NodeList' object \2", content) content = self.for_display(content) self.outfp.write(p + content + '\n') if o.data[0] == '\n': o.data = o.data[1:] self.outfp.write(o.data + '</screen>') delattr(self, 'o') self.afunclist = self.afunclist[:-1]
def test_WhereIs(self): test = TestCmd.TestCmd(workdir='') sub1_xxx_exe = test.workpath('sub1', 'xxx.exe') sub2_xxx_exe = test.workpath('sub2', 'xxx.exe') sub3_xxx_exe = test.workpath('sub3', 'xxx.exe') sub4_xxx_exe = test.workpath('sub4', 'xxx.exe') test.subdir('subdir', 'sub1', 'sub2', 'sub3', 'sub4') if sys.platform != 'win32': test.write(sub1_xxx_exe, "\n") os.mkdir(sub2_xxx_exe) test.write(sub3_xxx_exe, "\n") os.chmod(sub3_xxx_exe, 0o777) test.write(sub4_xxx_exe, "\n") os.chmod(sub4_xxx_exe, 0o777) env_path = os.environ['PATH'] try: pathdirs_1234 = [ test.workpath('sub1'), test.workpath('sub2'), test.workpath('sub3'), test.workpath('sub4'), ] + env_path.split(os.pathsep) pathdirs_1243 = [ test.workpath('sub1'), test.workpath('sub2'), test.workpath('sub4'), test.workpath('sub3'), ] + env_path.split(os.pathsep) os.environ['PATH'] = os.pathsep.join(pathdirs_1234) wi = WhereIs('xxx.exe') assert wi == test.workpath(sub3_xxx_exe), wi wi = WhereIs('xxx.exe', pathdirs_1243) assert wi == test.workpath(sub4_xxx_exe), wi wi = WhereIs('xxx.exe', os.pathsep.join(pathdirs_1243)) assert wi == test.workpath(sub4_xxx_exe), wi wi = WhereIs('xxx.exe', reject=sub3_xxx_exe) assert wi == test.workpath(sub4_xxx_exe), wi wi = WhereIs('xxx.exe', pathdirs_1243, reject=sub3_xxx_exe) assert wi == test.workpath(sub4_xxx_exe), wi os.environ['PATH'] = os.pathsep.join(pathdirs_1243) wi = WhereIs('xxx.exe') assert wi == test.workpath(sub4_xxx_exe), wi wi = WhereIs('xxx.exe', pathdirs_1234) assert wi == test.workpath(sub3_xxx_exe), wi wi = WhereIs('xxx.exe', os.pathsep.join(pathdirs_1234)) assert wi == test.workpath(sub3_xxx_exe), wi if sys.platform == 'win32': wi = WhereIs('xxx', pathext='') assert wi is None, wi wi = WhereIs('xxx', pathext='.exe') assert wi == test.workpath(sub4_xxx_exe), wi wi = WhereIs('xxx', path=pathdirs_1234, pathext='.BAT;.EXE') assert wi.lower() == test.workpath(sub3_xxx_exe).lower(), wi # Test that we return a normalized path even when # the path contains forward slashes. forward_slash = test.workpath('') + '/sub3' wi = WhereIs('xxx', path=forward_slash, pathext='.EXE') assert wi.lower() == test.workpath(sub3_xxx_exe).lower(), wi del os.environ['PATH'] wi = WhereIs('xxx.exe') assert wi is None, wi finally: os.environ['PATH'] = env_path