Пример #1
0
 def setup(self):
     test_data = {'some-name': 'some-data'}
     self.expected_out = json.dumps(test_data,
                                    sort_keys=True,
                                    indent=4,
                                    separators=(',', ': '))
     self.out = DataOutput(test_data)
Пример #2
0
 def test_display_file(self):
     with self._caplog.at_level(logging.INFO):
         with patch('builtins.open', create=True) as mock_open:
             file_handle = mock_open.return_value.__enter__.return_value
             DataOutput.display_file('some-file', 'some-message')
             mock_open.assert_called_once_with('some-file')
             file_handle.read.assert_called_once_with()
Пример #3
0
    def process(self):
        """
        Walks through the given info options and provide the requested data
        """
        self.manual = Help()
        if self.command_args.get('help') is True:
            return self.manual.show('kiwi::image::info')

        self.load_xml_description(self.command_args['--description'])

        if self.command_args['--ignore-repos']:
            self.xml_state.delete_repository_sections()

        if self.command_args['--add-repo']:
            for add_repo in self.command_args['--add-repo']:
                (repo_source, repo_type, repo_alias, repo_prio) = \
                    self.quadruple_token(add_repo)
                self.xml_state.add_repository(repo_source, repo_type,
                                              repo_alias, repo_prio)

        self.runtime_checker.check_repositories_configured()

        result = {'image': self.xml_state.xml_data.get_name()}

        if self.command_args['--resolve-package-list']:
            solver = self._setup_solver()
            boostrap_package_list = self.xml_state.get_bootstrap_packages() + \
                [self.xml_state.get_package_manager()]
            package_list = boostrap_package_list + \
                self.xml_state.get_system_packages()
            bootstrap_packages = solver.solve(
                boostrap_package_list, False,
                True if self.xml_state.get_bootstrap_collection_type() is
                'onlyRequired' else False)
            solved_packages = solver.solve(
                self.xml_state.get_system_packages(), False, True if
                self.xml_state.get_system_collection_type() is 'onlyRequired'
                else False)
            solved_packages.update(bootstrap_packages)
            package_info = {}
            for package, metadata in sorted(list(solved_packages.items())):
                if package in package_list:
                    status = 'listed_in_kiwi_description'
                else:
                    status = 'added_by_dependency_solver'
                package_info[package] = {
                    'source': metadata.uri,
                    'installsize_bytes': int(metadata.installsize_bytes),
                    'arch': metadata.arch,
                    'version': metadata.version,
                    'status': status
                }
            result['resolved-packages'] = package_info

        if self.global_args['--color-output']:
            DataOutput(result, style='color').display()
        else:
            DataOutput(result).display()
Пример #4
0
 def setup(self):
     test_data = {
         'some-name': 'some-data'
     }
     self.expected_out = json.dumps(
         test_data, sort_keys=True, indent=4, separators=(',', ': ')
     )
     self.out = DataOutput(test_data)
Пример #5
0
class TestDataOutput:
    def setup(self):
        test_data = {'some-name': 'some-data'}
        self.expected_out = json.dumps(test_data,
                                       sort_keys=True,
                                       indent=4,
                                       separators=(',', ': '))
        self.out = DataOutput(test_data)

    @patch('sys.stdout')
    def test_display(self, mock_stdout):
        self.out.display()
        mock_stdout.write.assert_any_call(self.expected_out)

    @patch('sys.stdout')
    @patch('os.system')
    @patch('kiwi.utils.output.NamedTemporaryFile')
    def test_display_color(self, mock_temp, mock_system, mock_stdout):
        out_file = mock.Mock()
        out_file.name = 'tmpfile'
        mock_temp.return_value = out_file
        self.out.style = 'color'
        self.out.color_json = True
        self.out.display()
        mock_system.assert_called_once_with('cat tmpfile | pjson')

    @patch('sys.stdout')
    @patch('kiwi.logger.log.warning')
    def test_display_color_no_pjson(self, mock_warn, mock_stdout):
        self.out.style = 'color'
        self.out.color_json = False
        self.out.display()
        mock_warn.assert_any_call('pjson for color output not installed')
        mock_warn.assert_any_call('run: pip install pjson')
