def test_simple_dependency(self): # Given mkl = self.package_factory(u"mkl 10.3-1") libgfortran = self.package_factory(u"libgfortran 3.0.0-2") numpy = self.package_factory( u"numpy 1.9.2-1; depends (mkl == 10.3-1, libgfortran ^= 3.0.0)") r_operations = [ # libgfortran sorts before mkl InstallOperation(libgfortran), InstallOperation(mkl), InstallOperation(numpy), ] self.repository.add_package(mkl) self.repository.add_package(libgfortran) self.repository.add_package(numpy) request = Request() request.install(R("numpy")) # When transaction = self.resolve(request) # Then self.assertEqualOperations(transaction.operations, r_operations)
def from_yaml(cls, filename): with open(filename) as fp: data = yaml.load(fp) packages = collections.OrderedDict( parse_package_list(data.get("packages", []))) operations = data.get("request", []) request = Request() for operation in operations: kind = operation["operation"] requirement = Requirement._from_string(operation["requirement"]) getattr(request, kind)(requirement) decisions = data.get("decisions", {}) operations = [] for operation in data.get("transaction", []): if operation["kind"] == "install": operations.append(InstallOperation(operation["package"])) elif operation["kind"] == "update": operations.append( UpdateOperation(operation["from"], operation["to"])) elif operation["kind"] == "remove": operations.append(RemoveOperation(operation["package"])) else: msg = "invalid operation kind {!r}".format(operation["kind"]) raise ValueError(msg) return cls(packages, [remote_repository(data, packages)], installed_repository(data, packages), request, decisions, operations)
def test_multiple_installs(self): # Given mkl = self.package_factory(u"mkl 10.3-1") libgfortran = self.package_factory(u"libgfortran 3.0.0-2") r_operations = [ InstallOperation(libgfortran), InstallOperation(mkl), ] self.repository.add_package(mkl) self.repository.add_package(libgfortran) request = Request() request.install(R("mkl")) request.install(R("libgfortran")) # When transaction = self.resolve(request) # Then self.assertEqualOperations(transaction.operations, r_operations)
def test_upgrade_simple(self): # Given mkl_11_3_1 = P(u"mkl 11.3.1-1") mkl_2017_0_1_1 = P(u"mkl 2017.0.1-1") mkl_2017_0_1_2 = P(u"mkl 2017.0.1-2") numpy_1_10_4 = P(u"numpy 1.10.4-1; depends (mkl ^= 11.3.1)") numpy_1_11_3 = P(u"numpy 1.11.3-1; depends (mkl ^= 2017.0.1)") scipy_0_17_1 = P( u"scipy 0.17.1-1; depends (mkl ^= 11.3.1, numpy ^= 1.10.4)") scipy_0_18_1 = P( u"scipy 0.18.1-1; depends (mkl ^= 2017.0.1, numpy ^= 1.11.3)") self.repository.update([ mkl_11_3_1, mkl_2017_0_1_1, mkl_2017_0_1_2, numpy_1_10_4, numpy_1_11_3, scipy_0_17_1, scipy_0_18_1 ]) self.installed_repository.update( [mkl_11_3_1, numpy_1_10_4, scipy_0_17_1]) r_operations = [ RemoveOperation(scipy_0_17_1), RemoveOperation(numpy_1_10_4), RemoveOperation(mkl_11_3_1), InstallOperation(mkl_2017_0_1_2), InstallOperation(numpy_1_11_3), InstallOperation(scipy_0_18_1), ] # When request = Request() request.upgrade() transaction = self.resolve(request) # Then self.assertEqualOperations(transaction.operations, r_operations)
def test_simple_install(self): # Given mkl = self.package_factory(u"mkl 10.3-1") self.repository.add_package(mkl) r_operations = [InstallOperation(mkl)] request = Request() request.install(R("mkl")) # When transaction = self.resolve(request) # Then self.assertEqualOperations(transaction.operations, r_operations)
def test_no_conflict(self): # Given mkl_2017_0_1_1 = P(u"mkl 2017.0.1-1") numpy_1_11_3 = P(u"numpy 1.11.3-1; depends (mkl ^= 2017.0.1)") scipy_0_18_1 = P( u"scipy 0.18.1-1; depends (mkl ^= 2017.0.1, numpy ^= 1.11.3)") r_operations = [ InstallOperation(mkl_2017_0_1_1), InstallOperation(numpy_1_11_3), InstallOperation(scipy_0_18_1), ] self.repository.update([mkl_2017_0_1_1, numpy_1_11_3, scipy_0_18_1]) request = Request() request.install(R(u"scipy >= 0.18.0")) request.install(R(u"numpy >= 1.10.0")) # When transaction = self.resolve_with_hint(request) # Then self.assertEqualOperations(transaction.operations, r_operations)
def _operations_from_transaction_list(transaction_ops): def P(p): return next(parse_package_list([p]))[1] operations = [] for operation in transaction_ops: if operation["kind"] == "install": operations.append(InstallOperation(P(operation["package"]))) elif operation["kind"] == "update": operations.append( UpdateOperation(P(operation["to"]), P(operation["from"]))) elif operation["kind"] == "remove": operations.append(RemoveOperation(P(operation["package"]))) else: msg = "invalid operation kind {!r}".format(operation["kind"]) raise ValueError(msg) return operations
def test_already_installed(self): # Given mkl1 = self.package_factory(u"mkl 10.3-1") mkl2 = self.package_factory(u"mkl 10.3-2") r_operations = [] self.repository.add_package(mkl1) self.repository.add_package(mkl2) self.installed_repository.add_package(mkl1) # When request = Request() request.install(R("mkl")) transaction = self.resolve(request) # Then self.assertEqualOperations(transaction.operations, r_operations) # Given r_operations = [ RemoveOperation(mkl1), InstallOperation(mkl2), ] r_pretty_operations = [ UpdateOperation(mkl2, mkl1), ] # When request = Request() request.install(R("mkl > 10.3-1")) # When transaction = self.resolve(request) # Then self.assertEqualOperations(transaction.operations, r_operations) self.assertEqualOperations(transaction.pretty_operations, r_pretty_operations)