예제 #1
0
    def setUp(self):
        self.bs = BuildSystem()

        self.a = {'a': 'value'}
        self.b = {'b': 1 * 10 }

        job = BuildStage()
        job.add(dump_args_to_json_file, (self.a, self.b))

        self.bs.add_stage('test', job)
예제 #2
0
    def setUp(self):
        self.bs = BuildSystem()

        self.a = {'a': 'value'}
        self.b = {'b': 1 * 10}

        job = BuildStage()
        job.add(dump_args_to_json_file, (self.a, self.b))

        self.bs.add_stage('test', job)
예제 #3
0
    def test_init_with_stages(self):
        b_one = BuildStage()
        b_two = BuildSequence()

        bs_one = BuildSystem()
        bs_one.add_stage('one', b_one)
        bs_one.add_stage('two', b_two)

        bs_two = BuildSystem(bs_one)

        self.assertEqual(bs_two.count(), bs_one.count())
        self.assertEqual(bs_two.get_order(), bs_one.get_order())
예제 #4
0
class TestStagesBuildStage(StagesBuildStepTests, TestCase):
    @classmethod
    def setUp(self):
        self.b = BuildStage()
        self.args = [ [1, 2], [2, 3], [1, 5], [8, 9] ]
        self.result = ''.join([ str(i) for i in self.args ])

    def test_running(self, a=None, b=None):
        for arg in self.args:
            self.b.add(dump_args_to_json_file, [arg[0], arg[1]])

        self.b.run()

        with open('t', 'r') as f:
            jsn = f.read()

        self.assertEqual(sorted(self.result), sorted(jsn))

    @classmethod
    def tearDown(self):
        if os.path.exists('t'):
            os.remove('t')
예제 #5
0
    def setUp(self):
        self.bs = BuildSystem()

        self.a = {'a': 1}
        self.b = {'b': 'string'}
        self.c = {'c': 'string' * 4}
        self.d = {'d': 10 * 4}

        self.fn_one = 'one.json'
        self.fn_two = 'two.json'
        self.fn_three = 'three.json'
        self.fn_four = 'four.json'

        job_one = BuildStage()
        job_two = BuildStage()
        job_three = BuildStage()
        job_four = BuildStage()

        job_one.add(dump_args_to_json_file_with_newlines,
                    (self.a, self.b, self.fn_one))
        job_one.add(dump_args_to_json_file_with_newlines,
                    (self.d, self.c, self.fn_one))
        job_one.add(dummy_function, (self.a, self.b))
        job_one.add(dummy_function, (self.a, self.c))

        job_two.add(dump_args_to_json_file_with_newlines,
                    (self.a, self.b, self.fn_two))
        job_two.add(dump_args_to_json_file_with_newlines,
                    (self.c, self.d, self.fn_two))
        job_two.add(dummy_function, (self.a, self.c))
        job_two.add(dummy_function, (self.a, self.d))

        job_three.add(dump_args_to_json_file_with_newlines,
                      (self.c, self.b, self.fn_three))
        job_three.add(dump_args_to_json_file_with_newlines,
                      (self.a, self.d, self.fn_three))
        job_three.add(dummy_function, (self.a, self.b))
        job_three.add(dummy_function, (self.a, self.c))

        job_four.add(dump_args_to_json_file_with_newlines,
                     (self.a, self.a, self.fn_four))
        job_four.add(dump_args_to_json_file_with_newlines,
                     (self.a, self.b, self.fn_four))
        job_four.add(dummy_function, (self.a, self.c))
        job_four.add(dummy_function, (self.a, self.c))

        self.bs.add_stage('one', job_one)
        self.bs.add_stage('two', job_two)
        self.bs.add_stage('three', job_three)
        self.bs.add_stage('four', job_four)
