Ticket #23551: test_subcommand_completed.patch
File test_subcommand_completed.patch, 2.1 KB (added by , 10 years ago) |
---|
-
.py
old new 32 32 del os.environ['DJANGO_AUTO_COMPLETE'] 33 33 34 34 def _user_input(self, input_str): 35 """Set the environment and the list of command line arguments. 36 37 This method sets the bash variables $COMP_WORDS and $COMP_CWORD. 38 The former is an array consisting of the individual words in the 39 current command line, the latter is the index of the current 40 cursor position, so in case a word is completed and the cursor is 41 placed after a whitespace, $COMP_CWORD must be incremented by 1: 42 43 * 'django-admin start' -> COMP_CWORD=1 44 * 'django-admin startproject' -> COMP_CWORD=1 45 * 'django-admin startproject ' -> COMP_CWORD=2 46 """ 35 47 os.environ['COMP_WORDS'] = input_str 36 os.environ['COMP_CWORD'] = str(len(input_str.split()) - 1) 37 sys.argv = input_str.split(' ') 48 idx = len(input_str.split(' ')) - 1 # Index of the last word 49 comp_cword = idx + 1 if input_str.endswith(' ') else idx 50 os.environ['COMP_CWORD'] = str(comp_cword) 51 sys.argv = input_str.split() 38 52 39 53 def _run_autocomplete(self): 40 54 util = ManagementUtility(argv=sys.argv) … … 68 82 output = self._run_autocomplete() 69 83 self.assertEqual(output, ['sql sqlall sqlclear sqlcustom sqldropindexes sqlflush sqlindexes sqlmigrate sqlsequencereset']) 70 84 85 def test_completed_subcommand(self): 86 """Show option flags in case a subcommand is completed""" 87 self._user_input('django-admin startproject ') # Trailing whitespace 88 output = self._run_autocomplete() 89 for item in output: 90 self.assertTrue(item.startswith('--')) 91 71 92 def test_help(self): 72 93 "No errors, just an empty list if there are no autocomplete options" 73 94 self._user_input('django-admin help --') … … 88 109 for app_config in apps.get_app_configs() 89 110 if app_config.label.startswith('a')) 90 111 self.assertEqual(output, a_labels) 112