Mercurial > p > roundup > code
comparison roundup/admin.py @ 6198:39513b36ca59
Add set tests. Test and fix table command.
admin.py:do_set:
Better document use of classname in set command.
Remove traceback.print_exc() that generates stderr index error which
duplicates UsageError and can confuse the user.
admin.py:do_table:
Fix null width spec to be length of label not len(label)+1
Handle exception if width is not an int.
Outdent code to proper location. Was inside loop and should not have
been.
test_admin.py:
Add tests for get with bad node designator
Add disabled test for HelpInitopts. Proper test TBD as valid result
depends on the environment the test is run in. So making it
robust it tricky.
Add tests for set error cases.
Add test for using set on class rather than designator
Add new tests for table command
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Fri, 12 Jun 2020 23:22:58 -0400 |
| parents | 6e0c4d50b97e |
| children | 74784dd531c8 |
comparison
equal
deleted
inserted
replaced
| 6197:2492e2e17371 | 6198:39513b36ca59 |
|---|---|
| 658 list of item designators (ie "designator[,designator,...]"). | 658 list of item designators (ie "designator[,designator,...]"). |
| 659 | 659 |
| 660 A designator is a classname and a nodeid concatenated, | 660 A designator is a classname and a nodeid concatenated, |
| 661 eg. bug1, user10, ... | 661 eg. bug1, user10, ... |
| 662 | 662 |
| 663 This command sets the properties to the values for all designators | 663 This command sets the properties to the values for all |
| 664 given. If the value is missing (ie. "property=") then the property | 664 designators given. If a class is used, the property will be |
| 665 is un-set. If the property is a multilink, you specify the linked | 665 set for all items in the class. If the value is missing |
| 666 ids for the multilink as comma-separated numbers (ie "1,2,3"). | 666 (ie. "property=") then the property is un-set. If the property |
| 667 is a multilink, you specify the linked ids for the multilink | |
| 668 as comma-separated numbers (ie "1,2,3"). | |
| 669 | |
| 667 """ | 670 """ |
| 668 import copy # needed for copying props list | 671 import copy # needed for copying props list |
| 669 | 672 |
| 670 if len(args) < 2: | 673 if len(args) < 2: |
| 671 raise UsageError(_('Not enough arguments supplied')) | 674 raise UsageError(_('Not enough arguments supplied')) |
| 709 | 712 |
| 710 # try the set | 713 # try the set |
| 711 try: | 714 try: |
| 712 cl.set(itemid, **props) | 715 cl.set(itemid, **props) |
| 713 except (TypeError, IndexError, ValueError) as message: | 716 except (TypeError, IndexError, ValueError) as message: |
| 714 import traceback; traceback.print_exc() | |
| 715 raise UsageError(message) | 717 raise UsageError(message) |
| 716 self.db_uncommitted = True | 718 self.db_uncommitted = True |
| 717 return 0 | 719 return 0 |
| 718 | 720 |
| 719 def do_filter(self, args): | 721 def do_filter(self, args): |
| 1071 props = [] | 1073 props = [] |
| 1072 for spec in prop_names: | 1074 for spec in prop_names: |
| 1073 if ':' in spec: | 1075 if ':' in spec: |
| 1074 name, width = spec.split(':') | 1076 name, width = spec.split(':') |
| 1075 if width == '': | 1077 if width == '': |
| 1076 props.append((name, len(spec))) | 1078 # spec includes trailing :, use label/name width |
| 1079 props.append((name, len(name))) | |
| 1077 else: | 1080 else: |
| 1078 props.append((name, int(width))) | 1081 try: |
| 1082 props.append((name, int(width))) | |
| 1083 except ValueError: | |
| 1084 raise UsageError(_('"%(spec)s" does not have an ' | |
| 1085 'integer width: "%(width)s"') % | |
| 1086 locals()) | |
| 1079 else: | 1087 else: |
| 1080 # this is going to be slow | 1088 # this is going to be slow |
| 1081 maxlen = len(spec) | 1089 maxlen = len(spec) |
| 1082 for nodeid in cl.list(): | 1090 for nodeid in cl.list(): |
| 1083 curlen = len(str(cl.get(nodeid, spec))) | 1091 curlen = len(str(cl.get(nodeid, spec))) |
| 1084 if curlen > maxlen: | 1092 if curlen > maxlen: |
| 1085 maxlen = curlen | 1093 maxlen = curlen |
| 1086 props.append((spec, maxlen)) | 1094 props.append((spec, maxlen)) |
| 1087 | 1095 |
| 1088 # now display the heading | 1096 # now display the heading |
| 1089 print(' '.join([name.capitalize().ljust(width) | 1097 print(' '.join([name.capitalize().ljust(width) |
| 1090 for name, width in props])) | 1098 for name, width in props])) |
| 1091 | 1099 |
