def setup(self, mock_import_module): self.sat = Sat() self.solver = MagicMock() self.transaction = Mock() self.transaction.newpackages = Mock(return_value=[Mock()]) self.selection = Mock() self.solver.transaction = Mock(return_value=self.transaction) self.sat.pool.Solver = Mock(return_value=self.solver) self.sat.pool.select = Mock(return_value=self.selection) mock_import_module.assert_called_once_with('solv')
def _setup_solver(self): solver = Sat() for xml_repo in self.xml_state.get_repository_sections_used_for_build( ): repo_source = xml_repo.get_source().get_path() repo_user = xml_repo.get_username() repo_secret = xml_repo.get_password() repo_type = xml_repo.get_type() solver.add_repository( SolverRepository(Uri(repo_source, repo_type), repo_user, repo_secret)) return solver
def _setup_solver(self): solver = Sat() for xml_repo in self.xml_state.get_repository_sections_used_for_build(): repo_source = xml_repo.get_source().get_path() repo_user = xml_repo.get_username() repo_secret = xml_repo.get_password() repo_type = xml_repo.get_type() solver.add_repository( SolverRepository( Uri(repo_source, repo_type), repo_user, repo_secret ) ) return solver
def setup(self, mock_import_module): self.sat = Sat() self.solver = mock.MagicMock() self.transaction = mock.Mock() self.transaction.newpackages = mock.Mock(return_value=[mock.Mock()]) self.selection = mock.Mock() self.solver.transaction = mock.Mock(return_value=self.transaction) self.sat.pool.Solver = mock.Mock(return_value=self.solver) self.sat.pool.select = mock.Mock(return_value=self.selection) assert mock_import_module.call_args_list == [ call('solv'), call('solv', 'Pool'), call('solv', 'Selection') ]
def setup(self, mock_import_module): self.sat = Sat() self.solver = mock.MagicMock() self.transaction = mock.Mock() self.transaction.newpackages = mock.Mock( return_value=[mock.Mock()] ) self.selection = mock.Mock() self.solver.transaction = mock.Mock( return_value=self.transaction ) self.sat.pool.Solver = mock.Mock( return_value=self.solver ) self.sat.pool.select = mock.Mock( return_value=self.selection ) mock_import_module.assert_called_once_with('solv')
def _setup_solver(self): solver = Sat() for xml_repo in self.xml_state.get_repository_sections_used_for_build( ): repo_source = xml_repo.get_source().get_path() repo_sourcetype = xml_repo.get_sourcetype() or '' repo_user = xml_repo.get_username() repo_secret = xml_repo.get_password() repo_type = xml_repo.get_type() repo_dist = xml_repo.get_distribution() repo_components = xml_repo.get_components() if not repo_type: repo_type = SolverRepositoryBase( Uri(uri=repo_source, source_type=repo_sourcetype), repo_user, repo_secret).get_repo_type() if repo_type == 'apt-deb': # Debian based repos can be setup for a specific # distribution including a list of individual components. # For each component of the selected distribution extra # repository metadata exists. In such a case we iterate # over the configured dist components and add them as # repository each. dist_type = solver.set_dist_type('deb') if repo_components and repo_dist: for component in repo_components.split(): repo_source_for_component = os.sep.join([ repo_source.rstrip(os.sep), 'dists', repo_dist, component, f'binary-{dist_type.get("arch")}' ]) solver.add_repository( SolverRepository.new( Uri(repo_source_for_component, repo_type, repo_sourcetype), repo_user, repo_secret)) continue solver.add_repository( SolverRepository.new( Uri(repo_source, repo_type, repo_sourcetype), repo_user, repo_secret)) return solver
def test_setup_no_sat_plugin(self, mock_import_module): mock_import_module.side_effect = Exception with raises(KiwiSatSolverPluginError): Sat()
class TestSat: @fixture(autouse=True) def inject_fixtures(self, caplog): self._caplog = caplog @patch('importlib.import_module') def setup(self, mock_import_module): self.sat = Sat() self.solver = MagicMock() self.transaction = Mock() self.transaction.newpackages = Mock(return_value=[Mock()]) self.selection = Mock() self.solver.transaction = Mock(return_value=self.transaction) self.sat.pool.Solver = Mock(return_value=self.solver) self.sat.pool.select = Mock(return_value=self.selection) mock_import_module.assert_called_once_with('solv') self.solv = mock_import_module.return_value self.sat.pool.setarch.assert_called_once_with() self.sat.pool.setarch.reset_mock() @patch('importlib.import_module') def setup_method(self, cls, mock_import_module): self.setup() @patch('importlib.import_module') def test_setup_no_sat_plugin(self, mock_import_module): mock_import_module.side_effect = Exception with raises(KiwiSatSolverPluginError): Sat() def test_set_dist_type_raises(self): Defaults.set_platform_name('x86_64') self.sat.pool.setdisttype.return_value = -1 with raises(KiwiSatSolverPluginError): self.sat.set_dist_type('deb') def test_set_dist_type_deb(self): Defaults.set_platform_name('x86_64') self.sat.pool.setdisttype.return_value = 0 self.sat.set_dist_type('deb') self.sat.pool.setdisttype.assert_called_once_with( self.solv.Pool.DISTTYPE_DEB) self.sat.pool.setarch.assert_called_once_with('amd64') def test_add_repository(self): solver_repository = Mock() solver_repository.uri.uri = 'some-uri' solvable = Mock() solver_repository.create_repository_solvable.return_value = solvable pool_repository = Mock() self.sat.pool.add_repo.return_value = pool_repository self.sat.add_repository(solver_repository) solver_repository.create_repository_solvable.assert_called_once_with() self.sat.pool.add_repo.assert_called_once_with('some-uri') pool_repository.add_solv.assert_called_once_with(solvable) self.sat.pool.addfileprovides.assert_called_once_with() self.sat.pool.createwhatprovides.assert_called_once_with() @patch.object(Sat, '_setup_jobs') def test_solve_has_problems(self, mock_setup_jobs): packages = ['vim'] problem = Mock() problem.id = 42 info = Mock() info.problemstr = Mock(return_value='some-problem') findproblemrule = Mock() findproblemrule.info = Mock(return_value=info) problem.findproblemrule.return_value = findproblemrule option = Mock() option.str = Mock(return_value='some-option') solution = Mock() solution.id = 42 solution.elements = Mock(return_value=[option]) problem.solutions.return_value = [solution] self.solver.solve = Mock(return_value=[problem]) with raises(KiwiSatSolverJobProblems): self.sat.solve(packages) def test_solve_package_not_found_and_skipped(self): packages = ['vim'] self.solver.solve = Mock(return_value=None) self.sat.solv.Selection.SELECTION_PROVIDES = 0 self.selection.flags = 0 self.selection.isempty = Mock(return_value=True) with self._caplog.at_level(logging.INFO): self.sat.solve(packages, skip_missing=True) assert '--> Package vim not found: skipped' in self._caplog.text def test_solve_package_not_found_raises(self): packages = ['vim'] self.solver.solve = Mock(return_value=None) self.selection.isempty = Mock(return_value=True) with raises(KiwiSatSolverJobError): self.sat.solve(packages) def test_solve(self): packages = ['vim'] self.solver.solve = Mock(return_value=None) self.selection.isempty = Mock(return_value=False) self.selection.jobs = Mock(return_value=packages) self.sat.solve(packages) self.solver.solve.assert_called_once_with(['vim']) self.solver.transaction.assert_called_once_with() def test_solve_with_capabilities(self): packages = ['kernel-base'] self.solver.solve = Mock(return_value=None) self.sat.solv.Selection.SELECTION_PROVIDES = 1 self.selection.flags = 1 self.selection.isempty = Mock(return_value=False) self.selection.jobs = Mock(return_value=packages) with self._caplog.at_level(logging.INFO): self.sat.solve(packages) assert '--> Using capability match for kernel-base' in \ self._caplog.text
class TestSat(object): @patch('importlib.import_module') def setup(self, mock_import_module): self.sat = Sat() self.solver = mock.MagicMock() self.transaction = mock.Mock() self.transaction.newpackages = mock.Mock( return_value=[mock.Mock()] ) self.selection = mock.Mock() self.solver.transaction = mock.Mock( return_value=self.transaction ) self.sat.pool.Solver = mock.Mock( return_value=self.solver ) self.sat.pool.select = mock.Mock( return_value=self.selection ) mock_import_module.assert_called_once_with('solv') @patch('importlib.import_module') @raises(KiwiSatSolverPluginError) def test_setup_no_sat_plugin(self, mock_import_module): mock_import_module.side_effect = Exception Sat() def test_add_repository(self): solver_repository = mock.Mock() solver_repository.uri.uri = 'some-uri' solvable = mock.Mock() solver_repository.create_repository_solvable.return_value = solvable pool_repository = mock.Mock() self.sat.pool.add_repo.return_value = pool_repository self.sat.add_repository(solver_repository) solver_repository.create_repository_solvable.assert_called_once_with() self.sat.pool.add_repo.assert_called_once_with('some-uri') pool_repository.add_solv.assert_called_once_with(solvable) self.sat.pool.addfileprovides.assert_called_once_with() self.sat.pool.createwhatprovides.assert_called_once_with() @raises(KiwiSatSolverJobProblems) @patch.object(Sat, '_setup_jobs') def test_solve_has_problems(self, mock_setup_jobs): packages = ['vim'] problem = mock.Mock() problem.id = 42 info = mock.Mock() info.problemstr = mock.Mock( return_value='some-problem' ) findproblemrule = mock.Mock() findproblemrule.info = mock.Mock( return_value=info ) problem.findproblemrule.return_value = findproblemrule option = mock.Mock() option.str = mock.Mock( return_value='some-option' ) solution = mock.Mock() solution.id = 42 solution.elements = mock.Mock( return_value=[option] ) problem.solutions.return_value = [solution] self.solver.solve = mock.Mock( return_value=[problem] ) self.sat.solve(packages) @patch('kiwi.logger.log.info') def test_solve_package_not_found_and_skipped(self, mock_log_info): packages = ['vim'] self.solver.solve = mock.Mock( return_value=None ) self.sat.solv.Selection.SELECTION_PROVIDES = 0 self.selection.flags = mock.Mock( return_value=0 ) self.selection.isempty = mock.Mock( return_value=True ) self.sat.solve(packages, skip_missing=True) mock_log_info.assert_called_once_with( '--> Package vim not found: skipped' ) @raises(KiwiSatSolverJobError) def test_solve_package_not_found_raises(self): packages = ['vim'] self.solver.solve = mock.Mock( return_value=None ) self.selection.isempty = mock.Mock( return_value=True ) self.sat.solve(packages) def test_solve(self): packages = ['vim'] self.solver.solve = mock.Mock( return_value=None ) self.selection.isempty = mock.Mock( return_value=False ) self.selection.jobs = mock.Mock( return_value=packages ) self.sat.solve(packages) self.solver.solve.assert_called_once_with(['vim']) self.solver.transaction.assert_called_once_with() @patch('kiwi.logger.log.info') def test_solve_with_capabilities(self, mock_log_info): packages = ['kernel-base'] self.solver.solve = mock.Mock( return_value=None ) self.sat.solv.Selection.SELECTION_PROVIDES = 1 self.selection.flags = mock.Mock( return_value=1 ) self.selection.isempty = mock.Mock( return_value=False ) self.selection.jobs = mock.Mock( return_value=packages ) self.sat.solve(packages) mock_log_info.assert_called_once_with( '--> Using capability match for kernel-base' )
def test_setup_no_sat_plugin(self, mock_import_module): mock_import_module.side_effect = Exception Sat()
class TestSat(object): @patch('importlib.import_module') def setup(self, mock_import_module): self.sat = Sat() self.solver = mock.MagicMock() self.transaction = mock.Mock() self.transaction.newpackages = mock.Mock(return_value=[mock.Mock()]) self.selection = mock.Mock() self.solver.transaction = mock.Mock(return_value=self.transaction) self.sat.pool.Solver = mock.Mock(return_value=self.solver) self.sat.pool.select = mock.Mock(return_value=self.selection) assert mock_import_module.call_args_list == [ call('solv'), call('solv', 'Pool'), call('solv', 'Selection') ] @patch('importlib.import_module') @raises(KiwiSatSolverPluginError) def test_setup_no_sat_plugin(self, mock_import_module): mock_import_module.side_effect = Exception Sat() def test_add_repository(self): solver_repository = mock.Mock() solver_repository.uri.uri = 'some-uri' solvable = mock.Mock() solver_repository.create_repository_solvable.return_value = solvable pool_repository = mock.Mock() self.sat.pool.add_repo.return_value = pool_repository self.sat.add_repository(solver_repository) solver_repository.create_repository_solvable.assert_called_once_with() self.sat.pool.add_repo.assert_called_once_with('some-uri') pool_repository.add_solv.assert_called_once_with(solvable) self.sat.pool.addfileprovides.assert_called_once_with() self.sat.pool.createwhatprovides.assert_called_once_with() @raises(KiwiSatSolverJobProblems) @patch.object(Sat, '_setup_jobs') def test_solve_has_problems(self, mock_setup_jobs): packages = ['vim'] problem = mock.Mock() problem.id = 42 info = mock.Mock() info.problemstr = mock.Mock(return_value='some-problem') findproblemrule = mock.Mock() findproblemrule.info = mock.Mock(return_value=info) problem.findproblemrule.return_value = findproblemrule option = mock.Mock() option.str = mock.Mock(return_value='some-option') solution = mock.Mock() solution.id = 42 solution.elements = mock.Mock(return_value=[option]) problem.solutions.return_value = [solution] self.solver.solve = mock.Mock(return_value=[problem]) self.sat.solve(packages) @patch('kiwi.logger.log.info') def test_solve_package_not_found_and_skipped(self, mock_log_info): packages = ['vim'] self.solver.solve = mock.Mock(return_value=None) self.selection.isempty = mock.Mock(return_value=True) self.sat.solve(packages, skip_missing=True) mock_log_info.assert_called_once_with( '--> Package vim not found: skipped') @raises(KiwiSatSolverJobError) def test_solve_package_not_found_raises(self): packages = ['vim'] self.solver.solve = mock.Mock(return_value=None) self.selection.isempty = mock.Mock(return_value=True) self.sat.solve(packages) def test_solve(self): packages = ['vim'] self.solver.solve = mock.Mock(return_value=None) self.selection.isempty = mock.Mock(return_value=False) self.selection.jobs = mock.Mock(return_value=packages) self.sat.solve(packages) self.solver.solve.assert_called_once_with(['vim']) self.solver.transaction.assert_called_once_with()
class TestSat: @patch('importlib.import_module') def setup(self, mock_import_module): self.sat = Sat() self.solver = MagicMock() self.transaction = Mock() self.transaction.newpackages = Mock(return_value=[Mock()]) self.selection = Mock() self.solver.transaction = Mock(return_value=self.transaction) self.sat.pool.Solver = Mock(return_value=self.solver) self.sat.pool.select = Mock(return_value=self.selection) mock_import_module.assert_called_once_with('solv') @patch('importlib.import_module') def test_setup_no_sat_plugin(self, mock_import_module): mock_import_module.side_effect = Exception with raises(KiwiSatSolverPluginError): Sat() def test_add_repository(self): solver_repository = Mock() solver_repository.uri.uri = 'some-uri' solvable = Mock() solver_repository.create_repository_solvable.return_value = solvable pool_repository = Mock() self.sat.pool.add_repo.return_value = pool_repository self.sat.add_repository(solver_repository) solver_repository.create_repository_solvable.assert_called_once_with() self.sat.pool.add_repo.assert_called_once_with('some-uri') pool_repository.add_solv.assert_called_once_with(solvable) self.sat.pool.addfileprovides.assert_called_once_with() self.sat.pool.createwhatprovides.assert_called_once_with() @patch.object(Sat, '_setup_jobs') def test_solve_has_problems(self, mock_setup_jobs): packages = ['vim'] problem = Mock() problem.id = 42 info = Mock() info.problemstr = Mock(return_value='some-problem') findproblemrule = Mock() findproblemrule.info = Mock(return_value=info) problem.findproblemrule.return_value = findproblemrule option = Mock() option.str = Mock(return_value='some-option') solution = Mock() solution.id = 42 solution.elements = Mock(return_value=[option]) problem.solutions.return_value = [solution] self.solver.solve = Mock(return_value=[problem]) with raises(KiwiSatSolverJobProblems): self.sat.solve(packages) @patch('kiwi.logger.log.info') def test_solve_package_not_found_and_skipped(self, mock_log_info): packages = ['vim'] self.solver.solve = Mock(return_value=None) self.sat.solv.Selection.SELECTION_PROVIDES = 0 self.selection.flags = Mock(return_value=0) self.selection.isempty = Mock(return_value=True) self.sat.solve(packages, skip_missing=True) mock_log_info.assert_called_once_with( '--> Package vim not found: skipped') def test_solve_package_not_found_raises(self): packages = ['vim'] self.solver.solve = Mock(return_value=None) self.selection.isempty = Mock(return_value=True) with raises(KiwiSatSolverJobError): self.sat.solve(packages) def test_solve(self): packages = ['vim'] self.solver.solve = Mock(return_value=None) self.selection.isempty = Mock(return_value=False) self.selection.jobs = Mock(return_value=packages) self.sat.solve(packages) self.solver.solve.assert_called_once_with(['vim']) self.solver.transaction.assert_called_once_with() @patch('kiwi.logger.log.info') def test_solve_with_capabilities(self, mock_log_info): packages = ['kernel-base'] self.solver.solve = Mock(return_value=None) self.sat.solv.Selection.SELECTION_PROVIDES = 1 self.selection.flags = Mock(return_value=1) self.selection.isempty = Mock(return_value=False) self.selection.jobs = Mock(return_value=packages) self.sat.solve(packages) mock_log_info.assert_called_once_with( '--> Using capability match for kernel-base')
class TestSat: @fixture(autouse=True) def inject_fixtures(self, caplog): self._caplog = caplog @patch('importlib.import_module') def setup(self, mock_import_module): self.sat = Sat() self.solver = MagicMock() self.transaction = Mock() self.transaction.newpackages = Mock(return_value=[Mock()]) self.selection = Mock() self.solver.transaction = Mock(return_value=self.transaction) self.sat.pool.Solver = Mock(return_value=self.solver) self.sat.pool.select = Mock(return_value=self.selection) mock_import_module.assert_called_once_with('solv') self.solv = mock_import_module.return_value self.sat.pool.setarch.assert_called_once_with() self.sat.pool.setarch.reset_mock() @patch('importlib.import_module') def test_setup_no_sat_plugin(self, mock_import_module): mock_import_module.side_effect = Exception with raises(KiwiSatSolverPluginError): Sat() @patch('platform.machine') def test_set_dist_type_raises(self, mock_platform_machine): mock_platform_machine.return_value = 'x86_64' self.sat.pool.setdisttype.return_value = -1 with raises(KiwiSatSolverPluginError): self.sat.set_dist_type('deb') @patch('platform.machine') def test_set_dist_type_deb(self, mock_platform_machine): mock_platform_machine.return_value = 'x86_64' self.sat.pool.setdisttype.return_value = 0 self.sat.set_dist_type('deb') self.sat.pool.setdisttype.assert_called_once_with( self.solv.Pool.DISTTYPE_DEB) self.sat.pool.setarch.assert_called_once_with('amd64') def test_add_repository(self): solver_repository = Mock() solver_repository.uri.uri = 'some-uri' solvable = Mock() solver_repository.create_repository_solvable.return_value = solvable pool_repository = Mock() self.sat.pool.add_repo.return_value = pool_repository self.sat.add_repository(solver_repository) solver_repository.create_repository_solvable.assert_called_once_with() self.sat.pool.add_repo.assert_called_once_with('some-uri') pool_repository.add_solv.assert_called_once_with(solvable) self.sat.pool.addfileprovides.assert_called_once_with() self.sat.pool.createwhatprovides.assert_called_once_with() @patch.object(Sat, '_setup_jobs') def test_solve_has_problems(self, mock_setup_jobs): packages = ['vim'] problem = Mock() problem.id = 42 info = Mock() info.problemstr = Mock(return_value='some-problem') findproblemrule = Mock() findproblemrule.info = Mock(return_value=info) problem.findproblemrule.return_value = findproblemrule option = Mock() option.str = Mock(return_value='some-option') solution = Mock() solution.id = 42 solution.elements = Mock(return_value=[option]) problem.solutions.return_value = [solution] self.solver.solve = Mock(return_value=[problem]) with raises(KiwiSatSolverJobProblems): self.sat.solve(packages) def test_solve_package_not_found_and_skipped(self): packages = ['vim'] self.solver.solve = Mock(return_value=None) self.sat.solv.Selection.SELECTION_PROVIDES = 0 self.selection.flags = 0 self.selection.isempty = Mock(return_value=True) with self._caplog.at_level(logging.INFO): self.sat.solve(packages, skip_missing=True) assert '--> Package vim not found: skipped' in self._caplog.text def test_solve_package_not_found_raises(self): packages = ['vim'] self.solver.solve = Mock(return_value=None) self.selection.isempty = Mock(return_value=True) with raises(KiwiSatSolverJobError): self.sat.solve(packages) def test_solve_apt_get(self): # There is a special handling for apt-get. In kiwi the # package manager for debian based distros is selected # by the name apt-get. That name is added to the package # list, but apt-get does not really exist in Debian based # distros. The name of the package manager from a packaging # perspective is just: apt not apt-get. We should change # this in the schema and code in kiwi. But so far we # have the hack here packages = ['apt-get'] self.solver.solve = Mock(return_value=None) self.selection.isempty = Mock(return_value=False) self.selection.jobs = Mock(return_value=packages) self.sat.solve(packages) selection_name = self.solv.Selection.SELECTION_NAME selection_provides = self.solv.Selection.SELECTION_PROVIDES self.sat.pool.select.assert_called_once_with( 'apt', selection_name | selection_provides) def test_solve(self): packages = ['vim'] self.solver.solve = Mock(return_value=None) self.selection.isempty = Mock(return_value=False) self.selection.jobs = Mock(return_value=packages) self.sat.solve(packages) self.solver.solve.assert_called_once_with(['vim']) self.solver.transaction.assert_called_once_with() def test_solve_with_capabilities(self): packages = ['kernel-base'] self.solver.solve = Mock(return_value=None) self.sat.solv.Selection.SELECTION_PROVIDES = 1 self.selection.flags = 1 self.selection.isempty = Mock(return_value=False) self.selection.jobs = Mock(return_value=packages) with self._caplog.at_level(logging.INFO): self.sat.solve(packages) assert '--> Using capability match for kernel-base' in \ self._caplog.text