Rename and reorganize stuff
This commit is contained in:
parent
6d9ee7b405
commit
35b20c90a5
|
@ -25,8 +25,7 @@ from nilmdb.server.serverutil import (
|
|||
cherrypy_stop,
|
||||
)
|
||||
import nilmrun
|
||||
import nilmrun.filters.trainola
|
||||
import nilmrun.filters.dummy
|
||||
import nilmrun.testfilter
|
||||
|
||||
# Add CORS_allow tool
|
||||
cherrypy.tools.CORS_allow = cherrypy.Tool('on_start_resource', CORS_allow)
|
||||
|
@ -124,6 +123,7 @@ class AppRun(object):
|
|||
and 'argv[1:]' are arguments"""
|
||||
return self.manager.run_command("command", argv)
|
||||
|
||||
# /run/code
|
||||
@cherrypy.expose
|
||||
@cherrypy.tools.json_in()
|
||||
@cherrypy.tools.json_out()
|
||||
|
@ -135,25 +135,15 @@ class AppRun(object):
|
|||
(i.e., they end up in sys.argv[1:])"""
|
||||
return self.manager.run_code("usercode", code, args)
|
||||
|
||||
# /run/trainola
|
||||
# /run/testfilter
|
||||
@cherrypy.expose
|
||||
@cherrypy.tools.json_in()
|
||||
@cherrypy.tools.json_out()
|
||||
@exception_to_httperror(KeyError, ValueError)
|
||||
@cherrypy.tools.CORS_allow(methods = ["POST"])
|
||||
def trainola(self, data):
|
||||
def testfilter(self, data):
|
||||
return self.manager.run_function(
|
||||
"trainola", nilmrun.filters.trainola.filterfunc, data)
|
||||
|
||||
# /run/dummy
|
||||
@cherrypy.expose
|
||||
@cherrypy.tools.json_in()
|
||||
@cherrypy.tools.json_out()
|
||||
@exception_to_httperror(KeyError, ValueError)
|
||||
@cherrypy.tools.CORS_allow(methods = ["POST"])
|
||||
def dummy(self, data):
|
||||
return self.manager.run_function(
|
||||
"dummy", nilmrun.filters.dummy.filterfunc, data)
|
||||
"dummy", nilmrun.testfilter.test, data)
|
||||
|
||||
class Server(object):
|
||||
def __init__(self, host = '127.0.0.1', port = 8080,
|
||||
|
|
|
@ -6,7 +6,7 @@ import signal
|
|||
import sys
|
||||
|
||||
# This is just for testing the process management.
|
||||
def filterfunc(n):
|
||||
def test(n):
|
||||
n = int(n)
|
||||
if n < 0: # raise an exception
|
||||
raise Exception("test exception")
|
|
@ -1,3 +1,3 @@
|
|||
test_client.py
|
||||
test_nilmrun.py
|
||||
|
||||
test_*.py
|
||||
|
|
|
@ -98,7 +98,7 @@ class TestClient(object):
|
|||
client = HTTPClient(baseurl = testurl, post_json = True)
|
||||
|
||||
# start dummy filter
|
||||
pid = client.post("/run/dummy", { "data": 30 })
|
||||
pid = client.post("/run/testfilter", { "data": 30 })
|
||||
eq_(client.get("/process/list"), [pid])
|
||||
time.sleep(1)
|
||||
|
||||
|
@ -132,7 +132,7 @@ class TestClient(object):
|
|||
client = HTTPClient(baseurl = testurl, post_json = True)
|
||||
|
||||
# Trigger exception in filter
|
||||
pid = client.post("/run/dummy", { "data": -1 })
|
||||
pid = client.post("/run/testfilter", { "data": -1 })
|
||||
time.sleep(0.5)
|
||||
status = client.get("/process/status", { "pid": pid })
|
||||
eq_(status["alive"], False)
|
||||
|
@ -141,7 +141,7 @@ class TestClient(object):
|
|||
client.post("/process/remove", { "pid": pid })
|
||||
|
||||
# Kill a running filter by removing it early
|
||||
newpid = client.post("/run/dummy", { "data": 50 })
|
||||
newpid = client.post("/run/testfilter", { "data": 50 })
|
||||
ne_(newpid, pid)
|
||||
time.sleep(0.5)
|
||||
start = time.time()
|
||||
|
@ -156,7 +156,7 @@ class TestClient(object):
|
|||
eq_(client.get("/process/list"), [])
|
||||
|
||||
# Try to remove a running filter that ignored SIGTERM
|
||||
pid = client.post("/run/dummy", { "data": 0 })
|
||||
pid = client.post("/run/testfilter", { "data": 0 })
|
||||
start = time.time()
|
||||
status = client.post("/process/remove", { "pid": pid })
|
||||
elapsed = time.time() - start
|
||||
|
@ -165,6 +165,7 @@ class TestClient(object):
|
|||
eq_(status["alive"], False)
|
||||
ne_(status["exitcode"], 0)
|
||||
|
||||
@unittest.skip("trainola moving to nilmtools")
|
||||
def test_client_05_trainola_simple(self):
|
||||
client = HTTPClient(baseurl = testurl, post_json = True)
|
||||
pid = client.post("/run/trainola", { "data": {} })
|
||||
|
@ -172,7 +173,7 @@ class TestClient(object):
|
|||
ne_(status["exitcode"], 0)
|
||||
status = client.post("/process/remove", { "pid": pid })
|
||||
|
||||
@unittest.skip("needs a running nilmdb")
|
||||
@unittest.skip("needs a running nilmdb; trainola moved to nilmtools")
|
||||
def test_client_06_trainola(self):
|
||||
client = HTTPClient(baseurl = testurl, post_json = True)
|
||||
|
Loading…
Reference in New Issue
Block a user