Skip to content

Commit

Permalink
Properly generate a PYTHONPATH and locate the cheetah executable for …
Browse files Browse the repository at this point in the history
…CheetahWrapper tests

On FreeBSD particularly, the tempfile.mktemp() heavily sandboxes the
process into /tmp/ somewhere. Finding absolute paths to the cheetah
process and the Cheetah/ directory is necessary to properly run the tests
  • Loading branch information
R. Tyler Ballance committed Mar 22, 2010
1 parent 7ab7f51 commit 8724436
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions cheetah/Tests/CheetahWrapper.py
Expand Up @@ -63,6 +63,12 @@ def setUp(self):
"""Create the top-level directories, subdirectories and .tmpl """Create the top-level directories, subdirectories and .tmpl
files. files.
""" """
self.cmd = self.locate_cheetah('cheetah')
pythonPath = os.getcwd()
if not os.environ.get('PYTHONPATH'):
os.environ['PYTHONPATH'] = pythonPath
else:
os.environ['PYTHONPATH'] = '%s:%s' % (os.environ['PYTHONPATH'], pythonPath)
I = self.inform I = self.inform
# Step 1: Create the scratch directory and chdir into it. # Step 1: Create the scratch directory and chdir into it.
self.scratchDir = scratchDir = tempfile.mktemp() self.scratchDir = scratchDir = tempfile.mktemp()
Expand All @@ -79,7 +85,6 @@ def setUp(self):
f = open(fil, 'w') f = open(fil, 'w')
f.write("Hello, world!\n") f.write("Hello, world!\n")
f.close() f.close()



def tearDown(self): def tearDown(self):
os.chdir(self.origCwd) os.chdir(self.origCwd)
Expand Down Expand Up @@ -157,17 +162,18 @@ def checkNoBackup(self, path):
msg = "backup file exists in spite of --nobackup: %s" % path msg = "backup file exists in spite of --nobackup: %s" % path
self.failIf(exists, msg) self.failIf(exists, msg)


def locate_command(self, cmd): def locate_cheetah(self, cmd):
paths = os.getenv('PATH') paths = os.getenv('PATH')
if not paths: if not paths:
return cmd return cmd
parts = cmd.split(' ') parts = cmd.split(' ')
paths = paths.split(':') paths = paths.split(':')
for p in paths: for p in paths:
p = p + os.path.sep + parts[0] p = os.path.join(p, cmd)
p = os.path.abspath(p)
if os.path.isfile(p): if os.path.isfile(p):
return ' '.join([p] + parts[1:]) return p
return ' '.join(parts) return cmd


def assertWin32Subprocess(self, cmd): def assertWin32Subprocess(self, cmd):
_in, _out = os.popen4(cmd) _in, _out = os.popen4(cmd)
Expand All @@ -179,7 +185,7 @@ def assertWin32Subprocess(self, cmd):
return rc, output return rc, output


def assertPosixSubprocess(self, cmd): def assertPosixSubprocess(self, cmd):
cmd = self.locate_command(cmd) cmd = cmd.replace('cheetah', self.cmd)
process = Popen4(cmd, env=os.environ) process = Popen4(cmd, env=os.environ)
process.tochild.close() process.tochild.close()
output = process.fromchild.read() output = process.fromchild.read()
Expand Down

0 comments on commit 8724436

Please sign in to comment.