bugfix: reorder variants in Spec strings (#16462)
* change print order for variants to avoid zsh parsing bugs * change tests for new variant parse order
This commit is contained in:
parent
473424ad60
commit
dc59fc7ab8
@ -177,7 +177,7 @@ def test_full_specs(self):
|
|||||||
" ^stackwalker@8.1_1e")
|
" ^stackwalker@8.1_1e")
|
||||||
self.check_parse(
|
self.check_parse(
|
||||||
"mvapich_foo"
|
"mvapich_foo"
|
||||||
" ^_openmpi@1.2:1.4,1.6%intel@12.1 debug=2 ~qt_4"
|
" ^_openmpi@1.2:1.4,1.6%intel@12.1~qt_4 debug=2"
|
||||||
" ^stackwalker@8.1_1e")
|
" ^stackwalker@8.1_1e")
|
||||||
self.check_parse(
|
self.check_parse(
|
||||||
'mvapich_foo'
|
'mvapich_foo'
|
||||||
@ -185,7 +185,7 @@ def test_full_specs(self):
|
|||||||
' ^stackwalker@8.1_1e')
|
' ^stackwalker@8.1_1e')
|
||||||
self.check_parse(
|
self.check_parse(
|
||||||
"mvapich_foo"
|
"mvapich_foo"
|
||||||
" ^_openmpi@1.2:1.4,1.6%intel@12.1 debug=2 ~qt_4"
|
" ^_openmpi@1.2:1.4,1.6%intel@12.1~qt_4 debug=2"
|
||||||
" ^stackwalker@8.1_1e arch=test-redhat6-x86")
|
" ^stackwalker@8.1_1e arch=test-redhat6-x86")
|
||||||
|
|
||||||
def test_canonicalize(self):
|
def test_canonicalize(self):
|
||||||
|
@ -694,7 +694,7 @@ def test_str(self):
|
|||||||
c['foobar'] = SingleValuedVariant('foobar', 'fee')
|
c['foobar'] = SingleValuedVariant('foobar', 'fee')
|
||||||
c['feebar'] = SingleValuedVariant('feebar', 'foo')
|
c['feebar'] = SingleValuedVariant('feebar', 'foo')
|
||||||
c['shared'] = BoolValuedVariant('shared', True)
|
c['shared'] = BoolValuedVariant('shared', True)
|
||||||
assert str(c) == ' feebar=foo foo=bar,baz foobar=fee +shared'
|
assert str(c) == '+shared feebar=foo foo=bar,baz foobar=fee'
|
||||||
|
|
||||||
|
|
||||||
def test_disjoint_set_initialization_errors():
|
def test_disjoint_set_initialization_errors():
|
||||||
|
@ -567,25 +567,24 @@ def __str__(self):
|
|||||||
# print keys in order
|
# print keys in order
|
||||||
sorted_keys = sorted(self.keys())
|
sorted_keys = sorted(self.keys())
|
||||||
|
|
||||||
|
# Separate boolean variants from key-value pairs as they print
|
||||||
|
# differently. All booleans go first to avoid ' ~foo' strings that
|
||||||
|
# break spec reuse in zsh.
|
||||||
|
bool_keys = []
|
||||||
|
kv_keys = []
|
||||||
|
for key in sorted_keys:
|
||||||
|
bool_keys.append(key) if isinstance(self[key].value, bool) \
|
||||||
|
else kv_keys.append(key)
|
||||||
|
|
||||||
# add spaces before and after key/value variants.
|
# add spaces before and after key/value variants.
|
||||||
string = StringIO()
|
string = StringIO()
|
||||||
|
|
||||||
kv = False
|
for key in bool_keys:
|
||||||
for key in sorted_keys:
|
string.write(str(self[key]))
|
||||||
vspec = self[key]
|
|
||||||
|
|
||||||
if not isinstance(vspec.value, bool):
|
for key in kv_keys:
|
||||||
# add space before all kv pairs.
|
|
||||||
string.write(' ')
|
string.write(' ')
|
||||||
kv = True
|
string.write(str(self[key]))
|
||||||
else:
|
|
||||||
# not a kv pair this time
|
|
||||||
if kv:
|
|
||||||
# if it was LAST time, then pad after.
|
|
||||||
string.write(' ')
|
|
||||||
kv = False
|
|
||||||
|
|
||||||
string.write(str(vspec))
|
|
||||||
|
|
||||||
return string.getvalue()
|
return string.getvalue()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user