def test_categories_and_order(self): fil = op.join( op.split(bfile)[0], 'schema/examples/test_pretty_print.json') prettystring = bosh.prettyprint(fil) i_tl_descs = prettystring.index("Tool name") i_con_info = prettystring.index("Container Information") i_sugg_res = prettystring.index("Suggested Resources") i_er_codes = prettystring.index("Error Codes") i_inp_grps = prettystring.index("Input Groups") i_pos_args = prettystring.index("positional arguments") i_opt_args = prettystring.index("optional arguments") i_req_args = prettystring.index("required arguments") i_conf_fil = prettystring.index("Config Files") i_out_file = prettystring.index("Output Files") # Fluff asserts for easy debugging self.assertTrue(i_tl_descs < i_con_info) self.assertTrue(i_con_info < i_sugg_res) self.assertTrue(i_sugg_res < i_er_codes) self.assertTrue(i_er_codes < i_inp_grps) self.assertTrue(i_inp_grps < i_pos_args) self.assertTrue(i_pos_args < i_opt_args) self.assertTrue(i_opt_args < i_req_args) self.assertTrue(i_req_args < i_conf_fil) self.assertTrue(i_conf_fil < i_out_file)
def test_input_optionality_separation(self): fil = op.join( op.split(bfile)[0], 'schema/examples/test_pretty_print.json') prettystring = bosh.prettyprint(fil) inputs = prettystring.split("=" * 80)[6].split("arguments:") positional_inputs = inputs[1] optional_inputs = inputs[2] required_inputs = inputs[3] self.assertFalse("Optional: False" in positional_inputs) self.assertFalse("Optional: False" in optional_inputs) self.assertFalse("Optional: True" in required_inputs)
def test_output_config_separation(self): self.maxDiff = None fil = op.join( op.split(bfile)[0], 'schema/examples/test_pretty_print.json') prettystring = bosh.prettyprint(fil) categories = prettystring.split("=" * 80) configs = categories[7] outputs = categories[8] self.assertTrue("Config Files:" in configs) self.assertTrue("Template:" in configs) self.assertTrue("Output Files:" in outputs) self.assertFalse("Template:" in outputs)
def function(descriptor): ''' Returns a function to invoke bosh.execute on a descriptor. args: descriptor: Zenodo id, file name, or JSON string representing a descriptor. name: name of the function to create. Defaults to the tool name in the descriptor. ''' validate(descriptor) descriptor_json = loadJson(descriptor) def f(*args, **kwargs): # Set default mode to 'launch' if len(args) > 0: mode = args[0] else: mode = 'launch' if mode not in ['launch', 'simulate']: mode = 'launch' else: args = args[1:] # Call bosh execute if mode == 'launch': return execute(mode, descriptor, json.dumps(kwargs), *args) if len(kwargs) > 0: return execute(mode, descriptor, '-i', json.dumps(kwargs), *args) return execute(mode, descriptor, *args) f.__name__ = str(descriptor_json['name']) # Documentation doc = [] doc.append(r'''Runs {0} through its Boutiques interface. *args: - mode: 'launch' or 'simulate'. Defaults to 'launch'. - other arguments: will be passed to bosh execute. Examples: '-s', '-x'. See help(bosh.execute) for a complete list. *kwargs: {1} arguments as defined in the Boutiques descriptor, referenced from input ids. Example: {2}='some_value'. See complete list in descriptor help below. '''.format(f.__name__, f.__name__, descriptor_json['inputs'][0]['id'])) doc.append(prettyprint(descriptor)) f.__doc__ = ''.join(doc) return f
def test_doesntcrash(self): fil = op.join( op.split(bfile)[0], 'schema/examples/test_pretty_print.json') prettystring = bosh.prettyprint(fil) self.assertIsInstance(prettystring, string_types)
def test_duplcate_flags(self): fil = op.join(op.split(bfile)[0], 'schema/examples/good_dupFlags.json') prettystring = bosh.prettyprint(fil) self.assertIn("-duplicate", prettystring) self.assertIn("-duplicate_DUP1", prettystring) self.assertIn("-duplicate_DUP2", prettystring)