|
|
@@ -391,12 +391,73 @@ class TestClient(object): |
|
|
|
"probably not closing properly.") |
|
|
|
if test == 1: |
|
|
|
# explicit close |
|
|
|
client = nilmdb.Client(url = "http://localhost:12380/") |
|
|
|
client = nilmdb.Client(url = testurl) |
|
|
|
with assert_raises(ClientError) as e: |
|
|
|
client.stream_remove("/newton/prep", 123, 120) |
|
|
|
client.close() # remove this to see the failure |
|
|
|
elif test == 2: |
|
|
|
# use the context manager |
|
|
|
with nilmdb.Client(url = "http://localhost:12380/") as c: |
|
|
|
with nilmdb.Client(url = testurl) as c: |
|
|
|
with assert_raises(ClientError) as e: |
|
|
|
c.stream_remove("/newton/prep", 123, 120) |
|
|
|
|
|
|
|
def test_client_10_context(self): |
|
|
|
# Test using the client's stream insertion context manager to |
|
|
|
# insert data. |
|
|
|
client = nilmdb.Client(testurl) |
|
|
|
|
|
|
|
client.stream_create("/context/test", "uint16_1") |
|
|
|
with client.stream_insert_context("/context/test") as ctx: |
|
|
|
# override _max_data to trigger frequent server updates |
|
|
|
ctx._max_data = 15 |
|
|
|
|
|
|
|
with assert_raises(ValueError): |
|
|
|
ctx.insert_line("100 1") |
|
|
|
|
|
|
|
ctx.insert_line("100 1\n") |
|
|
|
ctx.insert_iter([ "101 1\n", |
|
|
|
"102 1\n", |
|
|
|
"103 1\n" ]) |
|
|
|
ctx.insert_line("104 1\n") |
|
|
|
ctx.insert_line("105 1\n") |
|
|
|
ctx.finalize() |
|
|
|
|
|
|
|
ctx.insert_line("106 1\n") |
|
|
|
ctx.update_end(106.5) |
|
|
|
ctx.finalize() |
|
|
|
ctx.update_start(106.8) |
|
|
|
ctx.insert_line("107 1\n") |
|
|
|
ctx.insert_line("108 1\n") |
|
|
|
ctx.insert_line("109 1\n") |
|
|
|
ctx.insert_line("110 1\n") |
|
|
|
ctx.insert_line("111 1\n") |
|
|
|
ctx.update_end(113) |
|
|
|
ctx.insert_line("112 1\n") |
|
|
|
ctx.update_end(114) |
|
|
|
ctx.insert_line("113 1\n") |
|
|
|
ctx.update_end(115) |
|
|
|
ctx.insert_line("114 1\n") |
|
|
|
ctx.finalize() |
|
|
|
|
|
|
|
with assert_raises(ClientError): |
|
|
|
with client.stream_insert_context("/context/test", 100, 200) as ctx: |
|
|
|
ctx.insert_line("115 1\n") |
|
|
|
|
|
|
|
with assert_raises(ClientError): |
|
|
|
with client.stream_insert_context("/context/test", 200, 300) as ctx: |
|
|
|
ctx.insert_line("115 1\n") |
|
|
|
|
|
|
|
with client.stream_insert_context("/context/test", 200, 300) as ctx: |
|
|
|
# make sure our override wasn't permanent |
|
|
|
ne_(ctx._max_data, 15) |
|
|
|
ctx.insert_line("225 1\n") |
|
|
|
ctx.finalize() |
|
|
|
|
|
|
|
eq_(list(client.stream_intervals("/context/test")), |
|
|
|
[ [ 100, 105.000001 ], |
|
|
|
[ 106, 106.5 ], |
|
|
|
[ 106.8, 115 ], |
|
|
|
[ 200, 300 ] ]) |
|
|
|
|
|
|
|
client.stream_destroy("/context/test") |
|
|
|
client.close() |