예제 #6
0
    def setUp(self):
        self.bs = BuildSystem()

        self.a = {'a': 1 }
        self.b = {'b': 'string'}
        self.c = {'c': 'string' * 4 }
        self.d = {'d': 10 * 4 }

        self.fn_one = 'one.json'
        self.fn_two = 'two.json'
        self.fn_three = 'three.json'
        self.fn_four = 'four.json'

        job_one = BuildStage()
        job_two = BuildStage()
        job_three = BuildStage()
        job_four = BuildStage()

        job_one.add(dump_args_to_json_file_with_newlines, (self.a, self.b, self.fn_one))
        job_one.add(dump_args_to_json_file_with_newlines, (self.d, self.c, self.fn_one))
        job_one.add(dummy_function, (self.a, self.b))
        job_one.add(dummy_function, (self.a, self.c))

        job_two.add(dump_args_to_json_file_with_newlines, (self.a, self.b, self.fn_two))
        job_two.add(dump_args_to_json_file_with_newlines, (self.c, self.d, self.fn_two))
        job_two.add(dummy_function, (self.a, self.c))
        job_two.add(dummy_function, (self.a, self.d))

        job_three.add(dump_args_to_json_file_with_newlines, (self.c, self.b, self.fn_three))
        job_three.add(dump_args_to_json_file_with_newlines, (self.a, self.d, self.fn_three))
        job_three.add(dummy_function, (self.a, self.b))
        job_three.add(dummy_function, (self.a, self.c))

        job_four.add(dump_args_to_json_file_with_newlines, (self.a, self.a, self.fn_four))
        job_four.add(dump_args_to_json_file_with_newlines, (self.a, self.b, self.fn_four))
        job_four.add(dummy_function, (self.a, self.c))
        job_four.add(dummy_function, (self.a, self.c))

        self.bs.add_stage('one', job_one)
        self.bs.add_stage('two', job_two)
        self.bs.add_stage('three', job_three)
        self.bs.add_stage('four', job_four)
예제 #7
0
    def add_stage(self, name, stage=None, stage_type='stage', strict=None):
        """
        :param string name: The name of a stage.

        :param BuildStage stage: A :class:~stages.BuildSteps` object. Default's
           to ``None``, which has the same effect as
           :meth:~system.BuildSystem.new_stage()`.

        :param string stage_type: Defaults to ``stage``. Either ``sequence`` (or
           ``seq``) or ``stage`` to determine what kind of
           :class`~stages.BuildSteps()` object to instantiate if ``stage`` is
           ``None``

        :param bool strict: Overrides the default
           :attr:`~system.BuildSystem.strict` attribute. When ``True``, prevents
           callers from adding duplicate stages to a :class:~system.BuildSystem`
           object.

        :raises: :exc:`~err.InvalidStage()` in strict mode if ``name`` or
           ``stage`` is malformed.

        Creates a new stage and optionally populates the stage with tasks. Note
        the following behaviors:

        - If ``name`` exists in the current :class:~system.BuildSystem`,
          ``strict`` is ``False``, and ``stage`` is ``None``; then
          :meth:~system.BuildSystem.add_stage()` adds the stage with ``name`` to
          the current :class:~system.BuildSystem` object. This allows you to
          perform the same stage multiple times in one build process.

        - If ```name`` does not exist in the current
          :class:~system.BuildSystem`, and ``stage`` is ``None``,
          :meth:~system.BuildSystem.add_stage()` adds the stage and instantiates
          a new :class`~stages.BuildSteps()` (either
          :class`~stages.BuildSequence()` or :class`~stages.BuildStage()`
          depending on the value of ``stage_type``) object with ``name`` to the
          current :class:~system.BuildSystem` object.

          :meth:~system.BuildSystem.add_stage()` must specify a ``stage_type``
          if ``stage`` is ``None``. When ``strict`` is ``True`` not doing so
          raises an exception.

        - Adds the ``stage`` with the specified :class`~stages.BuildSteps()`
          object to the :class:~system.BuildSystem` object. Raises an exception
          if ``stage`` is not a :class`~stages.BuildSteps()` object.
        """

        if stage is None and stage_type is 'stage':
            stage = BuildStage()
            logger.debug('created new (parallel) stage object')
        elif stage is None and stage_type in ['seq', 'sequence']:
            stage = BuildSequence()
            logger.debug('created new sequence object.')
        elif stage is None and stage_type not in ['stage', 'seq', 'sequence']:
            logger.critical(
                'no default stage object and no valid stage type named {0}.'.
                format(stage_type))
            self._error_or_return(
                msg="must add a BuildSteps object to a build system.",
                exception=InvalidStage,
                strict=strict)
        if isinstance(stage, BuildSteps) is False:
            logger.critical('{0} is not a build step object'.format(name))
            self._error_or_return(
                msg="must add a BuildSteps object to a build system.",
                exception=InvalidStage,
                strict=strict)
        else:
            logger.info('appending well formed stage.')
            self._stages.append(name)
            self.stages[name] = stage

            return True
예제 #8
0
    def setUp(self):
        self.jobs = [ (cpu_count, (1, 2)), (dummy_function, ('str', 'str')) ]
        self.args = [ (1, 2), (2, 3), (1, 'str'), ('str', 'str') ]

        self.b = BuildStage()
        self.bs = BuildStage()
예제 #9
0
 def setUp(self):
     self.b = BuildStage()
     self.args = [ [1, 2], [2, 3], [1, 5], [8, 9] ]
     self.result = ''.join([ str(i) for i in self.args ])