Skip to content

Commit 1e9c8df

Browse files
committed
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.
1 parent bd81420 commit 1e9c8df

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

roundup/admin.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,6 +1920,12 @@ def do_updateconfig(self, args):
19201920
"""
19211921
self.do_genconfig(args, update=True)
19221922

1923+
def usageError_feedback(self, message, function):
1924+
print(_('Error: %s') % message)
1925+
print()
1926+
print(function.__doc__)
1927+
return 1
1928+
19231929
def run_command(self, args):
19241930
"""Run a single command
19251931
"""
@@ -1937,12 +1943,6 @@ def run_command(self, args):
19371943
self.help_commands()
19381944
self.help_all()
19391945
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
19461946

19471947
# figure what the command is
19481948
try:
@@ -1961,6 +1961,13 @@ def run_command(self, args):
19611961
return 1
19621962
command, function = functions[0]
19631963

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+
19641971
# make sure we have a tracker_home
19651972
while not self.tracker_home:
19661973
if not self.force:
@@ -1973,14 +1980,12 @@ def run_command(self, args):
19731980
try:
19741981
return self.do_initialise(self.tracker_home, args)
19751982
except UsageError as message: # noqa: F841
1976-
print(_('Error: %(message)s') % locals())
1977-
return 1
1983+
return self.usageError_feedback(message, function)
19781984
elif command == 'install':
19791985
try:
19801986
return self.do_install(self.tracker_home, args)
19811987
except UsageError as message: # noqa: F841
1982-
print(_('Error: %(message)s') % locals())
1983-
return 1
1988+
return self.usageError_feedback(message, function)
19841989

19851990
# get the tracker
19861991
try:
@@ -2020,10 +2025,7 @@ def run_command(self, args):
20202025
try:
20212026
ret = function(args[1:])
20222027
except UsageError as message: # noqa: F841
2023-
print(_('Error: %(message)s') % locals())
2024-
print()
2025-
print(function.__doc__)
2026-
ret = 1
2028+
ret = self.usageError_feedback(message, function)
20272029
except Exception:
20282030
import traceback
20292031
traceback.print_exc()

test/test_admin.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,18 @@ def testInit(self):
255255
self.assertTrue(os.path.isfile(self.dirname + "/config.ini"))
256256
self.assertTrue(os.path.isfile(self.dirname + "/schema.py"))
257257

258+
self.admin=AdminTool()
259+
with captured_output() as (out, err):
260+
sys.argv=['main', '-i', '/tmp/noSuchDirectory/nodir', 'install', 'classic', self.backend]
261+
ret = self.admin.main()
262+
263+
out = out.getvalue().strip()
264+
print(ret)
265+
print(out)
266+
self.assertEqual(ret, 1)
267+
self.assertIn('Error: Instance home parent directory '
268+
'"/tmp/noSuchDirectory" does not exist', out)
269+
258270
def testInitWithConfig_ini(self):
259271
from roundup.configuration import CoreConfig
260272
self.admin=AdminTool()

0 commit comments

Comments
 (0)