jw-python/test/parse-opts/test.py
Jan Lindemann 1ffdb8728a Add class Options
The Options constructor takes an options string, parses it and
makes the options available via __getitem__().

Signed-off-by: Jan Lindemann <jan@janware.com>
2022-12-01 14:29:01 +01:00

32 lines
999 B
Python

from jwutils.log import *
from jwutils.Options import *
delim = "======================= "
d = "----------------------- "
s = "this=that a=b doit"
slog(NOTICE, d + s)
a = Options(s)
slog(NOTICE, d + "dump()")
a.dump(NOTICE)
slog(NOTICE, d + "by index")
for i in range(0, 4):
slog(NOTICE, "attr({}) = {}".format(i, a.get(i, by_index=True, default=False)))
slog(NOTICE, d + "by key")
for i in [ "this", "that", "b", "a", "doit"]:
slog(NOTICE, "attr({}) = {}".format(i, a[i]))
s = '"me": "too", "Pfalse": true, "myarr": ["a", "b", "c"], "me": "not"'
slog(NOTICE, delim + s)
a = Options(s)
slog(NOTICE, d + "dump()")
a.dump(NOTICE)
slog(NOTICE, d + "by index")
for i in range(0, 5):
slog(NOTICE, "attr({}) = {}".format(i, a.get(i, by_index=True, default=False)))
slog(NOTICE, d + "by key in keys()")
for i in a.keys():
slog(NOTICE, "attr({}) = {}".format(i, a[i]))
slog(NOTICE, d + "by key")
for i in [ "me", "Pfalse", "myarr" ]:
slog(NOTICE, "attr({}) = {}".format(i, a[i]))