|
|
@@ -360,6 +360,12 @@ class TestCmdline(object): |
|
|
|
self.ok("metadata /newton/raw --update " |
|
|
|
"v_scale=1.234") |
|
|
|
|
|
|
|
# unicode |
|
|
|
self.ok("metadata /newton/raw --set " |
|
|
|
"a_๐ด๐ฎ๐=value a_key=๐ฟ๐ช๐ต๐พ๐ฎ a_๐ธ๐ฒ๐=๐๐ฎ๐น๐๐ฒ") |
|
|
|
self.ok("metadata /newton/raw --get") |
|
|
|
self.match("a_key=๐ฟ๐ช๐ต๐พ๐ฎ\na_๐ด๐ฎ๐=value\na_๐ธ๐ฒ๐=๐๐ฎ๐น๐๐ฒ\n") |
|
|
|
|
|
|
|
# various parsing tests |
|
|
|
self.ok("metadata /newton/raw --update foo=") |
|
|
|
self.fail("metadata /newton/raw --update =bar") |
|
|
@@ -1166,3 +1172,74 @@ class TestCmdline(object): |
|
|
|
|
|
|
|
server_stop() |
|
|
|
server_start() |
|
|
|
|
|
|
|
def test_05b_completion(self): |
|
|
|
# Test bash completion. This depends on some data put in the DB by |
|
|
|
# earlier tests, so the execution order is important. |
|
|
|
def complete(line, expect="<unspecified>"): |
|
|
|
# set env vars |
|
|
|
env = { |
|
|
|
'_ARGCOMPLETE': '1', |
|
|
|
'COMP_LINE': line, |
|
|
|
'COMP_POINT': str(len(line)), |
|
|
|
'COMP_TYPE': '8', |
|
|
|
'NILMDB_URL': "http://localhost:32180/", |
|
|
|
} |
|
|
|
for (k, v) in env.items(): |
|
|
|
os.environ[k] = v |
|
|
|
|
|
|
|
# create pipe for completion output |
|
|
|
output = io.BytesIO() |
|
|
|
|
|
|
|
# ensure argcomplete won't mess with any FDs |
|
|
|
def fake_fdopen(fd, mode): |
|
|
|
return io.BytesIO() |
|
|
|
old_fdopen = os.fdopen |
|
|
|
os.fdopen = fake_fdopen |
|
|
|
|
|
|
|
# run cli |
|
|
|
cmdline = nilmdb.cmdline.Cmdline([]) |
|
|
|
cmdline.complete_output_stream = output |
|
|
|
try: |
|
|
|
cmdline.run() |
|
|
|
sys.exit(0) |
|
|
|
except SystemExit as e: |
|
|
|
exitcode = e.code |
|
|
|
eq_(exitcode, 0) |
|
|
|
|
|
|
|
# clean up |
|
|
|
os.fdopen = old_fdopen |
|
|
|
for (k, v) in env.items(): |
|
|
|
del os.environ[k] |
|
|
|
|
|
|
|
# read completion output |
|
|
|
comp = output.getvalue() |
|
|
|
|
|
|
|
# replace completion separators with commas, for clarity |
|
|
|
cleaned = comp.replace(b'\x0b', b',').decode('utf-8') |
|
|
|
|
|
|
|
# expect the given match or prefix |
|
|
|
if expect.endswith('*'): |
|
|
|
if not cleaned.startswith(expect[:-1]): |
|
|
|
raise AssertionError(("completions:\n '%s'\n" |
|
|
|
"don't start with:\n '%s'") % |
|
|
|
(cleaned, expect[:-1])) |
|
|
|
else: |
|
|
|
if cleaned != expect: |
|
|
|
raise AssertionError(("completions:\n '%s'\n" |
|
|
|
"don't match:\n '%s'") % |
|
|
|
(cleaned, expect)) |
|
|
|
|
|
|
|
complete("nilmtool -u ", "") |
|
|
|
complete("nilmtool list ", "-h,--help,-E,--ext*") |
|
|
|
complete("nilmtool list --st", "--start ") |
|
|
|
complete("nilmtool list --start ", "") |
|
|
|
complete("nilmtool list /", "/newton/prep,/newton/raw*") |
|
|
|
complete("nilmtool create /foo int3", "int32_1,int32_2*") |
|
|
|
complete("nilmtool metadata /newton/raw --get a", |
|
|
|
"a_๐ด๐ฎ๐,a_key,a_๐ธ๐ฒ๐") |
|
|
|
complete("nilmtool metadata /newton/raw --set a", |
|
|
|
"a_๐ด๐ฎ๐=value,a_key=๐ฟ๐ช๐ต๐พ๐ฎ,a_๐ธ๐ฒ๐=๐๐ฎ๐น๐๐ฒ") |
|
|
|
complete("nilmtool metadata /newton/raw --set a_๐ธ", "a_๐ธ๐ฒ๐=๐๐ฎ๐น๐๐ฒ ") |
|
|
|
complete("nilmtool metadata '' --set a", "") |
|
|
|
self.run("list") |