|
|
@@ -4,6 +4,7 @@ import nilmdb |
|
|
|
from nilmdb.utils.printf import * |
|
|
|
import nilmdb.cmdline |
|
|
|
|
|
|
|
import unittest |
|
|
|
from nose.tools import * |
|
|
|
from nose.tools import assert_raises |
|
|
|
import itertools |
|
|
@@ -133,7 +134,7 @@ class TestCmdline(object): |
|
|
|
def dump(self): |
|
|
|
printf("-----dump start-----\n%s-----dump end-----\n", self.captured) |
|
|
|
|
|
|
|
def test_cmdline_01_basic(self): |
|
|
|
def test_01_basic(self): |
|
|
|
|
|
|
|
# help |
|
|
|
self.ok("--help") |
|
|
@@ -179,14 +180,14 @@ class TestCmdline(object): |
|
|
|
self.fail("extract --start 2000-01-01 --start 2001-01-02") |
|
|
|
self.contain("duplicated argument") |
|
|
|
|
|
|
|
def test_cmdline_02_info(self): |
|
|
|
def test_02_info(self): |
|
|
|
self.ok("info") |
|
|
|
self.contain("Server URL: http://localhost:12380/") |
|
|
|
self.contain("Server version: " + test_server.version) |
|
|
|
self.contain("Server database path") |
|
|
|
self.contain("Server database size") |
|
|
|
|
|
|
|
def test_cmdline_03_createlist(self): |
|
|
|
def test_03_createlist(self): |
|
|
|
# Basic stream tests, like those in test_client. |
|
|
|
|
|
|
|
# No streams |
|
|
@@ -230,10 +231,17 @@ class TestCmdline(object): |
|
|
|
"/newton/raw RawData\n" |
|
|
|
"/newton/zzz/rawnotch RawNotchedData\n") |
|
|
|
|
|
|
|
# Match just one type or one path |
|
|
|
# Match just one type or one path. Also check |
|
|
|
# that --path is optional |
|
|
|
self.ok("list --path /newton/raw") |
|
|
|
self.match("/newton/raw RawData\n") |
|
|
|
|
|
|
|
self.ok("list /newton/raw") |
|
|
|
self.match("/newton/raw RawData\n") |
|
|
|
|
|
|
|
self.fail("list -p /newton/raw /newton/raw") |
|
|
|
self.contain("too many paths") |
|
|
|
|
|
|
|
self.ok("list --layout RawData") |
|
|
|
self.match("/newton/raw RawData\n") |
|
|
|
|
|
|
@@ -245,10 +253,14 @@ class TestCmdline(object): |
|
|
|
self.ok("list --path *zzz* --layout Raw*") |
|
|
|
self.match("/newton/zzz/rawnotch RawNotchedData\n") |
|
|
|
|
|
|
|
self.ok("list *zzz* --layout Raw*") |
|
|
|
self.match("/newton/zzz/rawnotch RawNotchedData\n") |
|
|
|
|
|
|
|
self.ok("list --path *zzz* --layout Prep*") |
|
|
|
self.match("") |
|
|
|
|
|
|
|
def test_cmdline_04_metadata(self): |
|
|
|
|
|
|
|
def test_04_metadata(self): |
|
|
|
# Set / get metadata |
|
|
|
self.fail("metadata") |
|
|
|
self.fail("metadata --get") |
|
|
@@ -305,7 +317,7 @@ class TestCmdline(object): |
|
|
|
self.fail("metadata /newton/nosuchpath") |
|
|
|
self.contain("No stream at path /newton/nosuchpath") |
|
|
|
|
|
|
|
def test_cmdline_05_parsetime(self): |
|
|
|
def test_05_parsetime(self): |
|
|
|
os.environ['TZ'] = "America/New_York" |
|
|
|
cmd = nilmdb.cmdline.Cmdline(None) |
|
|
|
test = datetime_tz.datetime_tz.now() |
|
|
@@ -320,7 +332,7 @@ class TestCmdline(object): |
|
|
|
eq_(cmd.parse_time("snapshot-20120405-140000.raw.gz"), test) |
|
|
|
eq_(cmd.parse_time("prep-20120405T1400"), test) |
|
|
|
|
|
|
|
def test_cmdline_06_insert(self): |
|
|
|
def test_06_insert(self): |
|
|
|
self.ok("insert --help") |
|
|
|
|
|
|
|
self.fail("insert /foo/bar baz qwer") |
|
|
@@ -380,7 +392,7 @@ class TestCmdline(object): |
|
|
|
# bad start time |
|
|
|
self.fail("insert --rate 120 --start 'whatever' /newton/prep /dev/null") |
|
|
|
|
|
|
|
def test_cmdline_07_detail(self): |
|
|
|
def test_07_detail(self): |
|
|
|
# Just count the number of lines, it's probably fine |
|
|
|
self.ok("list --detail") |
|
|
|
lines_(self.captured, 8) |
|
|
@@ -414,7 +426,7 @@ class TestCmdline(object): |
|
|
|
self.ok("list --detail") |
|
|
|
lines_(self.captured, 8) |
|
|
|
|
|
|
|
def test_cmdline_08_extract(self): |
|
|
|
def test_08_extract(self): |
|
|
|
# nonexistent stream |
|
|
|
self.fail("extract /no/such/foo --start 2000-01-01 --end 2020-01-01") |
|
|
|
self.contain("Error getting stream info") |
|
|
@@ -469,7 +481,7 @@ class TestCmdline(object): |
|
|
|
self.ok("extract -c /newton/prep --start 2000-01-01 --end 2020-01-01") |
|
|
|
self.match("43200\n") |
|
|
|
|
|
|
|
def test_cmdline_09_truncated(self): |
|
|
|
def test_09_truncated(self): |
|
|
|
# Test truncated responses by overriding the nilmdb max_results |
|
|
|
server_stop() |
|
|
|
server_start(max_results = 2) |
|
|
@@ -478,7 +490,51 @@ class TestCmdline(object): |
|
|
|
server_stop() |
|
|
|
server_start() |
|
|
|
|
|
|
|
def test_cmdline_10_destroy(self): |
|
|
|
@unittest.skip("not ready") |
|
|
|
def test_10_remove(self): |
|
|
|
# Removing data |
|
|
|
|
|
|
|
# Try nonexistent stream |
|
|
|
self.fail("remove /no/such/foo --start 2000-01-01 --end 2020-01-01") |
|
|
|
self.contain("Error getting stream info") |
|
|
|
|
|
|
|
# empty ranges return success |
|
|
|
self.ok("remove /newton/prep " + |
|
|
|
"--start '23 Mar 2012 10:00:30' " + |
|
|
|
"--end '23 Mar 2012 10:00:30'") |
|
|
|
self.match("") |
|
|
|
self.ok("remove /newton/prep " + |
|
|
|
"--start '23 Mar 2012 10:00:30.000001' " + |
|
|
|
"--end '23 Mar 2012 10:00:30.000001'") |
|
|
|
self.match("") |
|
|
|
self.ok("remove /newton/prep " + |
|
|
|
"--start '23 Mar 2022 10:00:30' " + |
|
|
|
"--end '23 Mar 2022 10:00:30'") |
|
|
|
self.match("") |
|
|
|
|
|
|
|
# Verbose |
|
|
|
self.ok("remove -v /newton/prep " + |
|
|
|
"--start '23 Mar 2012 10:00:30' " + |
|
|
|
"--end '23 Mar 2012 10:00:30'") |
|
|
|
self.match("0\n") |
|
|
|
self.ok("remove --verbose /newton/prep " + |
|
|
|
"--start '23 Mar 2012 10:00:30' " + |
|
|
|
"--end '23 Mar 2012 10:00:30'") |
|
|
|
self.match("0\n") |
|
|
|
|
|
|
|
# Remove various chunks of prep data and make sure |
|
|
|
# they're gone |
|
|
|
self.ok("remove -v /newton/prep " + |
|
|
|
"--start '23 Mar 2012 10:00:30' " + |
|
|
|
"--end '23 Mar 2012 10:00:40'") |
|
|
|
self.match("1200\n") |
|
|
|
self.ok("extract -c /newton/prep --start 2000-01-01 --end 2020-01-01") |
|
|
|
self.match("42000\n") |
|
|
|
|
|
|
|
# See the missing chunk in list output |
|
|
|
#self.ok("list --detail ") |
|
|
|
|
|
|
|
def test_11_destroy(self): |
|
|
|
# Delete records |
|
|
|
self.ok("destroy --help") |
|
|
|
|
|
|
@@ -529,7 +585,7 @@ class TestCmdline(object): |
|
|
|
self.ok("list --detail --path " + path) |
|
|
|
self.contain("(no intervals)") |
|
|
|
|
|
|
|
def test_cmdline_11_unicode(self): |
|
|
|
def test_12_unicode(self): |
|
|
|
# Unicode paths. |
|
|
|
self.ok("destroy /newton/asdf/qwer") |
|
|
|
self.ok("destroy /newton/prep") |
|
|
@@ -549,7 +605,7 @@ class TestCmdline(object): |
|
|
|
|
|
|
|
self.ok(u"destroy /düsseldorf/raw") |
|
|
|
|
|
|
|
def test_cmdline_12_files(self): |
|
|
|
def test_13_files(self): |
|
|
|
# Test BulkData's ability to split into multiple files, |
|
|
|
# by forcing the file size to be really small. |
|
|
|
server_stop() |
|
|
|