def test_bad_server_init(self): s = Server(port=36710, ml=FittingInterface, ml_config={ 'shit': False, 'poop': True }) with self.assertRaises(RuntimeError): s()
def setUpClass(cls): a = [[255, 128, 3], [255, 127, 2], [253, 125, 0]] cls._data = np.array([[[a, a, a], [a, a, a]], [[a, a, a], [a, a, a]]]) cls._short_server = Server(port=36789, ml=FittingInterface(), log=False) cls._short_server_address = 'http://127.0.0.1:36789' cls._pr1 = Process(target=cls._short_server) cls._long_server = Server(port=36790, ml=FittingInterface(True), log=False) cls._pr2 = Process(target=cls._long_server) cls._long_server_address = 'http://127.0.0.1:36790' cls._sm = StateMachine(port=36791, ml=FittingInterface(False), log=False) cls._pr3 = Process(target=cls._sm) cls._sm_address = 'http://127.0.0.1:36791' cls._pr1.start() cls._pr2.start() cls._pr3.start()
def test_ready_safe(self): s = Server(port=36795, ml=FittingInterface, ml_config={ 'long_predict': False, 'long_init': True }) pr = Process(target=s) client = Client(address='http://127.0.0.1:36795') pr.start() while not client.ready(): pass pr.terminate()
def test_fails(self): s = Server(port=36795, ml=FailingInterface, ml_config={ 'long_predict': False, 'long_init': True }) pr = Process(target=s) client = Client(address='http://127.0.0.1:36795') pr.start() while not client.ready(): pass with self.assertRaises(ValueError): res = client.predict(self._data) res.result() pr.terminate()
def test_ready(self): s = Server(port=36794, ml=FittingInterface, ml_config={ 'long_predict': False, 'long_init': True }) pr = Process(target=s) client = Client(address='http://127.0.0.1:36794') self.assertFalse(client.started()) res = client.predict(self._data) self.assertIsNotNone(res.exception()) pr.start() while not client.started(): pass self.assertFalse(client.ready()) while not client.ready(): pass self.assertTrue(client.ready()) pr.terminate()
def run_server(port): predictor = IDS() server = Server(port=port, ml=predictor) server()
def test_interface(self): with self.assertRaises(ValueError): Server(port=36789, ml='test')
def test_init_ml(self): Server(port=36795, ml=FittingInterface, ml_config={})