Skip to content

Commit

Permalink
fix tests for homedir searching on win32
Browse files Browse the repository at this point in the history
On windows, buildbot looks for a config in %APPDATA%/buildbot, rather than
$HOME/.buildbot.
  • Loading branch information
djmitche committed May 28, 2012
1 parent e591646 commit 08060ca
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions master/buildbot/test/unit/test_scripts_base.py
Expand Up @@ -21,7 +21,7 @@
from twisted.trial import unittest
from buildbot.scripts import base
from buildbot.test.util import dirs, misc
from twisted.python import usage
from twisted.python import usage, runtime

class TestIBD(dirs.DirsMixin, misc.StdoutAssertionsMixin, unittest.TestCase):

Expand Down Expand Up @@ -115,9 +115,14 @@ def do_loadOptionsFile(self, _here, exp):
# avoid breaking other parts of the test system
patches = []

def expanduser(p):
return p.replace('~/', self.home + '/')
patches.append(self.patch(os.path, 'expanduser', expanduser))
if runtime.platformType == 'win32':
from win32com.shell import shell
patches.append(self.patch(shell, 'SHGetFolderPath',
lambda *args : self.home))
else:
def expanduser(p):
return p.replace('~/', self.home + '/')
patches.append(self.patch(os.path, 'expanduser', expanduser))

old_dirname = os.path.dirname
def dirname(p):
Expand All @@ -133,9 +138,9 @@ def dirname(p):
for p in patches:
p.restore()

def writeOptionsFile(self, dir, content):
os.makedirs(os.path.join(dir, '.buildbot'))
with open(os.path.join(dir, '.buildbot', 'options'), 'w') as f:
def writeOptionsFile(self, dir, content, bbdir='.buildbot'):
os.makedirs(os.path.join(dir, bbdir))
with open(os.path.join(dir, bbdir, 'options'), 'w') as f:
f.write(content)

def test_loadOptionsFile_subdirs_not_found(self):
Expand All @@ -160,7 +165,10 @@ def test_loadOptionsFile_subdirs_at_tip(self):
def test_loadOptionsFile_subdirs_at_homedir(self):
subdir = os.path.join(self.dir, 'a', 'b')
os.makedirs(subdir)
self.writeOptionsFile(self.home, 'abc=123')
# on windows, the subdir of the home (well, appdata) dir
# is 'buildbot', not '.buildbot'
self.writeOptionsFile(self.home, 'abc=123',
'buildbot' if runtime.platformType == 'win32' else '.buildbot')
self.do_loadOptionsFile(_here=subdir, exp={'abc':123})

def test_loadOptionsFile_syntax_error(self):
Expand Down

0 comments on commit 08060ca

Please sign in to comment.