Revision 63b883de
b/lib/utils/text.py | ||
---|---|---|
588 | 588 |
return text |
589 | 589 |
else: |
590 | 590 |
return text[:length - len(_ASCII_ELLIPSIS)] + _ASCII_ELLIPSIS |
591 |
|
|
592 |
|
|
593 |
def FormatKeyValue(data): |
|
594 |
"""Formats a dictionary as "key=value" parameters. |
|
595 |
|
|
596 |
The keys are sorted to have a stable order. |
|
597 |
|
|
598 |
@type data: dict |
|
599 |
@rtype: list of string |
|
600 |
|
|
601 |
""" |
|
602 |
return ["%s=%s" % (key, value) for (key, value) in sorted(data.items())] |
b/test/ganeti.utils.text_unittest.py | ||
---|---|---|
576 | 576 |
self.assertRaises(AssertionError, utils.Truncate, "", i) |
577 | 577 |
|
578 | 578 |
|
579 |
class TestFormatKeyValue(unittest.TestCase): |
|
580 |
def test(self): |
|
581 |
self.assertEqual(utils.FormatKeyValue({}), []) |
|
582 |
self.assertEqual(utils.FormatKeyValue({1: 2}), ["1=2"]) |
|
583 |
self.assertEqual(utils.FormatKeyValue({ |
|
584 |
"zzz": "0", |
|
585 |
"aaa": "1", |
|
586 |
}), |
|
587 |
["aaa=1", "zzz=0"]) |
|
588 |
|
|
589 |
|
|
579 | 590 |
if __name__ == "__main__": |
580 | 591 |
testutils.GanetiTestProgram() |
Also available in: Unified diff