Skip to content
Browse files

Properly generate a PYTHONPATH and locate the cheetah executable for …

…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...
1 parent 7ab7f51 commit 8724436c90babf5a9e45580858749ad3050d0db3 @rtyler rtyler committed Mar 21, 2010
Showing with 12 additions and 6 deletions.
  1. +12 −6 cheetah/Tests/CheetahWrapper.py
View
18 cheetah/Tests/CheetahWrapper.py
@@ -63,6 +63,12 @@ def setUp(self):
"""Create the top-level directories, subdirectories and .tmpl
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
# Step 1: Create the scratch directory and chdir into it.
self.scratchDir = scratchDir = tempfile.mktemp()
@@ -79,7 +85,6 @@ def setUp(self):
f = open(fil, 'w')
f.write("Hello, world!\n")
f.close()
-
def tearDown(self):
os.chdir(self.origCwd)
@@ -157,17 +162,18 @@ def checkNoBackup(self, path):
msg = "backup file exists in spite of --nobackup: %s" % path
self.failIf(exists, msg)
- def locate_command(self, cmd):
+ def locate_cheetah(self, cmd):
paths = os.getenv('PATH')
if not paths:
return cmd
parts = cmd.split(' ')
paths = paths.split(':')
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):
- return ' '.join([p] + parts[1:])
- return ' '.join(parts)
+ return p
+ return cmd
def assertWin32Subprocess(self, cmd):
_in, _out = os.popen4(cmd)
@@ -179,7 +185,7 @@ def assertWin32Subprocess(self, cmd):
return rc, output
def assertPosixSubprocess(self, cmd):
- cmd = self.locate_command(cmd)
+ cmd = cmd.replace('cheetah', self.cmd)
process = Popen4(cmd, env=os.environ)
process.tochild.close()
output = process.fromchild.read()

0 comments on commit 8724436

Please sign in to comment.
Something went wrong with that request. Please try again.