"Fossies" - the Fresh Open Source Software Archive

Member "buildbot-2.5.1/buildbot/test/unit/test_process_factory.py" (24 Nov 2019, 7068 Bytes) of package /linux/misc/buildbot-2.5.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # This file is part of Buildbot.  Buildbot is free software: you can
    2 # redistribute it and/or modify it under the terms of the GNU General Public
    3 # License as published by the Free Software Foundation, version 2.
    4 #
    5 # This program is distributed in the hope that it will be useful, but WITHOUT
    6 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    7 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    8 # details.
    9 #
   10 # You should have received a copy of the GNU General Public License along with
   11 # this program; if not, write to the Free Software Foundation, Inc., 51
   12 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   13 #
   14 # Copyright Buildbot Team Members
   15 
   16 
   17 from random import choice
   18 from string import ascii_uppercase
   19 
   20 from twisted.trial import unittest
   21 
   22 from buildbot.process.buildstep import BuildStep
   23 from buildbot.process.buildstep import _BuildStepFactory
   24 from buildbot.process.factory import BuildFactory
   25 from buildbot.process.factory import GNUAutoconf
   26 from buildbot.process.factory import s
   27 from buildbot.steps.shell import Configure
   28 
   29 
   30 class TestBuildFactory(unittest.TestCase):
   31 
   32     def setUp(self):
   33         self.factory = BuildFactory()
   34 
   35     def test_init(self):
   36         step = BuildStep()
   37         self.factory = BuildFactory([step])
   38         self.assertEqual(self.factory.steps, [_BuildStepFactory(BuildStep)])
   39 
   40     def test_addStep(self):
   41         # create a string random string that will probably not collide
   42         # with what is already in the factory
   43         string = ''.join(choice(ascii_uppercase) for x in range(6))
   44         length = len(self.factory.steps)
   45 
   46         step = BuildStep(name=string)
   47         self.factory.addStep(step)
   48 
   49         # check if the number of nodes grew by one
   50         self.assertTrue(length + 1, len(self.factory.steps))
   51         # check if the 'right' node added in the factory
   52         self.assertEqual(self.factory.steps[-1],
   53                          _BuildStepFactory(BuildStep, name=string))
   54 
   55     def test_addStep_deprecated_withArguments(self):
   56         """
   57         Passing keyword arguments to L{BuildFactory.addStep} is deprecated,
   58         but pass the arguments to the first argument, to construct a step.
   59         """
   60         self.factory.addStep(BuildStep, name='test')
   61 
   62         self.assertEqual(self.factory.steps[-1],
   63                          _BuildStepFactory(BuildStep, name='test'))
   64 
   65         warnings = self.flushWarnings(
   66             [self.test_addStep_deprecated_withArguments])
   67         self.assertEqual(len(warnings), 1)
   68         self.assertEqual(warnings[0]['category'], DeprecationWarning)
   69 
   70     def test_addStep_deprecated(self):
   71         """
   72         Passing keyword arguments to L{BuildFactory.addStep} is deprecated,
   73         but pass the arguments to the first argument, to construct a step.
   74         """
   75         self.factory.addStep(BuildStep)
   76 
   77         self.assertEqual(self.factory.steps[-1],
   78                          _BuildStepFactory(BuildStep))
   79 
   80         warnings = self.flushWarnings([self.test_addStep_deprecated])
   81         self.assertEqual(len(warnings), 1)
   82         self.assertEqual(warnings[0]['category'], DeprecationWarning)
   83 
   84     def test_s(self):
   85         """
   86         L{s} is deprecated, but pass keyword arguments to the first argument,
   87         to construct a step.
   88         """
   89         stepFactory = s(BuildStep, name='test')
   90         self.assertEqual(
   91             stepFactory, _BuildStepFactory(BuildStep, name='test'))
   92         warnings = self.flushWarnings([self.test_s])
   93         self.assertEqual(len(warnings), 1)
   94         self.assertEqual(warnings[0]['category'], DeprecationWarning)
   95 
   96     def test_addStep_notAStep(self):
   97         # This fails because object isn't adaptable to IBuildStepFactory
   98         with self.assertRaises(TypeError):
   99             self.factory.addStep(object())
  100 
  101     def test_addStep_ArgumentsInTheWrongPlace(self):
  102         with self.assertRaises(TypeError):
  103             self.factory.addStep(BuildStep(), name="name")
  104         # this also raises a deprecation error, which we don't care about (see
  105         # test_s)
  106         self.flushWarnings()
  107 
  108     def test_addSteps(self):
  109         self.factory.addSteps([BuildStep(), BuildStep()])
  110         self.assertEqual(self.factory.steps[-2:],
  111                          [_BuildStepFactory(BuildStep),
  112                           _BuildStepFactory(BuildStep)])
  113 
  114 
  115 class TestGNUAutoconf(TestBuildFactory):
  116 
  117     def setUp(self):
  118         self.factory = GNUAutoconf(source=BuildStep())
  119 
  120     def test_init(self):
  121         # actual initialization is already done by setUp
  122         configurePresent = False
  123         compilePresent = False
  124         checkPresent = False
  125         distcheckPresent = False
  126         for step in self.factory.steps:
  127             if isinstance(step.buildStep(), Configure):
  128                 configurePresent = True
  129             # the following checks are rather hairy and should be
  130             # rewritten less implementation dependent.
  131             try:
  132                 if step.buildStep().command == ['make', 'all']:
  133                     compilePresent = True
  134                 if step.buildStep().command == ['make', 'check']:
  135                     checkPresent = True
  136                 if step.buildStep().command == ['make', 'distcheck']:
  137                     distcheckPresent = True
  138             except(AttributeError, KeyError):
  139                 pass
  140 
  141         self.assertTrue(configurePresent)
  142         self.assertTrue(compilePresent)
  143         self.assertTrue(checkPresent)
  144         self.assertTrue(distcheckPresent)
  145 
  146     def test_init_none(self):
  147         """Default steps can be uninitialized by setting None"""
  148 
  149         self.factory = GNUAutoconf(source=BuildStep(), compile=None, test=None,
  150                                    distcheck=None)
  151         for step in self.factory.steps:
  152             try:
  153                 cmd = step.buildStep().command
  154                 self.assertNotIn(cmd, [['make', 'all'], ['make', 'check'],
  155                                  ['make', 'distcheck']],
  156                                  "Build step %s should not be present." % cmd)
  157             except(AttributeError, KeyError):
  158                 pass
  159 
  160     def test_init_reconf(self):
  161         # test reconf = True
  162         self.factory = GNUAutoconf(source=BuildStep(), reconf=True)
  163         self.test_init()
  164         reconfPresent = False
  165         selfreconfPresent = False
  166 
  167         for step in self.factory.steps:
  168             try:
  169                 if step.buildStep().command[0] == 'autoreconf':
  170                     reconfPresent = True
  171             except(AttributeError, KeyError):
  172                 pass
  173         self.assertTrue(reconfPresent)
  174 
  175         # test setting your own reconfiguration step
  176         self.factory = GNUAutoconf(source=BuildStep(),
  177                                    reconf=['notsoautoreconf'])
  178         self.test_init()
  179         for step in self.factory.steps:
  180             try:
  181                 if step.buildStep().command == ['notsoautoreconf']:
  182                     selfreconfPresent = True
  183             except(AttributeError, KeyError):
  184                 pass
  185         self.assertTrue(selfreconfPresent)