Пример #1
0
    def test_set_and_get_outdated_step_action_with_contextmanager(self):
        with config.CLIConfig() as cli_config:
            cli_config.set_outdated_step_action(
                config.OutdatedStepAction.CLEAN)

        with config.CLIConfig() as cli_config:
            self.assertThat(cli_config.get_outdated_step_action(),
                            Equals(config.OutdatedStepAction.CLEAN))
Пример #2
0
    def test_set_and_get_sentry_send_always(self):
        cli_config = config.CLIConfig()
        cli_config.set_sentry_send_always(True)
        cli_config.save()

        new_cli_config = config.CLIConfig()
        new_cli_config.load()
        self.assertThat(new_cli_config.get_sentry_send_always(), Equals(True))
Пример #3
0
    def test_set_and_get_outdated_step_action(self):
        cli_config = config.CLIConfig()
        cli_config.set_outdated_step_action(config.OutdatedStepAction.CLEAN)
        cli_config.save()

        new_cli_config = config.CLIConfig()
        new_cli_config.load()
        self.assertThat(new_cli_config.get_outdated_step_action(),
                        Equals(config.OutdatedStepAction.CLEAN))
Пример #4
0
    def test_load_invalid_config(self):
        config_path = os.path.join(
            xdg.BaseDirectory.save_config_path("snapcraft"), "cli.cfg")
        with open(config_path, "w") as f:
            f.write("invalid config")

        cli_config = config.CLIConfig()

        self.assertRaises(SnapcraftInvalidCLIConfigError, cli_config.load)
Пример #5
0
    def test_load_invalid_config(self):
        # The test setup should take care of giving us the proper
        # xdg directory, but there is nothing wrong with caution.
        config_dir = os.path.join('.config', 'snapcraft')
        config_path = os.path.join(config_dir, 'cli.cfg')

        os.makedirs(config_dir)
        with open(config_path, 'w') as f:
            f.write('invalid config')

        cli_config = config.CLIConfig()

        self.assertRaises(SnapcraftInvalidCLIConfigError, cli_config.load)
Пример #6
0
    def run(self, step: steps.Step, part_names=None):
        if part_names:
            self.parts_config.validate(part_names)
            # self.config.all_parts is already ordered, let's not lose that
            # and keep using a list.
            parts = [p for p in self.config.all_parts if p.name in part_names]
            processed_part_names = part_names
        else:
            parts = self.config.all_parts
            processed_part_names = self.config.part_names

        with config.CLIConfig() as cli_config:
            for current_step in step.previous_steps() + [step]:
                if current_step == steps.STAGE:
                    # XXX check only for collisions on the parts that have
                    # already been built --elopio - 20170713
                    pluginhandler.check_for_collisions(self.config.all_parts)
                for part in parts:
                    if self._dirty_reports[part.name][current_step]:
                        self._handle_dirty(
                            part, current_step,
                            self._dirty_reports[part.name][current_step],
                            cli_config)
                    elif current_step in self._steps_run[part.name]:
                        # By default, if a step has already run, don't run it
                        # again. However, automatically clean and re-run the
                        # step if all the following conditions apply:
                        #
                        #   1. The step is the exact step that was requested
                        #      (not an earlier one)
                        #   2. The part was explicitly specified
                        if (part_names and current_step == step and
                                part.name in part_names):
                            getattr(self, '_re{}'.format(
                                current_step.name))(part)
                        else:
                            notify_part_progress(
                                part,
                                'Skipping {}'.format(current_step.name),
                                '(already ran)')
                    else:
                        getattr(self, '_run_{}'.format(
                            current_step.name))(part)
                        self._steps_run[part.name].add(current_step)

        self._create_meta(step, processed_part_names)
Пример #7
0
    def _init_run_states(self):
        steps_run = {}

        for part in self.config.all_parts:
            steps_run[part.name] = set()
            with config.CLIConfig() as cli_config:
                for step in common.COMMAND_ORDER:
                    dirty_report = part.get_dirty_report(step)
                    if dirty_report:
                        self._handle_dirty(part, step, dirty_report,
                                           cli_config)
                    elif not (part.should_step_run(step)):
                        steps_run[part.name].add(step)
                        part.notify_part_progress('Skipping {}'.format(step),
                                                  '(already ran)')

        return steps_run
Пример #8
0
    def run(self, step: steps.Step, part_names=None):
        if part_names:
            self.parts_config.validate(part_names)
            # self.config.all_parts is already ordered, let's not lose that
            # and keep using a list.
            parts = [p for p in self.config.all_parts if p.name in part_names]
            processed_part_names = part_names
        else:
            parts = self.config.all_parts
            processed_part_names = self.config.part_names

        with config.CLIConfig() as cli_config:
            for current_step in step.previous_steps() + [step]:
                if current_step == steps.STAGE:
                    # XXX check only for collisions on the parts that have
                    # already been built --elopio - 20170713
                    pluginhandler.check_for_collisions(self.config.all_parts)
                for part in parts:
                    self._handle_step(part_names, part, step, current_step, cli_config)

        self._create_meta(step, processed_part_names)
Пример #9
0
 def test_contextmanager_with_read_only(self):
     with config.CLIConfig(read_only=True) as cli_config:
         # This should be False
         self.assertThat(cli_config.get_sentry_send_always(), Equals(False))
Пример #10
0
    def test_save_when_read_only(self):
        cli_config = config.CLIConfig(read_only=True)

        self.assertRaises(RuntimeError, cli_config.save)
Пример #11
0
    def test_set_when_read_only(self):
        cli_config = config.CLIConfig(read_only=True)

        self.assertRaises(RuntimeError, cli_config.set_sentry_send_always,
                          True)
Пример #12
0
    def test_set_and_get_sentry_send_always_with_contextmanager(self):
        with config.CLIConfig() as cli_config:
            cli_config.set_sentry_send_always(True)

        with config.CLIConfig() as cli_config:
            self.assertThat(cli_config.get_sentry_send_always(), Equals(True))
Пример #13
0
 def test_non_existing_file_succeeds(self):
     conf = config.CLIConfig()
     self.assertThat(conf.parser.sections(), Equals([]))