Пример #6
0
class TestDataOutput:
    @fixture(autouse=True)
    def inject_fixtures(self, caplog):
        self._caplog = caplog

    def setup(self):
        test_data = {
            'some-name': 'some-data'
        }
        self.expected_out = json.dumps(
            test_data, sort_keys=True, indent=4, separators=(',', ': ')
        )
        self.out = DataOutput(test_data)

    def setup_method(self, cls):
        self.setup()

    @patch('sys.stdout')
    def test_display(self, mock_stdout):
        self.out.display()
        mock_stdout.write.assert_any_call(self.expected_out)

    def test_display_file(self):
        with self._caplog.at_level(logging.INFO):
            with patch('builtins.open', create=True) as mock_open:
                file_handle = mock_open.return_value.__enter__.return_value
                DataOutput.display_file('some-file', 'some-message')
                mock_open.assert_called_once_with('some-file')
                file_handle.read.assert_called_once_with()

    @patch('sys.stdout')
    @patch('os.system')
    @patch('kiwi.utils.output.Temporary.new_file')
    def test_display_color(self, mock_temp, mock_system, mock_stdout):
        out_file = mock.Mock()
        out_file.name = 'tmpfile'
        mock_temp.return_value = out_file
        self.out.style = 'color'
        self.out.color_json = True
        self.out.display()
        mock_system.assert_called_once_with(
            'cat tmpfile | pjson'
        )

    @patch('sys.stdout')
    def test_display_color_no_pjson(self, mock_stdout):
        self.out.style = 'color'
        self.out.color_json = False
        with self._caplog.at_level(logging.WARNING):
            self.out.display()
            assert 'pjson for color output not installed' in self._caplog.text
            assert 'run: pip install pjson' in self._caplog.text
Пример #7
0
class TestDataOutput:
    def setup(self):
        test_data = {
            'some-name': 'some-data'
        }
        self.expected_out = json.dumps(
            test_data, sort_keys=True, indent=4, separators=(',', ': ')
        )
        self.out = DataOutput(test_data)

    @patch('sys.stdout')
    def test_display(self, mock_stdout):
        self.out.display()
        mock_stdout.write.assert_any_call(self.expected_out)

    @patch('sys.stdout')
    @patch('os.system')
    @patch('kiwi.utils.output.NamedTemporaryFile')
    def test_display_color(self, mock_temp, mock_system, mock_stdout):
        out_file = mock.Mock()
        out_file.name = 'tmpfile'
        mock_temp.return_value = out_file
        self.out.style = 'color'
        self.out.color_json = True
        self.out.display()
        mock_system.assert_called_once_with(
            'cat tmpfile | pjson'
        )

    @patch('sys.stdout')
    @patch('kiwi.logger.log.warning')
    def test_display_color_no_pjson(self, mock_warn, mock_stdout):
        self.out.style = 'color'
        self.out.color_json = False
        self.out.display()
        mock_warn.assert_any_call(
            'pjson for color output not installed'
        )
        mock_warn.assert_any_call(
            'run: pip install pjson'
        )
Пример #8
0
class TestDataOutput:
    @fixture(autouse=True)
    def inject_fixtures(self, caplog):
        self._caplog = caplog

    def setup(self):
        test_data = {'some-name': 'some-data'}
        self.expected_out = json.dumps(test_data,
                                       sort_keys=True,
                                       indent=4,
                                       separators=(',', ': '))
        self.out = DataOutput(test_data)

    @patch('sys.stdout')
    def test_display(self, mock_stdout):
        self.out.display()
        mock_stdout.write.assert_any_call(self.expected_out)

    @patch('sys.stdout')
    @patch('os.system')
    @patch('kiwi.utils.output.NamedTemporaryFile')
    def test_display_color(self, mock_temp, mock_system, mock_stdout):
        out_file = mock.Mock()
        out_file.name = 'tmpfile'
        mock_temp.return_value = out_file
        self.out.style = 'color'
        self.out.color_json = True
        self.out.display()
        mock_system.assert_called_once_with('cat tmpfile | pjson')

    @patch('sys.stdout')
    def test_display_color_no_pjson(self, mock_stdout):
        self.out.style = 'color'
        self.out.color_json = False
        with self._caplog.at_level(logging.WARNING):
            self.out.display()
            assert 'pjson for color output not installed' in self._caplog.text
            assert 'run: pip install pjson' in self._caplog.text