def test_masterViewMeters(testConfig): loadedProject = testConfig[-1] template = autor1.TemplateFile(TEMP_FILE) loadedProject.pId = loadedProject.createGrp(autor1.PARENT_GROUP_TITLE, 1)[0] autor1.createSubLRCGroups(loadedProject) autor1.getSrcGrpInfo(loadedProject) autor1.configureApChannels(loadedProject) autor1.createMeterView(loadedProject, template) autor1.createMasterView(loadedProject, template) autor1.createNavButtons(loadedProject, template) for id, srcGrpIndex in loadedProject.masterJoinedIDs: loadedProject.cursor.execute( f"SELECT TargetId, TargetType FROM Controls WHERE JoinedID = {id}") controls = loadedProject.cursor.fetchall() if controls is not None: for TargetId, TargetType in controls: srcGrp = loadedProject.sourceGroups[srcGrpIndex] channelGroupIDs = [] for channel in srcGrp.channelGroups: channelGroupIDs.append(channel.groupId) if TargetType == r1.CONTROLS_TargetType_Group: assert TargetId in channelGroupIDs
def test_hasSubGroups(testConfig): loadedProject = testConfig[-1] loadedProject.pId = loadedProject.createGrp(autor1.PARENT_GROUP_TITLE, 1)[0] autor1.createSubLRCGroups(loadedProject) assert autor1.hasSubGroups(loadedProject) == testConfig[4]
def test_getApStatus(testConfig): loadedProject = testConfig[-1] with pytest.raises(Exception): autor1.getApStatus(loadedProject) loadedProject.pId = loadedProject.createGrp(autor1.PARENT_GROUP_TITLE, 1)[0] autor1.createSubLRCGroups(loadedProject) autor1.getSrcGrpInfo(loadedProject) assert autor1.getApStatus(loadedProject) is testConfig[3]
def main(): dateTimeObj = datetime.now() if not os.path.exists(LOGDIR): os.makedirs(LOGDIR) timestamp = dateTimeObj.strftime("%d-%b-%Y-%H-%M-%S") logfn = LOGDIR + timestamp + "-autor1log.txt" with open(logfn, "w"): pass if not checkFile(logfn): print(f"Could not access {logfn}") logging.basicConfig(filename=logfn, level=logging.INFO) autor1.log.removeHandler(logging.StreamHandler(sys.stdout)) log = logging.getLogger(__name__) def exceptionHandler(type, value, tb): log.exception("Uncaught exception: {0}".format(str(value))) print("Uncaught exception: {0}".format(str(value))) sys.exit(1) # Install exception handler sys.excepthook = exceptionHandler ############################## START ############################## # Clear screen, ensure correct cmd for OS + set CWD if on Mac if platform.system() == "Windows": os.system("cls") else: os.system("clear") try: os.chdir(sys.argv[1] + "/") except: print("Could not get current working directory.") log.info("Sys Args:") for a in sys.argv: log.info(f"{a}") log.info(f"cwd - {os.getcwd()}") ########################################################################################## print("**AutoR1**") projects = [] projects += [ each for each in os.listdir("./") if each.endswith(".dbpr") and "_AUTO" not in each ] print(f"Found {len(projects)} projects in folder.") if not checkFile(TEMP_FILE): print(f"Could not access {TEMP_FILE}") sys.exit(1) else: tempFile = autor1.TemplateFile(TEMP_FILE) status = 0 for projectPath in projects: autoPath = os.path.splitext(projectPath)[0] + "_AUTO.dbpr" copyfile(projectPath, autoPath) if not checkFile(autoPath): print(f"Could not access {autoPath}") status = 1 projFile = r1.ProjectFile(autoPath) if projFile.isInitialised(): autor1.clean(projFile) projFile.pId = projFile.createGrp(autor1.PARENT_GROUP_TITLE, 1)[0] autor1.createSubLRCGroups(projFile) autor1.getSrcGrpInfo(projFile) autor1.configureApChannels(projFile) autor1.createMeterView(projFile, tempFile) autor1.createMasterView(projFile, tempFile) autor1.createNavButtons(projFile, tempFile) autor1.addSubCtoSubL(projFile) print( f"Finished generating views, controls and groups for {autoPath}." ) else: projFile.close() os.remove(autoPath) print( f"Initial setup has not been run for {projectPath}. Open the file in R1 and perform the initial group and view creation process first, save and then re-run AutoR1." ) status = 1 projFile.close() tempFile.close() sys.exit(status)
def test_cleanProjectFile(testConfig): loadedProject = testConfig[-1] template = autor1.TemplateFile(TEMP_FILE) assert type(loadedProject) is r1.ProjectFile assert type(template) is autor1.TemplateFile initGrpCount = loadedProject.getGroupCount() loadedProject.pId = loadedProject.createGrp(autor1.PARENT_GROUP_TITLE, 1)[0] autor1.createSubLRCGroups(loadedProject) autor1.getSrcGrpInfo(loadedProject) autor1.configureApChannels(loadedProject) autor1.createMeterView(loadedProject, template) autor1.createMasterView(loadedProject, template) autor1.createNavButtons(loadedProject, template) queries = [ # Master view f'SELECT * FROM Views WHERE "Name" = "{autor1.MASTER_WINDOW_TITLE}"', # Meter view f'SELECT * FROM Views WHERE "Name" = "{autor1.METER_WINDOW_TITLE}"', # AutoR1 group f'SELECT * FROM Groups WHERE Name = "{autor1.PARENT_GROUP_TITLE}"', # Nav controls f"SELECT * FROM Controls WHERE TargetId = {loadedProject.masterViewId}", # Master view controls f"SELECT * FROM Controls WHERE ViewId = {loadedProject.masterViewId}", # Meter view controls f"SELECT * FROM Controls WHERE ViewId = {loadedProject.meterViewId}", ] for q in queries: loadedProject.cursor.execute(q) assert loadedProject.cursor.fetchone() is not None masterGroups = 0 meterGroups = 0 for groupId in loadedProject.getSourceGroupIds(True): srcGrpType = autor1.getSrcGroupType(loadedProject, groupId) srcGrpType = str(srcGrpType) if int(srcGrpType[3]): # SUBs masterGroups += 1 meterGroups += 1 + int(srcGrpType[1]) if int(srcGrpType[2]): # TOPs masterGroups += 1 meterGroups += 1 + int(srcGrpType[1]) # Point source without SUBs or TOPs if (int(srcGrpType[3]) == 0 and int(srcGrpType[2]) == 0 and int(srcGrpType[0]) == 2): masterGroups += 1 meterGroups += 1 if int(srcGrpType[0]) == 4: # Device only masterGroups += 1 meterGroups += 1 assert len(loadedProject.masterJoinedIDs) == masterGroups assert len(loadedProject.masterJoinedIDs) == testConfig[1] assert len(loadedProject.meterJoinedIDs) == meterGroups assert len(loadedProject.meterJoinedIDs) == testConfig[2] loadedProject.close() copyfile(loadedProject.dirtyPath, loadedProject.cleanPath) cleanProj = r1.ProjectFile(loadedProject.cleanPath) cleanProj.pId = loadedProject.pId autor1.clean(cleanProj) postGrpCount = cleanProj.getGroupCount() assert postGrpCount == initGrpCount for q in queries: cleanProj.cursor.execute(q) assert cleanProj.cursor.fetchone() is None cleanProj.close()