def test_quote(self): """Test quote/unquote""" value = 'value with whitespace' txt = '--option=%s' % value # this looks strange, but is correct self.assertEqual(str(txt), '--option=value with whitespace') self.assertEqual(txt, shell_unquote(shell_quote(txt)))
def test_quote(self): """Test quote/unquote""" value = 'value with whitespace' txt = '--option=%s' % value # this looks strange, but is correct self.assertEqual(str(txt), '--option=value with whitespace') self.assertEqual(txt , shell_unquote(shell_quote(txt)))
def test_generate_cmdline(self): """Test the creation of cmd_line args to match options""" self.maxDiff = None ign = r'(^(base|debug|info|quiet)$)|(^ext(?!_(?:strlist|pathlist|add_list_first)))' topt = TestOption1(go_args=[ '--level-level', '--longbase', '--level-prefix-and-dash=YY', shell_unquote("--store='some whitespace'"), '--ext-pathlist=x:y', '--ext-pathliststorenone', '--ext-pathliststorenone2=y2:z2', '--ext-strlist=x,y', '--ext-add-list-first=two,three', '--ext-add-list-flex=a,,b', '--ext-add-pathlist-flex=p1/foo::p4', '--debug', ]) self.assertEqual( topt.options.__dict__, { 'help': None, 'store': 'some whitespace', 'debug': True, 'info': False, 'quiet': False, 'level_level': True, 'longbase': True, 'justatest': True, 'level_longlevel': True, 'store_with_dash': None, 'level_prefix_and_dash': 'YY', # this dict is about destinations 'ignoreconfigfiles': None, 'configfiles': ['/not/a/real/configfile'], 'base': False, 'ext_optional': None, 'ext_extend': None, 'ext_extenddefault': ['zero', 'one'], 'ext_add': None, 'ext_add_default': 'now', 'ext_add_list': None, 'ext_add_list_default': ['now'], 'ext_add_list_first': ['two', 'three', 'now'], 'ext_add_list_flex': ['a', 'x', 'y', 'b'], 'ext_add_pathlist_flex': ['p1/foo', 'p2', 'p3', 'p4'], 'ext_date': None, 'ext_datetime': None, 'ext_optionalchoice': None, 'ext_strlist': ['x', 'y'], 'ext_strtuple': ('x', ), 'ext_pathlist': ['x', 'y'], 'ext_pathliststorenone': ['x'], 'ext_pathliststorenone2': ['y2', 'z2'], 'ext_pathtuple': ('x', ), 'aregexopt': None, }) # cmdline is ordered alphabetically self.assertEqual(topt.generate_cmd_line(ignore=ign), [ '--ext-add-list-first=two,three', '--ext-pathlist=x:y', '--ext-pathliststorenone', '--ext-pathliststorenone2=y2:z2', '--ext-strlist=x,y', '--level-level', '--level-prefix-and-dash=YY', "--store='some whitespace'", ]) all_args = topt.generate_cmd_line(add_default=True, ignore=ign) self.assertEqual([shell_unquote(x) for x in all_args], [ '--ext-add-list-first=two,three', '--ext-pathlist=x:y', '--ext-pathliststorenone', '--ext-pathliststorenone2=y2:z2', '--ext-strlist=x,y', '--justatest', '--level-level', '--level-longlevel', '--level-prefix-and-dash=YY', '--longbase', '--store=some whitespace', ]) topt = TestOption1(go_args=[shell_unquote(x) for x in all_args], go_nosystemexit=True) self.assertEqual(topt.generate_cmd_line(add_default=True, ignore=ign), [ '--ext-add-list-first=two,three', '--ext-pathlist=x:y', '--ext-pathliststorenone', '--ext-pathliststorenone2=y2:z2', '--ext-strlist=x,y', '--justatest', '--level-level', '--level-longlevel', '--level-prefix-and-dash=YY', '--longbase', "--store='some whitespace'", ]) self.assertEqual(all_args, topt.generate_cmd_line(add_default=True, ignore=ign)) topt = TestOption1(go_args=["--aregexopt='^foo.*bar$'"]) print(topt.generate_cmd_line()) self.assertTrue(topt.options.aregexopt is not None) self.assertEqual(topt.options.aregexopt.pattern, "'^foo.*bar$'") self.assertTrue('--aregexopt=\'\'"\'"\'^foo.*bar$\'"\'"\'\'' in topt.generate_cmd_line()) self.assertTrue(topt.options.aregexopt is not None) self.assertEqual(topt.options.aregexopt.pattern, "'^foo.*bar$'")
def test_generate_cmdline(self): """Test the creation of cmd_line args to match options""" self.maxDiff = None ign = r'(^(base|debug|info|quiet)$)|(^ext(?!_(?:strlist|pathlist|add_list_first)))' topt = TestOption1(go_args=['--level-level', '--longbase', '--level-prefix-and-dash=YY', shell_unquote('--store="some whitespace"'), '--ext-pathlist=x:y', '--ext-pathliststorenone', '--ext-pathliststorenone2=y2:z2', '--ext-strlist=x,y', '--ext-add-list-first=two,three', '--ext-add-list-flex=a,,b', '--ext-add-pathlist-flex=p1/foo::p4', '--debug', ]) self.assertEqual(topt.options.__dict__, { 'help': None, 'store': 'some whitespace', 'debug': True, 'info': False, 'quiet': False, 'level_level': True, 'longbase': True, 'justatest': True, 'level_longlevel': True, 'store_with_dash': None, 'level_prefix_and_dash':'YY', # this dict is about destinations 'ignoreconfigfiles': None, 'configfiles': ['/not/a/real/configfile'], 'base': False, 'ext_optional': None, 'ext_extend': None, 'ext_extenddefault': ['zero', 'one'], 'ext_add': None, 'ext_add_default': 'now', 'ext_add_list': None, 'ext_add_list_default': ['now'], 'ext_add_list_first': ['two', 'three', 'now'], 'ext_add_list_flex': ['a','x', 'y', 'b'], 'ext_add_pathlist_flex': ['p1/foo','p2', 'p3', 'p4'], 'ext_date': None, 'ext_datetime': None, 'ext_optionalchoice': None, 'ext_strlist': ['x', 'y'], 'ext_strtuple': ('x',), 'ext_pathlist': ['x', 'y'], 'ext_pathliststorenone': ['x'], 'ext_pathliststorenone2': ['y2', 'z2'], 'ext_pathtuple': ('x',), 'aregexopt': None, }) # cmdline is ordered alphabetically self.assertEqual(topt.generate_cmd_line(ignore=ign), [ '--ext-add-list-first=two,three', '--ext-pathlist=x:y', '--ext-pathliststorenone', '--ext-pathliststorenone2=y2:z2', '--ext-strlist=x,y', '--level-level', '--level-prefix-and-dash=YY', '--store="some whitespace"', ]) all_args = topt.generate_cmd_line(add_default=True, ignore=ign) self.assertEqual([shell_unquote(x) for x in all_args], [ '--ext-add-list-first=two,three', '--ext-pathlist=x:y', '--ext-pathliststorenone', '--ext-pathliststorenone2=y2:z2', '--ext-strlist=x,y', '--justatest', '--level-level', '--level-longlevel', '--level-prefix-and-dash=YY', '--longbase', '--store=some whitespace', ]) topt = TestOption1(go_args=[shell_unquote(x) for x in all_args], go_nosystemexit=True) self.assertEqual(topt.generate_cmd_line(add_default=True, ignore=ign), [ '--ext-add-list-first=two,three', '--ext-pathlist=x:y', '--ext-pathliststorenone', '--ext-pathliststorenone2=y2:z2', '--ext-strlist=x,y', '--justatest', '--level-level', '--level-longlevel', '--level-prefix-and-dash=YY', '--longbase', '--store="some whitespace"', ]) self.assertEqual(all_args, topt.generate_cmd_line(add_default=True, ignore=ign)) topt = TestOption1(go_args=["--aregexopt='^foo.*bar$'"]) self.assertTrue("--aregexopt='^foo.*bar$'" in topt.generate_cmd_line()) self.assertTrue(topt.options.aregexopt is not None) self.assertEqual(topt.options.aregexopt.pattern, "'^foo.*bar$'")
def test_generate_cmdline(self): """Test the creation of cmd_line args to match options""" ign = r'(^(base|debug|info|quiet)$)|(^ext(?!_strlist))' topt = TestOption1(go_args=['--level-level', '--longbase', '--level-prefix-and-dash=YY', shell_unquote('--store="some whitespace"'), '--ext-strlist=x,y', ]) self.assertEqual(topt.options.__dict__, { 'store': 'some whitespace', 'debug': False, 'info':False, 'quiet':False, 'level_level': True, 'longbase': True, 'justatest': True, 'level_longlevel': True, 'store_with_dash':None, 'level_prefix_and_dash':'YY', # this dict is about destinations 'ignoreconfigfiles': None, 'configfiles': None, 'base': False, 'ext_optional': None, 'ext_extend': None, 'ext_date': None, 'ext_extenddefault': ['zero', 'one'], 'ext_datetime': None, 'ext_optionalchoice': None, 'ext_strlist': ['x', 'y'], 'ext_strtuple': ('x',), 'aregexopt': None, }) # cmdline is ordered alphabetically self.assertEqual(topt.generate_cmd_line(ignore=ign), [ '--ext-strlist=x,y', '--level-level', '--level-prefix-and-dash=YY', '--store="some whitespace"', ]) all_args = topt.generate_cmd_line(add_default=True, ignore=ign) self.assertEqual([shell_unquote(x) for x in all_args], [ '--ext-strlist=x,y', '--justatest', '--level-level', '--level-longlevel', '--level-prefix-and-dash=YY', '--longbase', '--store=some whitespace', ]) topt = TestOption1(go_args=[shell_unquote(x) for x in all_args], go_nosystemexit=True) self.assertEqual(topt.generate_cmd_line(add_default=True, ignore=ign), [ '--ext-strlist=x,y', '--justatest', '--level-level', '--level-longlevel', '--level-prefix-and-dash=YY', '--longbase', '--store="some whitespace"', ]) self.assertEqual(all_args, topt.generate_cmd_line(add_default=True, ignore=ign)) topt = TestOption1(go_args=["--aregexopt='^foo.*bar$'"]) self.assertTrue("--aregexopt='^foo.*bar$'" in topt.generate_cmd_line()) self.assertTrue(topt.options.aregexopt is not None) self.assertEqual(topt.options.aregexopt.pattern, "'^foo.*bar$'")