def test_loadSchemas(self, tmp_path): dba = DatabaseAccess(tmp_path / "db.json") fw = Warehouse(FASHION_WAREHOUSE_PATH) wh = Warehouse(tmp_path, fw) wh.loadSegments(dba) r = Runway(dba, wh) r.loadSchemas()
def loadWarehouses(self): self.warehouse = None wl = copy.copy(self.properties.warehouses) wl.append(FASHION_WAREHOUSE_PATH.as_posix()) wl.reverse() for wp in wl: self.warehouse = Warehouse(Path(wp), self.warehouse)
def test_create(self, tmp_path): dba = DatabaseAccess(tmp_path / "db.json") fw = Warehouse(FASHION_WAREHOUSE_PATH) wh = Warehouse(tmp_path, fw) wh.loadSegments(dba) r = Runway(dba, wh) assert r is not None
def test_warehouseFallback(self, tmp_path): '''Test the local warehouse refers properly to another warehouse.''' dba = DatabaseAccess(tmp_path / "db.json") fw = Warehouse(FASHION_WAREHOUSE_PATH) lw = Warehouse(tmp_path, fw) coreSeg = lw.loadSegment("fashion.core", dba) assert coreSeg is not None
def test_loadSegments(self, tmp_path): '''Test loading all segments in a warehouse.''' dba = DatabaseAccess(tmp_path / "db.json") wh = Warehouse(tmp_path) newSegName = "custom" wh.newSegment(newSegName, dba) segs = wh.loadSegments(dba) assert len(segs) == 1 assert segs[0].properties.name == newSegName
def test_newSegment(self, tmp_path): '''Test creating a new segment in a warehouse.''' dba = DatabaseAccess(tmp_path / "db.json") newSegName = "custom" wh = Warehouse(tmp_path) wh.newSegment(newSegName, dba) segNames = wh.listSegments() assert len(segNames) == 1 assert segNames[0] == newSegName seg = wh.loadSegment(segNames[0], dba) assert seg is not None
def test_loadModules(self, tmp_path): dba = DatabaseAccess(tmp_path / "db.json") fw = Warehouse(FASHION_WAREHOUSE_PATH) wh = Warehouse(tmp_path, fw) wh.loadSegments(dba) r = Runway(dba, wh) dba.setSingleton('fashion.prime.args', { "force":False, "verbose":True }) mirrorDir = tmp_path / "mirror" mirrorDir.mkdir() dba.setSingleton('fashion.prime.portfolio', { "projectPath":".", "mirrorPath":mirrorDir.as_posix() }) r.loadModules() r.initModules() r.plan() r.execute()
class Portfolio(object): '''Represents a fashion user project.''' def __init__(self, projDir): ''' Initialize a portfolio mapped to the given directory, whether or not the directory actually exists. :param str projDir: where the project is located. ''' self.projectPath = projDir.absolute() self.fashionPath = self.projectPath / 'fashion' self.mirrorPath = self.fashionPath / 'mirror' self.portfolioPath = self.fashionPath / 'portfolio.json' self.fashionDbPath = self.fashionPath / 'database.json' self.mirror = Mirror(self.projectPath, self.mirrorPath) if self.fashionDbPath.exists(): self.load() self.db = DatabaseAccess(self.fashionDbPath) def __setDefaultProperties(self): self.properties = munchify({ "name": "fashion", "defaultSegment": "local", "warehouses": [(self.fashionPath / 'warehouse').as_posix()] }) def loadWarehouses(self): self.warehouse = None wl = copy.copy(self.properties.warehouses) wl.append(FASHION_WAREHOUSE_PATH.as_posix()) wl.reverse() for wp in wl: self.warehouse = Warehouse(Path(wp), self.warehouse) def exists(self): '''Check if this project exists.''' return self.fashionPath.exists() def create(self): '''Create a new portfolio.''' if not self.exists(): self.segments = {} self.__setDefaultProperties() self.fashionPath.mkdir(parents=True, exist_ok=True) (self.fashionPath / "warehouse").mkdir(parents=True, exist_ok=True) self.db = DatabaseAccess(self.fashionDbPath) self.loadWarehouses() self.warehouse.newSegment("local", self.db) self.save() def delete(self): '''Delete an existing project.''' if self.exists(): self.db.close() shutil.rmtree(str(self.fashionPath)) def save(self): '''Save the portfolio.''' with self.portfolioPath.open(mode="w") as pf: pf.write(self.properties.toJSON(sort_keys=True, indent=4)) def load(self): '''Load a portfolio from a file.''' with self.portfolioPath.open(mode='r') as fd: dict = json.loads(fd.read()) self.properties = munchify(dict) self.loadWarehouses() def defaultSegment(self): return self.warehouse.loadSegment(self.defaultSegmentName(), self.db) def defaultSegmentName(self): return self.properties.defaultSegment def setDefaultSegment(self, segname): self.properties.defaultSegment = segname def getRunway(self, tags=None): ''' Get a Runway for this Portfolio. :param boolean verbose: True if the runway should be verbose. :param list tags: a list of tags for the Runway to include. :returns: a Runway object. :rtype: fashion.Runway ''' self.warehouse.loadSegments(self.db) r = Runway(self.db, self.warehouse) r.loadModules() r.initModules() return r def normalizeFilename(self, filename): '''Convert filename to realtive to project directory.''' fn = Path(filename).absolute() return fn.relative_to(self.projectPath)
def test_globalWarehouse(self): '''Test the default global warehouse.''' assert FASHION_WAREHOUSE_PATH is not None fw = Warehouse(FASHION_WAREHOUSE_PATH) globalSegNames = fw.listSegments() assert "fashion.core" in globalSegNames
def test_defaultLocalWarehouse(self, tmp_path): '''Test the default local warehouse.''' lw = Warehouse(tmp_path) localSegNames = lw.listSegments() assert len(localSegNames) == 0