def test_recursiveScan(self): loadedSettings = settings.recursivelyLoadSettingsFiles( ".", ["*.yaml"], ignorePatterns=["skip*"]) names = {cs.caseTitle for cs in loadedSettings} self.assertIn("settings1", names) self.assertIn("settings2", names) self.assertIn("settings3", names) self.assertNotIn("skipSettings", names) loadedSettings = settings.recursivelyLoadSettingsFiles( ".", ["*.yaml"], recursive=False, ignorePatterns=["skip*"]) names = {cs.caseTitle for cs in loadedSettings} self.assertIn("settings1", names) self.assertIn("settings2", names) self.assertNotIn("settings3", names)
def discover(self, rootDir=None, patterns=None, ignorePatterns=None, recursive=True): """ Finds case objects by searching for a pattern of inputs, and adds them to the suite. This searches for CaseSettings input files and loads them to create Case objects. Parameters ---------- rootDir : str, optional root directory to search for settings files patterns : list of str, optional file pattern to use to filter file names ignorePatterns : list of str, optional file patterns to exclude matching file names recursive : bool, optional if True, recursively search for settings files """ csFiles = settings.recursivelyLoadSettingsFiles( rootDir or os.path.abspath(os.getcwd()), patterns or ["*.yaml", "*.xml"], # xml temporary to transistion recursive=recursive, ignorePatterns=ignorePatterns, handleInvalids=False, ) for cs in csFiles: case = armicase.Case(cs=cs, caseSuite=self) case.checkInputs() self.add(case)
def invoke(self): csInstances = settings.recursivelyLoadSettingsFiles( ".", self.args.patterns) messages = (("found", "listing") if self.args.list_setting_files else ("writing", "modifying")) for cs in csInstances: runLog.important("{} settings file {}".format( messages[0], cs.path)) for settingName in self.settingsProvidedOnCommandLine: if cs[settingName] != self.cs[settingName]: runLog.info(" changing `{}` from : {}\n" " {} to -> {}".format( settingName, cs[settingName], " " * (2 + len(settingName)), self.cs[settingName], )) cs[settingName] = self.cs[settingName] # if we are only listing setting files, don't write them; it is OK that we modified them in memory :-) if not self.args.skip_inspection: inspector = operators.getOperatorClassFromSettings( cs).inspector(cs) inspector.run() if not self.args.list_setting_files: cs.writeToYamlFile(cs.path) runLog.important("Finished {} {} settings files.".format( messages[1], len(csInstances)))