def test_get_all_casfiles(self): """Test get all casefiles.""" self.settings['casefiles_dir'] = self.get_mocks_dir() + '/casefiles' ldrs = loaders.get_loaders(self.settings) casefiles = itertools.chain(*[ldr() for ldr in ldrs]) casefile_names = sorted([casefile.name() for casefile in casefiles]) expected_casefile_names = sorted(['bang', 'bash', 'pop', 'kelly', 'uname']) depends_on = 'deputy_lib' try: __import__(depends_on) self.assertEqual(casefile_names, expected_casefile_names) except ImportError: warn('Skipping test, deputy_lib is not available.')
def run_casefile(casefile_name, casefile_argv): settings = config.load_config() # TODO: Revisit, super ugly. casefile_loaders = loaders.get_loaders(settings) casefiles = [ldr(casefile_name=casefile_name) for ldr in casefile_loaders] casefiles = chain(*casefiles) casefiles = list(casefiles) if len(casefiles) == 1: casefile = casefiles[0].load() casefile.run(casefile_argv) elif len(casefiles) > 1: raise CasefileConflictError() else: raise CasefileMissingError() pass
def print_available_casefiles(): available_header = 'Available casefiles:\n' available_casefile_format = '{name}\t{doc}' settings = config.load_config() casefile_loaders = loaders.get_loaders(settings) # TODO: Revisit, call to chain here is a bit clunky casefiles = [ldr() for ldr in casefile_loaders] casefiles = chain(*casefiles) print(available_header) for casefile in casefiles: name, doc = casefile.name(), casefile.help() print(available_casefile_format.format(name=name, doc=doc)) # Print newline. print()