]> average.org Git - loctrkd.git/blobdiff - test/common.py
Cleanup some of the types
[loctrkd.git] / test / common.py
index b9f768c8f55d84573a9149f5de248f955039d32b..58954a2b217acbd0fa5a930476cee1882dea8ff1 100644 (file)
@@ -4,6 +4,7 @@ from configparser import ConfigParser, SectionProxy
 from contextlib import closing, ExitStack
 from http.server import HTTPServer, SimpleHTTPRequestHandler
 from importlib import import_module
 from contextlib import closing, ExitStack
 from http.server import HTTPServer, SimpleHTTPRequestHandler
 from importlib import import_module
+from logging import DEBUG, StreamHandler
 from multiprocessing import Process
 from os import kill, unlink
 from signal import SIGINT
 from multiprocessing import Process
 from os import kill, unlink
 from signal import SIGINT
@@ -16,17 +17,21 @@ from socket import (
     socket,
     SocketType,
 )
     socket,
     SocketType,
 )
-from sys import exit
+from sys import exit, stderr
 from tempfile import mkstemp
 from time import sleep
 from typing import Optional
 from unittest import TestCase
 
 from tempfile import mkstemp
 from time import sleep
 from typing import Optional
 from unittest import TestCase
 
+from loctrkd.common import init_protocols
+
 NUMPORTS = 3
 
 
 class TestWithServers(TestCase):
 NUMPORTS = 3
 
 
 class TestWithServers(TestCase):
-    def setUp(self, *args: str, httpd: bool = False) -> None:
+    def setUp(
+        self, *args: str, httpd: bool = False, verbose: bool = False
+    ) -> None:
         freeports = []
         with ExitStack() as stack:
             for _ in range(NUMPORTS):
         freeports = []
         with ExitStack() as stack:
             for _ in range(NUMPORTS):
@@ -36,6 +41,9 @@ class TestWithServers(TestCase):
                 freeports.append(sk.getsockname()[1])
         _, self.tmpfilebase = mkstemp()
         self.conf = ConfigParser()
                 freeports.append(sk.getsockname()[1])
         _, self.tmpfilebase = mkstemp()
         self.conf = ConfigParser()
+        self.conf["common"] = {
+            "protocols": "zx303proto",
+        }
         self.conf["collector"] = {
             "port": str(freeports[0]),
             "publishurl": "ipc://" + self.tmpfilebase + ".pub",
         self.conf["collector"] = {
             "port": str(freeports[0]),
             "publishurl": "ipc://" + self.tmpfilebase + ".pub",
@@ -48,26 +56,31 @@ class TestWithServers(TestCase):
             "dbfn": self.tmpfilebase + ".opencellid.sqlite",
             "downloadurl": f"http://localhost:{freeports[2]}/test/262.csv.gz",
         }
             "dbfn": self.tmpfilebase + ".opencellid.sqlite",
             "downloadurl": f"http://localhost:{freeports[2]}/test/262.csv.gz",
         }
-        self.conf["lookaside"] = {
-            "backend": "opencellid",
+        self.conf["rectifier"] = {
+            "lookaside": "opencellid",
+            "publishurl": "ipc://" + self.tmpfilebase + ".rect.pub",
         }
         self.conf["wsgateway"] = {
             "port": str(freeports[1]),
         }
         }
         self.conf["wsgateway"] = {
             "port": str(freeports[1]),
         }
+        init_protocols(self.conf)
         self.children = []
         for srvname in args:
             if srvname == "collector":
                 kwargs = {"handle_hibernate": False}
             else:
                 kwargs = {}
         self.children = []
         for srvname in args:
             if srvname == "collector":
                 kwargs = {"handle_hibernate": False}
             else:
                 kwargs = {}
-            cls = import_module("gps303." + srvname, package=".")
+            cls = import_module("loctrkd." + srvname, package=".")
+            if verbose:
+                cls.log.addHandler(StreamHandler(stderr))
+                cls.log.setLevel(DEBUG)
             p = Process(target=cls.runserver, args=(self.conf,), kwargs=kwargs)
             p.start()
             self.children.append((srvname, p))
         if httpd:
             server = HTTPServer(("", freeports[2]), SimpleHTTPRequestHandler)
 
             p = Process(target=cls.runserver, args=(self.conf,), kwargs=kwargs)
             p.start()
             self.children.append((srvname, p))
         if httpd:
             server = HTTPServer(("", freeports[2]), SimpleHTTPRequestHandler)
 
-            def run(server):
+            def run(server: HTTPServer) -> None:
                 try:
                     server.serve_forever()
                 except KeyboardInterrupt:
                 try:
                     server.serve_forever()
                 except KeyboardInterrupt:
@@ -87,11 +100,12 @@ class TestWithServers(TestCase):
             self.assertEqual(
                 p.exitcode,
                 0,
             self.assertEqual(
                 p.exitcode,
                 0,
-                srvname + " terminated with non-zero return code",
+                f"{srvname} terminated with return code {p.exitcode}",
             )
         for sfx in (
             "",
             ".pub",
             )
         for sfx in (
             "",
             ".pub",
+            ".rect.pub",
             ".pul",
             ".storage.sqlite",
             ".opencellid.sqlite",
             ".pul",
             ".storage.sqlite",
             ".opencellid.sqlite",