Mercurial > p > roundup > code
comparison roundup/admin.py @ 7392:bd6523c84a95
Fix test failure caused by making genconfig trackerless
When I removed the need to have a tracker for genconfig, I broke a
couple of tests. The breakage was hidden by a bad workflow.
This change allows the tests to pass and refactors reporting of
UsageError exceptions in admin.py.
It also adds a test for failure in install command as there is a test
case for it and this test tests the refactor.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 24 May 2023 11:25:47 -0400 |
| parents | 6480443c2607 |
| children | 312d52305583 |
comparison
equal
deleted
inserted
replaced
| 7391:531ca3b94b68 | 7392:bd6523c84a95 |
|---|---|
| 1918 <filename>. Use current settings from existing roundup | 1918 <filename>. Use current settings from existing roundup |
| 1919 tracker in tracker home. | 1919 tracker in tracker home. |
| 1920 """ | 1920 """ |
| 1921 self.do_genconfig(args, update=True) | 1921 self.do_genconfig(args, update=True) |
| 1922 | 1922 |
| 1923 def usageError_feedback(self, message, function): | |
| 1924 print(_('Error: %s') % message) | |
| 1925 print() | |
| 1926 print(function.__doc__) | |
| 1927 return 1 | |
| 1928 | |
| 1923 def run_command(self, args): | 1929 def run_command(self, args): |
| 1924 """Run a single command | 1930 """Run a single command |
| 1925 """ | 1931 """ |
| 1926 command = args[0] | 1932 command = args[0] |
| 1927 | 1933 |
| 1935 if command == 'morehelp': | 1941 if command == 'morehelp': |
| 1936 self.do_help(['help']) | 1942 self.do_help(['help']) |
| 1937 self.help_commands() | 1943 self.help_commands() |
| 1938 self.help_all() | 1944 self.help_all() |
| 1939 return 0 | 1945 return 0 |
| 1940 if command == 'templates': | |
| 1941 return self.do_templates(args[1:]) | |
| 1942 return 0 | |
| 1943 if command == 'genconfig': | |
| 1944 return self.do_genconfig(args[1:]) | |
| 1945 return 0 | |
| 1946 | 1946 |
| 1947 # figure what the command is | 1947 # figure what the command is |
| 1948 try: | 1948 try: |
| 1949 functions = self.commands.get(command) | 1949 functions = self.commands.get(command) |
| 1950 except KeyError: | 1950 except KeyError: |
| 1959 {'command': command, | 1959 {'command': command, |
| 1960 'list': ', '.join([i[0] for i in functions])}) | 1960 'list': ', '.join([i[0] for i in functions])}) |
| 1961 return 1 | 1961 return 1 |
| 1962 command, function = functions[0] | 1962 command, function = functions[0] |
| 1963 | 1963 |
| 1964 if command in ['genconfig', 'templates']: | |
| 1965 try: | |
| 1966 ret = function(args[1:]) | |
| 1967 return ret | |
| 1968 except UsageError as message: # noqa F841 | |
| 1969 return self.usageError_feedback(message, function) | |
| 1970 | |
| 1964 # make sure we have a tracker_home | 1971 # make sure we have a tracker_home |
| 1965 while not self.tracker_home: | 1972 while not self.tracker_home: |
| 1966 if not self.force: | 1973 if not self.force: |
| 1967 self.tracker_home = self.my_input(_('Enter tracker home: ')).strip() | 1974 self.tracker_home = self.my_input(_('Enter tracker home: ')).strip() |
| 1968 else: | 1975 else: |
| 1971 # before we open the db, we may be doing an install or init | 1978 # before we open the db, we may be doing an install or init |
| 1972 if command == 'initialise': | 1979 if command == 'initialise': |
| 1973 try: | 1980 try: |
| 1974 return self.do_initialise(self.tracker_home, args) | 1981 return self.do_initialise(self.tracker_home, args) |
| 1975 except UsageError as message: # noqa: F841 | 1982 except UsageError as message: # noqa: F841 |
| 1976 print(_('Error: %(message)s') % locals()) | 1983 return self.usageError_feedback(message, function) |
| 1977 return 1 | |
| 1978 elif command == 'install': | 1984 elif command == 'install': |
| 1979 try: | 1985 try: |
| 1980 return self.do_install(self.tracker_home, args) | 1986 return self.do_install(self.tracker_home, args) |
| 1981 except UsageError as message: # noqa: F841 | 1987 except UsageError as message: # noqa: F841 |
| 1982 print(_('Error: %(message)s') % locals()) | 1988 return self.usageError_feedback(message, function) |
| 1983 return 1 | |
| 1984 | 1989 |
| 1985 # get the tracker | 1990 # get the tracker |
| 1986 try: | 1991 try: |
| 1987 if self.tracker and not self.settings['_reopen_tracker']: | 1992 if self.tracker and not self.settings['_reopen_tracker']: |
| 1988 tracker = self.tracker | 1993 tracker = self.tracker |
| 2018 # do the command | 2023 # do the command |
| 2019 ret = 0 | 2024 ret = 0 |
| 2020 try: | 2025 try: |
| 2021 ret = function(args[1:]) | 2026 ret = function(args[1:]) |
| 2022 except UsageError as message: # noqa: F841 | 2027 except UsageError as message: # noqa: F841 |
| 2023 print(_('Error: %(message)s') % locals()) | 2028 ret = self.usageError_feedback(message, function) |
| 2024 print() | |
| 2025 print(function.__doc__) | |
| 2026 ret = 1 | |
| 2027 except Exception: | 2029 except Exception: |
| 2028 import traceback | 2030 import traceback |
| 2029 traceback.print_exc() | 2031 traceback.print_exc() |
| 2030 ret = 1 | 2032 ret = 1 |
| 2031 return ret | 2033 return ret |
