def testDeprecatedProduct(self): prod = Product(Eups(), "newprod", noInit=True) self.assert_(prod is not None) self.assert_(newerr.getvalue().find("deprecated") >= 0) self.assertEqual(prod.envarDirName(), "NEWPROD_DIR") self.assertEqual(prod.envarSetupName(), "SETUP_NEWPROD")
def testGetVersions(self): vers = self.stack.getVersions("afw") self.assertEquals(len(vers), 0) vers = self.stack.getVersions("fw") self.assertEquals(len(vers), 1) self.assertEquals(vers[0], '1.2') self.stack.addProduct(Product("fw", "1.3", "Linux", "/opt/sw/Linux/fw/1.3", "none")) vers = self.stack.getVersions("fw") self.assertEquals(len(vers), 2) expected = "1.2 1.3".split() for ver in expected: self.assert_(ver in vers) vers = self.stack.getVersions("fw", "Linux") self.assertEquals(len(vers), 1) self.assertEquals(vers[0], '1.3') self.stack.addProduct(Product("fw", "1.2", "Linux", "/opt/sw/Linux/fw/1.2", "none")) vers = self.stack.getVersions("fw") self.assertEquals(len(vers), 2) for ver in expected: self.assert_(ver in vers) vers = self.stack.getVersions("fw", "Linux") self.assertEquals(len(vers), 2) for ver in expected: self.assert_(ver in vers)
def makeProduct(self, flavor, eupsPathDir=None, dbpath=None): """ create a Product instance for the given flavor. If the product has not been declared for the flavor, a ProductNotFound exception is raised. @param flavor : the desired flavor for the Product. @param eupsPathDir : the product stack path to assume that product is installed under. If the product install directory is a relative path (product.dir), this eupsPathDir will be prepended in the output. If None, no alterations of the product install directory will be done. @param dbpath : the product database directory to store into the output product.db attribute. If None, it will default to eupsPathDir/ups_db; if eupsPathDir is None, the product.db field will not be set. @return Product : a Product instance representing the product data """ if flavor not in self.info: raise ProductNotFound(self.name, self.version, flavor) if eupsPathDir and not dbpath: dbpath = os.path.join(eupsPathDir, "ups_db") info = self.info[flavor] out = Product(self.name, self.version, flavor, info.get("productDir"), info.get("table_file"), db=dbpath, ups_dir=info.get("ups_dir")) out.resolvePaths() return out
def testAddProduct(self): self.assertRaises(TypeError, self.stack.addProduct, "fw", "1.2", "Linux") self.assertRaises(TypeError, self.stack.addProduct, "fw") prod = Product("fw", "1.2") self.assertRaises(UnderSpecifiedProduct, self.stack.addProduct, prod) prod = Product("afw", "1.2", "Darwin", "/opt/sw/Darwin/afw/1.2", "none") self.stack.addProduct(prod) self.assert_(self.stack.hasProduct("afw")) p = self.stack.getProduct("afw", "1.2", "Darwin") self.assertEquals(p.name, prod.name) self.assertEquals(p.version, prod.version) self.assertEquals(p.flavor, prod.flavor) self.assertEquals(p.dir, prod.dir) self.assertEquals(p.tablefile, prod.tablefile) self.assertEquals(p.db, os.path.join(testEupsStack, "ups_db")) self.assertEquals(len(p.tags), 0) self.assertRaises(ProductNotFound, self.stack.getProduct, "afw", "1.2", "Linux") self.assertRaises(ProductNotFound, self.stack.getProduct, "afw", "1.3", "Darwin") self.stack.removeProduct("afw", "Darwin", "1.2") self.assert_(not self.stack.hasProduct("afw")) self.assert_(not self.stack.removeProduct("afw", "Darwin", "1.2"))
def getProduct(self, version, dbpath=None, flavor=None): """ return the Product of the requested version or None if not found. This returned Product's db attribute will be set to None. @param version : the desired version @param dbpath a database path to set on the returned product @param flavor a platform flavor to set on the returned product @return the product description as a Product instance """ try: versdata = self.versions[version] tags = map(lambda item: item[0], filter(lambda x: x[1] == version, self.tags.items())) out = Product( self.name, version, flavor, versdata[0], # the install directory versdata[1], # the table file tags, dbpath) if versdata[2]: out._table = versdata[2] return out except KeyError: raise ProductNotFound(self.name, version)
def makeProduct(self, flavor, eupsPathDir=None, dbpath=None): """ create a Product instance for the given flavor. If the product has not been declared for the flavor, a ProductNotFound exception is raised. @param flavor : the desired flavor for the Product. @param eupsPathDir : the product stack path to assume that product is installed under. If the product install directory is a relative path (product.dir), this eupsPathDir will be prepended in the output. If None, no alterations of the product install directory will be done. @param dbpath : the product database directory to store into the output product.db attribute. If None, it will default to eupsPathDir/ups_db; if eupsPathDir is None, the product.db field will not be set. @return Product : a Product instance representing the product data """ if flavor not in self.info: raise ProductNotFound(self.name, self.version, flavor) if eupsPathDir and not dbpath: dbpath = os.path.join(eupsPathDir, "ups_db") info = self.info[flavor] out = Product(self.name, self.version, flavor, info.get("productDir"), info.get("table_file"), db=dbpath, ups_dir=info.get("ups_dir")) out.resolvePaths() return out
class ProductTestCase(unittest.TestCase): """test the Product container class""" def setUp(self): self.prod = Product("eups", "1.0", dir=testEupsStack) def testToString(self): self.assertEqual(str(self.prod), "Product: eups 1.0") def testInit(self): self.assertEqual(self.prod.name, "eups") self.assertEqual(self.prod.version, "1.0") self.assertEqual(self.prod.dir, testEupsStack) self.assert_(self.prod.db is None) self.assert_(self.prod._table is None) self.assert_(self.prod.tablefile is None) self.assert_(self.prod._prodStack is None) db = os.path.join(os.environ["PWD"], "ups_db") p = Product("eups", "1.0", dir=os.environ["PWD"], tags="stable mine".split(), db=db) self.assertEqual(p.db, db) self.assertEqual(len(p.tags), 2) self.assertIn("stable", p.tags) self.assertIn("mine", p.tags) def testStackRoot(self): self.assert_(self.prod.stackRoot() is None) self.prod.db = os.path.join(self.prod.dir, "ups_db") self.assertEqual(self.prod.stackRoot(), self.prod.dir) def testTableFileName(self): path = self.prod.tableFileName() self.assertEqual(path, os.path.join(testEupsStack, "ups", "eups.table")) self.prod.tablefile = "none" self.assert_(self.prod.tableFileName() is None) self.prod.tablefile = "/tmp/eups.table" self.assertEqual(self.prod.tableFileName(), "/tmp/eups.table") def testTableFileName2(self): self.prod.name = None self.assert_(self.prod.tableFileName() is None) def testTableFileName3(self): self.prod.dir = None self.assert_(self.prod.tableFileName() is None) self.prod.dir = "none" self.assert_(self.prod.tableFileName() is None) def testGetTable(self): self.assertRaises(TableFileNotFound, self.prod.getTable) def tearDown(self): if os.path.exists("test_product.pickle"): os.remove("test_product.pickle")
def testDetectOutOfSync(self): ps1 = ProductStack.fromCache(self.dbpath, "Linux", autosave=False, updateCache=True, verbose=1) ps2 = ProductStack.fromCache(self.dbpath, "Linux", autosave=False, updateCache=True, verbose=1) time.sleep(1) ps1.addProduct(Product("fw", "1.2", "Linux", "/opt/sw/Darwin/fw/1.2", "none")) self.assert_(ps1.cacheIsInSync()) ps1.save() self.assert_(ps1.cacheIsInSync()) self.assert_(not ps2.cacheIsInSync()) ps2.addProduct(Product("fw", "1.2", "Linux", "/opt/sw/Darwin/fw/1.2", "none")) self.assertRaises(CacheOutOfSync, ps2.save)
class ProductTestCase(unittest.TestCase): """test the Product container class""" def setUp(self): self.prod = Product("eups", "1.0", dir=testEupsStack) def testToString(self): self.assertEqual(str(self.prod), "Product: eups 1.0") def testInit(self): self.assertEqual(self.prod.name, "eups") self.assertEqual(self.prod.version, "1.0") self.assertEqual(self.prod.dir, testEupsStack) self.assert_(self.prod.db is None) self.assert_(self.prod._table is None) self.assert_(self.prod.tablefile is None) self.assert_(self.prod._prodStack is None) db = os.path.join(os.environ["PWD"], "ups_db") p = Product("eups", "1.0", dir=os.environ["PWD"], tags="stable mine".split(), db=db) self.assertEqual(p.db, db) self.assertEqual(len(p.tags), 2) self.assertIn("stable", p.tags) self.assertIn("mine", p.tags) def testStackRoot(self): self.assert_(self.prod.stackRoot() is None) self.prod.db = os.path.join(self.prod.dir, "ups_db") self.assertEqual(self.prod.stackRoot(), self.prod.dir) def testTableFileName(self): path = self.prod.tableFileName() self.assertEqual(path, os.path.join(testEupsStack,"ups","eups.table")) self.prod.tablefile = "none" self.assert_(self.prod.tableFileName() is None) self.prod.tablefile = "/tmp/eups.table" self.assertEqual(self.prod.tableFileName(), "/tmp/eups.table") def testTableFileName2(self): self.prod.name = None self.assert_(self.prod.tableFileName() is None) def testTableFileName3(self): self.prod.dir = None self.assert_(self.prod.tableFileName() is None) self.prod.dir = "none" self.assert_(self.prod.tableFileName() is None) def testGetTable(self): self.assertRaises(TableFileNotFound, self.prod.getTable) def tearDown(self): if os.path.exists("test_product.pickle"): os.remove("test_product.pickle")
def testLoadTables(self): tablefile = os.path.join(testEupsStack,"mwi.table") prod = Product("afw", "1.2", "Darwin", "/opt/sw/Darwin/afw/1.2", tablefile) self.stack.addProduct(prod) self.stack.loadTables() prod = self.stack.getProduct("afw", "1.2", "Darwin") self.assert_(prod._table is not None)
def testGetFlavors(self): flavors = self.stack.getFlavors() self.assertEquals(len(flavors), 1) self.assertEquals(flavors[0], "Darwin") prod = Product("afw", "1.2", "Linux", "/opt/sw/Linux/afw/1.2", "none") self.stack.addProduct(prod) flavors = self.stack.getFlavors() self.assertEquals(len(flavors), 2) expected = "Darwin Linux".split() for flav in expected: self.assert_(flav in flavors)
def testRegen(self): ps = ProductStack.fromCache(self.dbpath, "Linux", autosave=True, updateCache=True, verbose=False) self.assert_(not ps.hasProduct("afw")) prod = Product("afw", "1.2", "Darwin", "/opt/sw/Darwin/afw/1.2", "none") ps.addProduct(prod) ps.reload("Linux") self.assert_(ps.hasProduct("afw")) del ps ps = ProductStack.fromCache(self.dbpath, "Linux", autosave=False, updateCache=True, verbose=False) self.assert_(not ps.hasProduct("afw"))
def testPersist(self): fd = file("test_product.pickle", "w") self.prod.persist(fd) fd.close() fd = file("test_product.pickle") p = Product.unpersist(fd) self.assertEqual(self.prod.name, p.name) self.assertEqual(self.prod.version, p.version) self.assertEqual(self.prod.dir, p.dir) self.assertEqual(self.prod.db, p.db) self.assert_(self.prod._table is None) self.assert_(self.prod.tablefile is None)
def testPersist(self): fd = open("test_product.pickle", "wb") self.prod.persist(fd) fd.close() fd = open("test_product.pickle", "rb") p = Product.unpersist(fd) self.assertEqual(self.prod.name, p.name) self.assertEqual(self.prod.version, p.version) self.assertEqual(self.prod.dir, p.dir) self.assertEqual(self.prod.db, p.db) self.assert_(self.prod._table is None) self.assert_(self.prod.tablefile is None)
def testGetProductNames(self): prods = self.stack.getProductNames() self.assertEquals(len(prods), 1) self.assertEquals(prods[0], 'fw') self.stack.addProduct(Product("afw", "1.2", "Linux", "/opt/sw/Linux/afw/1.2", "none")) prods = self.stack.getProductNames() self.assertEquals(len(prods), 2) expected = "fw afw".split() for prod in expected: self.assert_(prod in prods) prods = self.stack.getProductNames("Linux") self.assertEquals(len(prods), 1) self.assertEquals(prods[0], 'afw') self.stack.addProduct(Product("fw", "1.2", "Linux", "/opt/sw/Linux/fw/1.2", "none")) prods = self.stack.getProductNames() self.assertEquals(len(prods), 2) for prod in expected: self.assert_(prod in prods)
def testTags(self): self.assertEquals(len(self.stack.getTags()), 0) prod = Product("afw", "1.2", "Linux", "/opt/sw/Linux/afw/1.2", "none") prod.tags = ["current", "beta"] self.stack.addProduct(prod) self.assertEquals(len(self.stack.getTags()), 2) prod.version = "1.3" prod.tags = [] self.stack.addProduct(prod) tags = self.stack.getTags() self.assertEquals(len(tags), 2) self.assertEquals(tags[0], "beta") self.assertEquals(tags[1], "current") prod = self.stack.getTaggedProduct("afw", "Linux", "stable") self.assert_(prod is None) prod = self.stack.getTaggedProduct("afw", "Linux", "beta") self.assertEqual(prod.version, "1.2") self.assertEqual(prod.flavor, "Linux") self.assertEqual(prod.db, self.dbpath) self.assertRaises(ProductNotFound, self.stack.assignTag, "gurn", "goober", "2") self.stack.assignTag("beta", "afw", "1.3") tags = self.stack.getTags() self.assertEquals(len(tags), 2) self.assertEquals(tags[0], "beta") self.assertEquals(tags[1], "current") prod = self.stack.getTaggedProduct("afw", "Linux", "beta") self.assertEqual(prod.version, "1.3") self.assertEqual(prod.flavor, "Linux") self.assertEqual(prod.db, self.dbpath) self.assert_(not self.stack.unassignTag("gurn", "afw", "Linux")) self.assert_(self.stack.unassignTag("beta", "afw")) tags = self.stack.getTags() self.assertEquals(len(tags), 1) self.assertEquals(tags[0], "current")
def getProduct(self, version, dbpath=None, flavor=None): """ return the Product of the requested version or None if not found. This returned Product's db attribute will be set to None. @param version : the desired version @param dbpath a database path to set on the returned product @param flavor a platform flavor to set on the returned product @return the product description as a Product instance """ try: versdata = self.versions[version] tags = [item[0] for item in [x for x in self.tags.items() if x[1] == version]] out = Product(self.name, version, flavor, versdata[0], # the install directory versdata[1], # the table file tags, dbpath) if versdata[2]: out._table = versdata[2] return out except KeyError: raise ProductNotFound(self.name, version)
def testAutoSave(self): self.assert_(self.stack.saveNeeded()) cache = os.path.join(os.environ["PWD"], ProductStack.persistFilename("Darwin")) if os.path.exists(cache): os.remove(cache) stack = ProductStack(os.path.join(testEupsStack, "ups_db"), os.environ["PWD"], autosave=True) self.assert_(not stack.saveNeeded()) stack.addProduct(Product("fw", "1.2", "Darwin", "/opt/sw/Darwin/fw/1.2", "none")) self.assert_(not stack.saveNeeded()) self.assert_(os.path.exists(cache)) if os.path.exists(cache): os.remove(cache)
def testInit(self): self.assertEqual(self.prod.name, "eups") self.assertEqual(self.prod.version, "1.0") self.assertEqual(self.prod.dir, testEupsStack) self.assert_(self.prod.db is None) self.assert_(self.prod._table is None) self.assert_(self.prod.tablefile is None) self.assert_(self.prod._prodStack is None) db = os.path.join(os.environ["PWD"], "ups_db") p = Product("eups", "1.0", dir=os.environ["PWD"], tags="stable mine".split(), db=db) self.assertEqual(p.db, db) self.assertEqual(len(p.tags), 2) self.assert_("stable" in p.tags) self.assert_("mine" in p.tags)
def testDeclare(self): pdir = self.db._productDir("base") if os.path.isdir(pdir): map( lambda r: os.remove(r), filter(lambda f: os.path.isfile(f), map(lambda p: os.path.join(pdir, p), os.listdir(pdir)))) os.removedirs(pdir) try: self.assert_(not os.path.exists(pdir)) baseidir = os.path.join(testEupsStack, "Linux/base/1.0") base = Product("base", "1.0", "Linux", baseidir, os.path.join(baseidir, "ups/base.table"), tags=["current"]) self.db.declare(base) self.assert_(os.path.isdir(pdir)) self.assert_(os.path.isfile(os.path.join(pdir, "1.0.version"))) self.assert_(os.path.isfile(os.path.join(pdir, "current.chain"))) prods = self.db.findProducts("base") self.assertEquals(len(prods), 1) self.assertEquals(prods[0].name, "base") self.assertEquals(prods[0].version, "1.0") self.assertEquals(prods[0].flavor, "Linux") self.assertEquals(prods[0].dir, baseidir) self.assertEquals(prods[0].tablefile, os.path.join(baseidir, "ups/base.table")) self.assertEquals(len(prods[0].tags), 1) self.assertEquals(prods[0].tags[0], "current") base2 = prods[0].clone() base2.version = "2.0" base2.tags = [] self.db.declare(base2) self.assertEquals( self.db.getTaggedVersion("current", "base", "Linux"), "1.0") base3 = prods[0].clone() base3.version = "3.0" self.db.declare(base3) self.assertEquals( self.db.getTaggedVersion("current", "base", "Linux"), "3.0") self.assertEquals(len(self.db.findProducts("base")), 3) self.db.undeclare(base) self.assertEquals(self.db.findProduct("base", "1.0", "Linux"), None) self.assertEquals(len(self.db.findProducts("base")), 2) self.assert_(not os.path.exists(os.path.join(pdir, "1.0.version"))) self.db.undeclare(base3) self.assertEquals(self.db.findProduct("base", "3.0", "Linux"), None) self.assertEquals(len(self.db.findProducts("base")), 1) self.assert_(not os.path.exists(os.path.join(pdir, "3.0.version"))) self.assertEquals( self.db.getTaggedVersion("current", "base", "Linux"), None) self.assert_( not os.path.exists(os.path.join(pdir, "current.chain"))) self.db.undeclare(base2) self.assertEquals(len(self.db.findProducts("base")), 0) self.assert_(not os.path.exists(pdir)) except: if False: if os.path.isdir(pdir): map( lambda r: os.remove(r), filter( lambda f: os.path.isfile(f), map(lambda p: os.path.join(pdir, p), os.listdir(pdir)))) os.removedirs(pdir) raise
def testProd1(self): pname = "newprod" pver = "2.0" pdir = os.path.join(self.eupsPathDir, "Linux", pname, pver) prod = Product("newprod", "2.0", "Linux", pdir, db=self.dbpath) self.assertEqual(prod.dir, pdir) self.assertEqual(prod.db, self.dbpath) self.assert_(prod.ups_dir is None) self.assert_(prod.tablefile is None) self.assertEqual(prod.tableFileName(), os.path.join(pdir, "ups", pname + ".table")) # test cloning (we'll use this later) clone = prod.clone() self.assertEqual(clone.dir, pdir) self.assertEqual(clone.db, self.dbpath) self.assert_(clone.ups_dir is None) self.assert_(clone.tablefile is None) self.assertEqual(clone.tableFileName(), os.path.join(pdir, "ups", pname + ".table")) # turn to absolute paths prod.resolvePaths() self.assertEqual(prod.dir, pdir) self.assertEqual(prod.db, self.dbpath) self.assertEqual(prod.tablefile, os.path.join(pdir, "ups", pname + ".table")) self.assertEqual(prod.ups_dir, os.path.join(pdir, "ups")) self.assertEqual(prod.tableFileName(), os.path.join(pdir, "ups", pname + ".table")) # turn to relative paths prod.canonicalizePaths() self.assertEqual(prod.dir, "Linux/newprod/2.0") self.assertEqual(prod.db, self.dbpath) self.assertEqual(prod.tablefile, pname + ".table") self.assertEqual(prod.ups_dir, "ups") self.assertEqual(prod.tableFileName(), os.path.join(pdir, "ups", pname + ".table")) # round trip: turn back to absolute paths prod.resolvePaths() self.assertEqual(prod.dir, pdir) self.assertEqual(prod.db, self.dbpath) self.assertEqual(prod.tablefile, os.path.join(pdir, "ups", pname + ".table")) self.assertEqual(prod.ups_dir, os.path.join(pdir, "ups")) self.assertEqual(prod.tableFileName(), os.path.join(pdir, "ups", pname + ".table")) # turn original to relative paths clone.canonicalizePaths() self.assertEqual(clone.dir, "Linux/newprod/2.0") self.assertEqual(clone.db, self.dbpath) self.assertEqual(clone.tablefile, pname + ".table") self.assertEqual(clone.ups_dir, "ups") self.assertEqual(clone.tableFileName(), os.path.join(pdir, "ups", pname + ".table")) # back to absolute paths clone.resolvePaths() self.assertEqual(clone.dir, pdir) self.assertEqual(clone.db, self.dbpath) self.assertEqual(clone.tablefile, os.path.join(pdir, "ups", pname + ".table")) self.assertEqual(clone.ups_dir, os.path.join(pdir, "ups")) self.assertEqual(clone.tableFileName(), os.path.join(pdir, "ups", pname + ".table"))
def testProd2(self): """ Test $UPS_DB transformations """ pname = "newprod" pver = "2.0" pdir = os.path.join(self.eupsPathDir,"Linux",pname,pver) prod = Product("newprod", "2.0", "Linux", pdir, db=self.dbpath, table=os.path.join(self.dbpath,pname,'Linux', pver+".table")) self.assertEqual(prod.dir, pdir) self.assertEqual(prod.db, self.dbpath) self.assertEqual(prod.tablefile, os.path.join(self.dbpath,"newprod/Linux/2.0.table")) self.assert_(prod.ups_dir is None) self.assertEqual(prod.tableFileName(), os.path.join(self.dbpath,"newprod/Linux/2.0.table")) # test cloning (we'll use this later) clone = prod.clone() self.assertEqual(clone.dir, pdir) self.assertEqual(clone.db, self.dbpath) self.assertEqual(clone.tablefile, os.path.join(self.dbpath,"newprod/Linux/2.0.table")) self.assert_(clone.ups_dir is None) self.assertEqual(clone.tableFileName(), os.path.join(self.dbpath,"newprod/Linux/2.0.table")) # turn to absolute paths prod.resolvePaths() self.assertEqual(prod.dir, pdir) self.assertEqual(prod.db, self.dbpath) self.assert_(prod.ups_dir is None) self.assertEqual(prod.tablefile, os.path.join(self.dbpath,"newprod/Linux/2.0.table")) self.assertEqual(prod.tableFileName(), os.path.join(self.dbpath,"newprod/Linux/2.0.table")) prod.canonicalizePaths() self.assertEqual(prod.dir, "Linux/newprod/2.0") self.assertEqual(prod.db, self.dbpath) self.assertEqual(prod.ups_dir, "$UPS_DB/newprod/Linux") self.assertEqual(prod.tablefile, "2.0.table") self.assertEqual(prod.tableFileName(), os.path.join(self.dbpath,"newprod/Linux/2.0.table")) # turn original to relative paths clone.canonicalizePaths() self.assertEqual(clone.dir, "Linux/newprod/2.0") self.assertEqual(clone.db, self.dbpath) self.assertEqual(clone.ups_dir, "$UPS_DB/newprod/Linux") self.assertEqual(clone.tablefile, "2.0.table") self.assertEqual(clone.tableFileName(), os.path.join(self.dbpath,"newprod/Linux/2.0.table")) # back to absolute paths clone.resolvePaths() self.assertEqual(clone.dir, pdir) self.assertEqual(clone.db, self.dbpath) self.assertEqual(clone.ups_dir, os.path.join(self.dbpath,pname,"Linux")) self.assertEqual(clone.tablefile, os.path.join(self.dbpath,"newprod/Linux/2.0.table")) self.assertEqual(clone.tableFileName(), os.path.join(self.dbpath,"newprod/Linux/2.0.table"))
def setUp(self): self.prod = Product("eups", "1.0", dir=testEupsStack)
def setUp(self): self.prod = Product("eups", "1.0", dir=testEupsStack)
def testProd2(self): """ Test $UPS_DB transformations """ pname = "newprod" pver = "2.0" pdir = os.path.join(self.eupsPathDir, "Linux", pname, pver) prod = Product("newprod", "2.0", "Linux", pdir, db=self.dbpath, table=os.path.join(self.dbpath, pname, 'Linux', pver + ".table")) self.assertEqual(prod.dir, pdir) self.assertEqual(prod.db, self.dbpath) self.assertEqual(prod.tablefile, os.path.join(self.dbpath, "newprod/Linux/2.0.table")) self.assert_(prod.ups_dir is None) self.assertEqual(prod.tableFileName(), os.path.join(self.dbpath, "newprod/Linux/2.0.table")) # test cloning (we'll use this later) clone = prod.clone() self.assertEqual(clone.dir, pdir) self.assertEqual(clone.db, self.dbpath) self.assertEqual(clone.tablefile, os.path.join(self.dbpath, "newprod/Linux/2.0.table")) self.assert_(clone.ups_dir is None) self.assertEqual(clone.tableFileName(), os.path.join(self.dbpath, "newprod/Linux/2.0.table")) # turn to absolute paths prod.resolvePaths() self.assertEqual(prod.dir, pdir) self.assertEqual(prod.db, self.dbpath) self.assert_(prod.ups_dir is None) self.assertEqual(prod.tablefile, os.path.join(self.dbpath, "newprod/Linux/2.0.table")) self.assertEqual(prod.tableFileName(), os.path.join(self.dbpath, "newprod/Linux/2.0.table")) prod.canonicalizePaths() self.assertEqual(prod.dir, "Linux/newprod/2.0") self.assertEqual(prod.db, self.dbpath) self.assertEqual(prod.ups_dir, "$UPS_DB/newprod/Linux") self.assertEqual(prod.tablefile, "2.0.table") self.assertEqual(prod.tableFileName(), os.path.join(self.dbpath, "newprod/Linux/2.0.table")) # turn original to relative paths clone.canonicalizePaths() self.assertEqual(clone.dir, "Linux/newprod/2.0") self.assertEqual(clone.db, self.dbpath) self.assertEqual(clone.ups_dir, "$UPS_DB/newprod/Linux") self.assertEqual(clone.tablefile, "2.0.table") self.assertEqual(clone.tableFileName(), os.path.join(self.dbpath, "newprod/Linux/2.0.table")) # back to absolute paths clone.resolvePaths() self.assertEqual(clone.dir, pdir) self.assertEqual(clone.db, self.dbpath) self.assertEqual(clone.ups_dir, os.path.join(self.dbpath, pname, "Linux")) self.assertEqual(clone.tablefile, os.path.join(self.dbpath, "newprod/Linux/2.0.table")) self.assertEqual(clone.tableFileName(), os.path.join(self.dbpath, "newprod/Linux/2.0.table"))
def testProd1(self): pname = "newprod" pver = "2.0" pdir = os.path.join(self.eupsPathDir,"Linux",pname,pver) prod = Product("newprod", "2.0", "Linux", pdir, db=self.dbpath) self.assertEqual(prod.dir, pdir) self.assertEqual(prod.db, self.dbpath) self.assert_(prod.ups_dir is None) self.assert_(prod.tablefile is None) self.assertEqual(prod.tableFileName(), os.path.join(pdir,"ups",pname+".table")) # test cloning (we'll use this later) clone = prod.clone() self.assertEqual(clone.dir, pdir) self.assertEqual(clone.db, self.dbpath) self.assert_(clone.ups_dir is None) self.assert_(clone.tablefile is None) self.assertEqual(clone.tableFileName(), os.path.join(pdir,"ups",pname+".table")) # turn to absolute paths prod.resolvePaths() self.assertEqual(prod.dir, pdir) self.assertEqual(prod.db, self.dbpath) self.assertEqual(prod.tablefile, os.path.join(pdir,"ups",pname+".table")) self.assertEqual(prod.ups_dir, os.path.join(pdir,"ups")) self.assertEqual(prod.tableFileName(), os.path.join(pdir,"ups",pname+".table")) # turn to relative paths prod.canonicalizePaths() self.assertEqual(prod.dir, "Linux/newprod/2.0") self.assertEqual(prod.db, self.dbpath) self.assertEqual(prod.tablefile, pname+".table") self.assertEqual(prod.ups_dir, "ups") self.assertEqual(prod.tableFileName(), os.path.join(pdir,"ups",pname+".table")) # round trip: turn back to absolute paths prod.resolvePaths() self.assertEqual(prod.dir, pdir) self.assertEqual(prod.db, self.dbpath) self.assertEqual(prod.tablefile, os.path.join(pdir,"ups",pname+".table")) self.assertEqual(prod.ups_dir, os.path.join(pdir,"ups")) self.assertEqual(prod.tableFileName(), os.path.join(pdir,"ups",pname+".table")) # turn original to relative paths clone.canonicalizePaths() self.assertEqual(clone.dir, "Linux/newprod/2.0") self.assertEqual(clone.db, self.dbpath) self.assertEqual(clone.tablefile, pname+".table") self.assertEqual(clone.ups_dir, "ups") self.assertEqual(clone.tableFileName(), os.path.join(pdir,"ups",pname+".table")) # back to absolute paths clone.resolvePaths() self.assertEqual(clone.dir, pdir) self.assertEqual(clone.db, self.dbpath) self.assertEqual(clone.tablefile, os.path.join(pdir,"ups",pname+".table")) self.assertEqual(clone.ups_dir, os.path.join(pdir,"ups")) self.assertEqual(clone.tableFileName(), os.path.join(pdir,"ups",pname+".table"))
def setUp(self): self.dbpath = os.path.join(testEupsStack, "ups_db") self.stack = ProductStack(self.dbpath, autosave=False) self.stack.addProduct(Product("fw", "1.2", "Darwin", "/opt/sw/Darwin/fw/1.2", "none"))