~ubuntu-branches/ubuntu/karmic/gears/karmic

« back to all changes in this revision

Viewing changes to gears/test/runner/unittests/bootstrap_test.py

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Lesicnik
  • Date: 2009-04-30 19:15:25 UTC
  • Revision ID: james.westby@ubuntu.com-20090430191525-0790sb5wzg8ou0xb
Tags: upstream-0.5.21.0~svn3334+dfsg
ImportĀ upstreamĀ versionĀ 0.5.21.0~svn3334+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
import shutil
 
3
import StringIO
 
4
import runner
 
5
import unittest
 
6
import pmock
 
7
from runner import Bootstrap
 
8
 
 
9
class BootstrapTest(unittest.TestCase):
 
10
  
 
11
  def setUp(self):
 
12
    self.__create_output_dir
 
13
    self.gears_binaries = "testdata/windows/installers"
 
14
    self.testrunner_mock = pmock.Mock()
 
15
    self.suites_report_mock = pmock.Mock()
 
16
    self.installers = [pmock.Mock(), pmock.Mock()]
 
17
    self.bootstrap = Bootstrap(self.gears_binaries, self.installers, 
 
18
                               self.testrunner_mock, self.suites_report_mock)
 
19
 
 
20
 
 
21
  def tearDown(self):
 
22
    self.testrunner_mock.verify()
 
23
    self.__delete_output_dir()
 
24
    self.suites_report_mock.verify()
 
25
    for installer in self.installers:
 
26
      installer.verify()
 
27
 
 
28
    
 
29
  def testStartTesting(self):
 
30
    self.testrunner_mock.expects(pmock.once()).runTests()
 
31
    self.bootstrap.startTesting()
 
32
  
 
33
  
 
34
  def testReportResultsWritesToFile(self):
 
35
    test_result_data = {'browser1': 'TIMED-OUT'}
 
36
    self.testrunner_mock.expects(pmock.once()).runTests() \
 
37
      .will(pmock.return_value(test_result_data))
 
38
    output_stream = StringIO.StringIO()
 
39
    self.suites_report_mock.expects(pmock.once()).method("writeReport")
 
40
    self.bootstrap.startTesting()
 
41
    self.bootstrap.writeResultsToFile()
 
42
 
 
43
 
 
44
  def testInstall(self):
 
45
    for installer in self.installers:
 
46
      installer.expects(pmock.once()).install()
 
47
    self.bootstrap.install()
 
48
 
 
49
 
 
50
  def testClean(self):
 
51
    self.__create_output_dir()
 
52
    self.assert_(os.path.exists('output'))
 
53
    self.bootstrap.clean()
 
54
    self.assert_(not os.path.exists('output'))
 
55
 
 
56
 
 
57
  def testCleanDoesNotFailIfOutputDirMissing(self):
 
58
    self.__delete_output_dir()
 
59
    self.assert_(not os.path.exists('output'))
 
60
    self.bootstrap.clean()
 
61
 
 
62
 
 
63
  def __create_output_dir(self):
 
64
    self.__delete_output_dir()
 
65
    os.mkdir('output')
 
66
    
 
67
    
 
68
  def __delete_output_dir(self):   
 
69
    if (os.path.exists('output')):
 
70
      shutil.rmtree('output')      
 
71
 
 
72
    
 
73
if __name__ == "__main__":
 
74
  unittest.main()