jw-python/test/parse-opts/test.py

32 lines
999 B
Python
Raw Normal View History

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]))