Skip to content

Commit

Permalink
implement some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jpommerening committed Mar 4, 2014
1 parent 3a634b2 commit 2027f32
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 14 deletions.
1 change: 1 addition & 0 deletions master/buildbot/status/logfile.py
Expand Up @@ -673,6 +673,7 @@ def __init__(self, parent, name, logfilename, html):
self.html = html

def hasContents(self):
assert not self._isNewStyle, "not available in new-style steps"
return True

def _fakeOpenfile(self, html):
Expand Down
106 changes: 92 additions & 14 deletions master/buildbot/test/unit/test_status_logfile.py
Expand Up @@ -344,6 +344,20 @@ def test_compressLog_none(self):

class TestHTMLLogFile(unittest.TestCase, dirs.DirsMixin):

# The following script was used to pickle an 0.8.8 logfile. It was then
# base64 encoded to be safely embedded in this test class.
#
# from buildbot.status import logfile
# import pickle
# lf = logfile.HTMLLogFile('error.html', '123-error_html', '<span>You lost the game</span>')
# with open('123-error_html', 'w') as f:
# pickle.dump(lf, f)
buildbot088pickle = '''
KGlidWlsZGJvdC5zdGF0dXMubG9nZmlsZQpIVE1MTG9nRmlsZQpwMAooZHAyClMnaHRtbCcKcD
MKUyc8c3Bhbj5Zb3UgbG9zdCB0aGUgZ2FtZTwvc3Bhbj4nCnA0CnNTJ25hbWUnCnA1ClMnZXJy
b3IuaHRtbCcKcDYKc1MnZmlsZW5hbWUnCnA3ClMnMTIzLWVycm9yX2h0bWwnCnA4CnNiLg==
'''

def setUp(self):
step = self.build_step_status = mock.Mock(name='build_step_status')
self.basedir = step.build.builder.basedir = os.path.abspath('basedir')
Expand All @@ -368,6 +382,13 @@ def pickle_and_restore(self):
self.logfile.master = self.master
step.build.builder.basedir = self.basedir

def create_large_logfile(self):
# fake a logfile that exceeds HTMLLogFile.maxEmbedSize
maxEmbedSize = logfile.HTMLLogFile.maxEmbedSize
logfile.HTMLLogFile.maxEmbedSize = 5
self.logfile = logfile.HTMLLogFile(self.build_step_status, 'error.html', '123-error_html', '<span>You lost the game</span>')
self.logfile.master = self.master

def delete_logfile(self):
if self.logfile.openfile:
try:
Expand All @@ -377,37 +398,94 @@ def delete_logfile(self):
os.unlink(os.path.join('basedir', '123-error_html'))

def test_unpickle_embedded(self):
pass
self.pickle_and_restore()

d = self.logfile.finish()

def check(_):
# LogFile.__init__ already creates the file ...
# self.assertFalse(os.path.exists(os.path.join('basedir', '123-error_html')))
pass

d.addCallback(check)
return d

def test_unpickle_fromFile(self):
pass
self.create_large_logfile()
self.pickle_and_restore()

d = self.logfile.finish()

def check(_):
self.assertTrue(os.path.exists(os.path.join('basedir', '123-error_html')))

d.addCallback(check)
return d

def test_unpickle_buildbot088pickle(self):
import base64
s = base64.b64decode(self.buildbot088pickle)
self.logfile = cPickle.loads(s)
step = self.build_step_status
self.logfile.step = step
self.logfile.master = self.master
step.build.builder.basedir = self.basedir

self.assertEqual(self.logfile.getName(), 'error.html')
self.assertEqual(self.logfile.getText(), '<span>You lost the game</span>')

def test_unpickle_pre089(self):
pass
def test_hasContents(self):
self.assertTrue(self.logfile.hasContents())

def test_getName(self):
pass
self.assertEqual(self.logfile.getName(), 'error.html')

def test_getStep(self):
pass
self.assertEqual(self.logfile.getStep(), self.build_step_status)

def test_isFinished(self):
pass
self.assertTrue(self.logfile.isFinished())

def test_waitUntilFinished(self):
pass
d = self.logfile.waitUntilFinished()
return d

def test_getText_embedded(self):
pass
self.assertEqual(self.logfile.getText(), '<span>You lost the game</span>')

def test_getText_fromFile(self):
pass
self.create_large_logfile()
self.pickle_and_restore()
self.assertEqual(self.logfile.getText(), '<span>You lost the game</span>')

def test_getTextWithHeaders_embedded(self):
pass
self.assertEqual(self.logfile.getTextWithHeaders(), '<span>You lost the game</span>')

def test_getTextWithHeaders_fromFile(self):
pass
self.create_large_logfile()
self.pickle_and_restore()
self.assertEqual(self.logfile.getTextWithHeaders(), '<span>You lost the game</span>')

def test_getFile_embedded(self):
fp = self.logfile.getFile()
fp.seek(0, 0)
self.assertEqual(fp.read(), '31:1<span>You lost the game</span>,')

self.pickle_and_restore()

def test_finish(self):
pass
fp = self.logfile.getFile()
fp.seek(0, 0)
self.assertEqual(fp.read(), '31:1<span>You lost the game</span>,')

def test_getFile_fromFile(self):
self.create_large_logfile()

fp = self.logfile.getFile()
fp.seek(0, 0)
self.assertEqual(fp.read(), '31:1<span>You lost the game</span>,')

self.pickle_and_restore()

fp = self.logfile.getFile()
fp.seek(0, 0)
self.assertEqual(fp.read(), '31:1<span>You lost the game</span>,')

0 comments on commit 2027f32

Please sign in to comment.