|
|
@@ -17,26 +17,48 @@ from nose.tools import assert_raises |
|
|
|
import unittest |
|
|
|
|
|
|
|
from testutil.helpers import * |
|
|
|
import multiprocessing |
|
|
|
import traceback |
|
|
|
|
|
|
|
from urllib.request import urlopen |
|
|
|
from nilmtools.filter import ArgumentError |
|
|
|
|
|
|
|
def run_cherrypy_server(path, port, event): |
|
|
|
db = nilmdb.utils.serializer_proxy(nilmdb.server.NilmDB)(path) |
|
|
|
server = nilmdb.server.Server(db, host="127.0.0.1", |
|
|
|
port=port, stoppable=True) |
|
|
|
server.start(blocking = True, event = event) |
|
|
|
db.close() |
|
|
|
|
|
|
|
class CommandTester(): |
|
|
|
|
|
|
|
url = "http://localhost:32182/" |
|
|
|
url2 = "http://localhost:32183/" |
|
|
|
|
|
|
|
@classmethod |
|
|
|
def setup_class(cls): |
|
|
|
path = "tests/testdb" |
|
|
|
recursive_unlink(path) |
|
|
|
cls.db = nilmdb.utils.serializer_proxy(nilmdb.server.NilmDB)(path) |
|
|
|
cls.server = nilmdb.server.Server(cls.db, host="127.0.0.1", |
|
|
|
port=32182, stoppable=True) |
|
|
|
cls.server.start(blocking=False) |
|
|
|
# Use multiprocessing with "spawn" method, so that we can |
|
|
|
# start two fully independent cherrypy instances |
|
|
|
# (needed for copy-wildcard) |
|
|
|
multiprocessing.set_start_method('spawn') |
|
|
|
|
|
|
|
events = [] |
|
|
|
for (path, port) in (("tests/testdb1", 32182), |
|
|
|
("tests/testdb2", 32183)): |
|
|
|
recursive_unlink(path) |
|
|
|
event = multiprocessing.Event() |
|
|
|
proc = multiprocessing.Process(target=run_cherrypy_server, |
|
|
|
args=(path, port, event)) |
|
|
|
proc.start() |
|
|
|
events.append(event) |
|
|
|
for event in events: |
|
|
|
if not event.wait(timeout = 10): |
|
|
|
raise AssertionError("server didn't start") |
|
|
|
|
|
|
|
@classmethod |
|
|
|
def teardown_class(cls): |
|
|
|
cls.server.stop() |
|
|
|
cls.db.close() |
|
|
|
urlopen("http://127.0.0.1:32182/exit/", timeout = 1) |
|
|
|
urlopen("http://127.0.0.1:32183/exit/", timeout = 1) |
|
|
|
|
|
|
|
def run(self, arg_string, infile=None, outfile=None): |
|
|
|
"""Run a cmdline client with the specified argument string, |
|
|
|