Skip to content

Commit

Permalink
fix missing imports in runprocess.py; add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin J. Mitchell committed Jun 14, 2010
1 parent 2d04f6b commit 29c3ba8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions slave/buildslave/runprocess.py
Expand Up @@ -8,10 +8,11 @@
import types
import re
import traceback
import stat
from collections import deque

from twisted.python import runtime, log
from twisted.internet import reactor, defer, protocol
from twisted.internet import reactor, defer, protocol, task

from buildslave import util
from buildslave.exceptions import AbandonChain
Expand Down Expand Up @@ -55,7 +56,7 @@ def stop(self):
def statFile(self):
if os.path.exists(self.logfile):
s = os.stat(self.logfile)
return (s[ST_CTIME], s[ST_MTIME], s[ST_SIZE])
return (s[stat.ST_CTIME], s[stat.ST_MTIME], s[stat.ST_SIZE])
return None

def poll(self):
Expand Down
21 changes: 21 additions & 0 deletions slave/buildslave/test/unit/test_runprocess.py
@@ -1,5 +1,6 @@
import sys
import re
import os

from twisted.trial import unittest
from twisted.internet import task, defer
Expand Down Expand Up @@ -265,3 +266,23 @@ def testSendNotimeout(self):
s._addToBuffers('stdout', data)
self.failUnlessEqual(len(b.updates), 1)

class TestLogFileWatcher(unittest.TestCase):
def makeRP(self):
b = FakeSlaveBuilder(False, 'base')
rp = runprocess.RunProcess(b, stdoutCommand('hello'), b.basedir)
return rp

def test_statFile_missing(self):
rp = self.makeRP()
if os.path.exists('statfile.log'):
os.remove('statfile.log')
lf = runprocess.LogFileWatcher(rp, 'test', 'statfile.log', False)
self.assertFalse(lf.statFile(), "statfile.log doesn't exist")

def test_statFile_exists(self):
rp = self.makeRP()
open('statfile.log', 'w').write('hi')
lf = runprocess.LogFileWatcher(rp, 'test', 'statfile.log', False)
st = lf.statFile()
self.assertEqual(st and st[2], 2, "statfile.log exists and size is correct")
os.remove('statfile.log')

0 comments on commit 29c3ba8

Please sign in to comment.