run-in-py-utils-bt2-env.sh: update error message style
[babeltrace.git] / tests / utils / python / cli_params_to_string.py
CommitLineData
0235b0db 1# SPDX-License-Identifier: GPL-2.0-only
0076e742
SM
2#
3# Copyright (C) 2019 EfficiOS Inc.
4#
0076e742
SM
5
6import bt2
7
8
9def to_string(p):
10 # Print BT values in a predictable way (the order of map entries) and with
11 # additional information (u suffix to differentiate unsigned integers from
12 # signed integers).
13
14 if type(p) is bt2._ArrayValueConst:
f5567ea8 15 s = "[{}]".format(", ".join([to_string(x) for x in p]))
0076e742 16 elif type(p) is bt2._MapValueConst:
f5567ea8
FD
17 s = "{{{}}}".format(
18 ", ".join([k + "=" + to_string(p[k]) for k in sorted(p.keys())])
0076e742
SM
19 )
20 elif type(p) is bt2._UnsignedIntegerValueConst:
f5567ea8 21 s = str(p) + "u"
5b616db9
SM
22 elif type(p) is bt2._RealValueConst:
23 s = "{:.7f}".format(float(p))
0076e742
SM
24 elif (
25 type(p)
26 in (
27 bt2._StringValueConst,
28 bt2._SignedIntegerValueConst,
0076e742
SM
29 bt2._BoolValueConst,
30 )
31 or p is None
32 ):
33 s = str(p)
34
35 else:
f5567ea8 36 raise TypeError("Unexpected type", type(p))
0076e742
SM
37
38 return s
This page took 0.045144 seconds and 4 git commands to generate.