Skip to content

Commit

Permalink
unit test on buildbot.steps.transfer._FileWriter.__init__()
Browse files Browse the repository at this point in the history
Test creating an instance of _FileWrite class. Test the code path
where destfile's parent directory is created.
  • Loading branch information
Elmir Jagudin committed Sep 3, 2013
1 parent 20a0802 commit f8c2019
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions master/buildbot/test/unit/test_steps_transfer.py
Expand Up @@ -18,6 +18,7 @@
import tempfile, os
import shutil
import tarfile
import stat
from twisted.trial import unittest

from mock import Mock
Expand All @@ -33,6 +34,46 @@
from buildbot.test.fake.remotecommand import Expect, ExpectRemoteRef


# Test buildbot.steps.transfer._FileWriter class.
class TestFileWriter(unittest.TestCase):

# test _FileWrite.__init__() method.
def testInit(self):
#
# patch functions called in constructor
#

# patch os.path.exists() to always return False
mockedExists = Mock(return_value=False)
self.patch(os.path, "exists", mockedExists)

# capture calls to os.makedirs()
mockedMakedirs = Mock()
self.patch(os, 'makedirs', mockedMakedirs)

# capture calls to tempfile.mkstemp()
mockedMkstemp = Mock(return_value=(7, "tmpname"))
self.patch(tempfile, "mkstemp", mockedMkstemp)

# capture calls to os.fdopen()
mockedFdopen = Mock()
self.patch(os, "fdopen", mockedFdopen)

#
# call _FileWriter constructor
#
destfile = os.path.join("dir", "file")
transfer._FileWriter(destfile, 64, stat.S_IRUSR)

#
# validate captured calls
#
absdir = os.path.dirname(os.path.abspath(os.path.join("dir", "file")))
mockedExists.assert_called_once_with(absdir)
mockedMakedirs.assert_called_once_with(absdir)
mockedMkstemp.assert_called_once_with(dir=absdir)
mockedFdopen.assert_called_once_with(7, 'wb')

# Test buildbot.steps.transfer._TransferBuildStep class.
class TestTransferBuildStep(unittest.TestCase):

Expand Down

0 comments on commit f8c2019

Please sign in to comment.