def test_generate_output_dir_command_text(self): obj_info = ScriptInfo(output_dir_script_info, 'output_dir_script', 'output_dir_script.py') obj = CommandGenerator(obj_info) obj._generate_output_dir_command_text(obj_info.required_opts[0]) exp = "output_dir_script.py -p output_dir_script_output" self.assertEqual(obj.command_text, exp) obj_info = ScriptInfo(output_dir_script_info, 'output_dir_script', 'output_dir_script.py') obj = CommandGenerator(obj_info) obj._is_optional = True obj._generate_output_dir_command_text(obj_info.optional_opts[0]) exp = "output_dir_script.py -d output_dir_script_output" self.assertEqual(obj.command_text, exp) obj._is_optional = False self.assertRaises(ValueError, obj._generate_output_dir_command_text, obj_info.required_opts[0])
def test_generate_output_command_text(self): obj_info = ScriptInfo(output_script_info, 'output_script', 'output_script.py') obj = CommandGenerator(obj_info) obj._generate_output_command_text(obj_info.required_opts[0]) exp = "output_script.py -o $output_fp" self.assertEqual(obj.command_text, exp) obj._is_optional = True obj._generate_output_command_text(obj_info.optional_opts[0]) exp = "output_script.py -o $output_fp --new_filepath=$new_filepath" self.assertEqual(obj.command_text, exp)
def test_generate_boolean_command_text(self): obj_info = ScriptInfo(boolean_script_info, 'boolean_script', 'boolean_script.py') obj = CommandGenerator(obj_info) obj._is_optional = True obj._generate_boolean_command_text(obj_info.optional_opts[0]) exp = "boolean_script.py\n#if $true_boolean:\n -t\n#end if\n" self.assertEqual(obj.command_text, exp) obj._generate_boolean_command_text(obj_info.optional_opts[1]) exp = "boolean_script.py\n#if $true_boolean:\n -t\n#end if\n\n#if $false_boolean:\n --false_boolean\n#end if\n" self.assertEqual(obj.command_text, exp)
def test_generate_repeat_command_text(self): obj_info = ScriptInfo(repeat_script_info, 'repeat_script', 'repeat_script.py') obj = CommandGenerator(obj_info) obj._generate_repeat_command_text(obj_info.required_opts[0]) exp = "repeat_script.py\n#def list_dict_to_string(list_dict):\n\t#set $file_list = list_dict[0]['additional_input'].__getattr__('file_name')\n\t#for d in list_dict[1:]:\n\t\t#set $file_list = $file_list + ',' + d['additional_input'].__getattr__('file_name')\n\t#end for\n\t#return $file_list\n#end def\n -i $list_dict_to_string($input_files_input_fps)" self.assertEqual(obj.command_text, exp) obj._is_optional = True obj._generate_repeat_command_text(obj_info.optional_opts[0]) exp = "repeat_script.py\n#def list_dict_to_string(list_dict):\n\t#set $file_list = list_dict[0]['additional_input'].__getattr__('file_name')\n\t#for d in list_dict[1:]:\n\t\t#set $file_list = $file_list + ',' + d['additional_input'].__getattr__('file_name')\n\t#end for\n\t#return $file_list\n#end def\n -i $list_dict_to_string($input_files_input_fps)\n#if $input_files_repeat:\n --repeat=$list_dict_to_string($input_files_repeat)\n#end if\n" self.assertEqual(obj.command_text, exp)
def test_generate_integer_float_command_text(self): obj_info = ScriptInfo(integer_float_script_info, 'int_float_script', 'int_float_script.py') obj = CommandGenerator(obj_info) obj._generate_integer_float_command_text(obj_info.required_opts[0]) exp = "int_float_script.py -i $integer" self.assertEqual(obj.command_text, exp) obj._is_optional = True obj._generate_integer_float_command_text(obj_info.optional_opts[0]) exp = "int_float_script.py -i $integer\n#if $float:\n --float=$float\n#end if\n" self.assertEqual(obj.command_text, exp)
def test_generate_data_select_command_text(self): obj_info = ScriptInfo(data_select_script_info, 'data_select_script', 'data_select_script.py') obj = CommandGenerator(obj_info) obj._generate_data_select_command_text(obj_info.required_opts[0]) exp = 'data_select_script.py --input_fp=$input_fp' self.assertEqual(obj.command_text, exp) obj._is_optional = True obj._generate_data_select_command_text(obj_info.optional_opts[0]) exp = "data_select_script.py --input_fp=$input_fp\n#if str($choice) != 'None':\n -c $choice\n#end if\n" self.assertEqual(obj.command_text, exp)
def test_generate_text_command_text(self): obj_info = ScriptInfo(text_script_info, 'text_script', 'text_script.py') obj = CommandGenerator(obj_info) obj._generate_text_command_text(obj_info.required_opts[0]) exp = 'text_script.py -s $string' self.assertEqual(obj.command_text, exp) obj._is_optional = True obj._generate_text_command_text(obj_info.optional_opts[0]) exp = 'text_script.py -s $string\n#if str($text):\n --text=$text\n#end if\n' self.assertEqual(obj.command_text, exp)
def setUp(self): self.info = ScriptInfo(script_info_example, 'example_script', 'example_script.py') self.obj = CommandGenerator(self.info)
class CommandGeneratorTest(TestCase): def setUp(self): self.info = ScriptInfo(script_info_example, 'example_script', 'example_script.py') self.obj = CommandGenerator(self.info) def test_init(self): self.assertEqual(self.obj.info, self.info) self.assertEqual(self.obj.command_text, 'example_script.py') def test_update(self): self.obj.update() exp = "uncompress_tgz.py -i $input_fp -o example_script_input;\nexample_script.py -i example_script_input -o example_script_output\n#if str($choice_ex) != 'None':\n -c $choice_ex\n#end if\n\n#if $input_files_repeat_ex:\n\n#def list_dict_to_string(list_dict):\n\t#set $file_list = list_dict[0]['additional_input'].__getattr__('file_name')\n\t#for d in list_dict[1:]:\n\t\t#set $file_list = $file_list + ',' + d['additional_input'].__getattr__('file_name')\n\t#end for\n\t#return $file_list\n#end def\n -r $list_dict_to_string($input_files_repeat_ex)\n#end if\n;\ncompress_path.py -i example_script_output -o $output_fp\n" self.assertEqual(self.obj.command_text, exp) def test_generate_text_command_text(self): obj_info = ScriptInfo(text_script_info, 'text_script', 'text_script.py') obj = CommandGenerator(obj_info) obj._generate_text_command_text(obj_info.required_opts[0]) exp = 'text_script.py -s $string' self.assertEqual(obj.command_text, exp) obj._is_optional = True obj._generate_text_command_text(obj_info.optional_opts[0]) exp = 'text_script.py -s $string\n#if str($text):\n --text=$text\n#end if\n' self.assertEqual(obj.command_text, exp) def test_generate_data_select_command_text(self): obj_info = ScriptInfo(data_select_script_info, 'data_select_script', 'data_select_script.py') obj = CommandGenerator(obj_info) obj._generate_data_select_command_text(obj_info.required_opts[0]) exp = 'data_select_script.py --input_fp=$input_fp' self.assertEqual(obj.command_text, exp) obj._is_optional = True obj._generate_data_select_command_text(obj_info.optional_opts[0]) exp = "data_select_script.py --input_fp=$input_fp\n#if str($choice) != 'None':\n -c $choice\n#end if\n" self.assertEqual(obj.command_text, exp) def test_generate_integer_float_command_text(self): obj_info = ScriptInfo(integer_float_script_info, 'int_float_script', 'int_float_script.py') obj = CommandGenerator(obj_info) obj._generate_integer_float_command_text(obj_info.required_opts[0]) exp = "int_float_script.py -i $integer" self.assertEqual(obj.command_text, exp) obj._is_optional = True obj._generate_integer_float_command_text(obj_info.optional_opts[0]) exp = "int_float_script.py -i $integer\n#if $float:\n --float=$float\n#end if\n" self.assertEqual(obj.command_text, exp) def test_generate_boolean_command_text(self): obj_info = ScriptInfo(boolean_script_info, 'boolean_script', 'boolean_script.py') obj = CommandGenerator(obj_info) obj._is_optional = True obj._generate_boolean_command_text(obj_info.optional_opts[0]) exp = "boolean_script.py\n#if $true_boolean:\n -t\n#end if\n" self.assertEqual(obj.command_text, exp) obj._generate_boolean_command_text(obj_info.optional_opts[1]) exp = "boolean_script.py\n#if $true_boolean:\n -t\n#end if\n\n#if $false_boolean:\n --false_boolean\n#end if\n" self.assertEqual(obj.command_text, exp) def test_generate_repeat_command_text(self): obj_info = ScriptInfo(repeat_script_info, 'repeat_script', 'repeat_script.py') obj = CommandGenerator(obj_info) obj._generate_repeat_command_text(obj_info.required_opts[0]) exp = "repeat_script.py\n#def list_dict_to_string(list_dict):\n\t#set $file_list = list_dict[0]['additional_input'].__getattr__('file_name')\n\t#for d in list_dict[1:]:\n\t\t#set $file_list = $file_list + ',' + d['additional_input'].__getattr__('file_name')\n\t#end for\n\t#return $file_list\n#end def\n -i $list_dict_to_string($input_files_input_fps)" self.assertEqual(obj.command_text, exp) obj._is_optional = True obj._generate_repeat_command_text(obj_info.optional_opts[0]) exp = "repeat_script.py\n#def list_dict_to_string(list_dict):\n\t#set $file_list = list_dict[0]['additional_input'].__getattr__('file_name')\n\t#for d in list_dict[1:]:\n\t\t#set $file_list = $file_list + ',' + d['additional_input'].__getattr__('file_name')\n\t#end for\n\t#return $file_list\n#end def\n -i $list_dict_to_string($input_files_input_fps)\n#if $input_files_repeat:\n --repeat=$list_dict_to_string($input_files_repeat)\n#end if\n" self.assertEqual(obj.command_text, exp) def test_generate_output_command_text(self): obj_info = ScriptInfo(output_script_info, 'output_script', 'output_script.py') obj = CommandGenerator(obj_info) obj._generate_output_command_text(obj_info.required_opts[0]) exp = "output_script.py -o $output_fp" self.assertEqual(obj.command_text, exp) obj._is_optional = True obj._generate_output_command_text(obj_info.optional_opts[0]) exp = "output_script.py -o $output_fp --new_filepath=$new_filepath" self.assertEqual(obj.command_text, exp) def test_generate_output_dir_command_text(self): obj_info = ScriptInfo(output_dir_script_info, 'output_dir_script', 'output_dir_script.py') obj = CommandGenerator(obj_info) obj._generate_output_dir_command_text(obj_info.required_opts[0]) exp = "output_dir_script.py -p output_dir_script_output" self.assertEqual(obj.command_text, exp) obj_info = ScriptInfo(output_dir_script_info, 'output_dir_script', 'output_dir_script.py') obj = CommandGenerator(obj_info) obj._is_optional = True obj._generate_output_dir_command_text(obj_info.optional_opts[0]) exp = "output_dir_script.py -d output_dir_script_output" self.assertEqual(obj.command_text, exp) obj._is_optional = False self.assertRaises(ValueError, obj._generate_output_dir_command_text, obj_info.required_opts[0]) def test_generate_input_dir_command_text(self): obj_info = ScriptInfo(input_dir_script_info, 'input_dir_script', 'input_dir_script.py') obj = CommandGenerator(obj_info) obj._generate_input_dir_command_text(obj_info.required_opts[0]) exp = "input_dir_script.py -p input_dir_script_input" self.assertEqual(obj.command_text, exp) obj_info = ScriptInfo(input_dir_script_info, 'input_dir_script', 'input_dir_script.py') obj = CommandGenerator(obj_info) self._is_optional = True obj._generate_input_dir_command_text(obj_info.optional_opts[0]) exp = "input_dir_script.py -d input_dir_script_input" self.assertEqual(obj.command_text, exp) obj._is_optional = False self.assertRaises(ValueError, obj._generate_input_dir_command_text, obj_info.required_opts[0])