def test_new_report(self):
     server = MriServerDispatch({'title': 'test'}, HTTP_BIN, 'test', 'tester')
     old = ServerConsts.API_URL.REPORT
     ServerConsts.API_URL.REPORT = '/post'
     result = server._new_report()
     ServerConsts.API_URL.REPORT = old
     self.assertEqual(result['data'], '{"title": "test"}')
 def test_formatting(self):
     server = MriServerDispatch({'id': 'abcde'}, HTTP_BIN, 'test', 'tester')
     event = TrainingEvent({'iteration': 100, 'loss': 200, 'accuracy': 300}, 'iteration')
     data = server._format_train_request(event)
     correct = json.dumps(
         {"type": "train.abcde", "properties": {"iteration": 100, "loss": 200, "accuracy": 300}}
     )
     self.assertEqual(data, correct)
 def test_train_event(self):
     # Check post
     server = MriServerDispatch({}, HTTP_BIN, 'test', 'tester')
     data = json.dumps(
         {"type": "train.abcde", "properties": {"iteration": 100, "loss": 200, "accuracy": 300}}
     )
     result = server._send_request('/post', 'POST', data)
     self.assertEqual(result.status_code, 200)
     self.assertTrue('train.abcde' in result.text)
Exemplo n.º 4
0
    def _gen_dispatch(self, task):
        # Get dispatch based on type
        dispatch_type = self._get_config('mri-client', 'dispatch').lower()
        if dispatch_type == 'matplotlib-dispatch':
            folder = os.path.join(
                self._get_config('matplotlib-dispatch', 'save_img_folder'))
            dispatch = MatplotlibDispatch(task, folder)
            windows = self._get_config('matplotlib-dispatch', 'show_windows')
            if windows:
                show_windows = windows.lower() == 'true'
            else:
                show_windows = False

            dispatch.setup_display('iteration',
                                   ['iteration', 'loss', 'accuracy'],
                                   show_windows=show_windows)
        elif dispatch_type == 'mri-server-dispatch':
            url = self._get_config('mri-server-dispatch', 'url')
            username = self._get_config('mri-server-dispatch', 'username')
            password = self._get_config('mri-server-dispatch', 'password')
            dispatch = MriServerDispatch(task, url, username, password)
            dispatch.setup_display('iteration',
                                   ['iteration', 'loss', 'accuracy'])
        else:
            logging.error(
                'Invalid configuration file, please select a dispatch')
            raise Exception(
                'Invalid configuration file, please select a dispatch')

        return dispatch
 def test_new_dispatch(self):
     server = MriServer("http://www.httpbin.com", "testuser", "testpass")
     task = {"title": "TEST", "id": "000112233"}
     dispatch = server.new_dispatch(task)
     test_against = MriServerDispatch(task, "http://www.httpbin.com",
                                      "testuser", "testpass")
     self.assertEqual(dispatch, test_against)
    def test_format_report(self):
        server = MriServerDispatch({'title': 'test', 'id': 'cbdcig'}, HTTP_BIN, 'test', 'tester')
        # Save const states
        old_id = ServerConsts.API_URL.REPORT_ID
        old = ServerConsts.API_URL.REPORT
        ServerConsts.API_URL.REPORT_ID = '/put'
        ServerConsts.API_URL.REPORT = '/post'

        # Test
        result = server.setup_display('iteration', ['iteration', 'loss', 'accuracy'])
        obj = json.loads(result.text)['json']

        # Restore states
        ServerConsts.API_URL.REPORT = old
        ServerConsts.API_URL.REPORT_ID = old_id

        self.assertEqual('big', obj['visualizations'][0]['configuration']['size'])
        self.assertEqual('train.cbdcig', obj['visualizations'][0]['eventName'])
 def test_exceptions(self):
     # Check that we gracefully handle failed servers
     server = MriServerDispatch({}, 'http://thiswontworkatall', 'test', 'tester')
     result = server._send_request('/', 'GET', None)
     self.assertEqual(result, None)
     # Check that we fail gracefully on invalid urls
     server = MriServerDispatch({}, 'http://744.255.255.1', 'test', 'tester')
     result = server._send_request('/get', 'GET', None)
     self.assertEqual(result, None)
     # Check that we can detect 404s
     server = MriServerDispatch({}, HTTP_BIN, 'test', 'tester')
     result = server._send_request('/thisisntarealpath', 'GET', None)
     self.assertEqual(result.status_code, 404)
 def test_basic_requests(self):
     # Check basic functionality
     server = MriServerDispatch({}, HTTP_BIN, 'test', 'tester')
     result = server._send_request('/get', 'GET', None)
     self.assertEqual(result.status_code, 200)
     # Check auth
     server = MriServerDispatch({}, HTTP_BIN, 'test', 'tester')
     result = server._send_request('/basic-auth/test/tester', 'GET', None)
     self.assertEqual(result.status_code, 200)
     # Check post
     server = MriServerDispatch({}, HTTP_BIN, 'test', 'tester')
     data = json.dumps({'introducing': 'kitton mittons'})
     result = server._send_request('/post', 'POST', data)
     self.assertEqual(result.status_code, 200)
 def test_format_train_request(self):
     server = MriServerDispatch({'title': 'test', 'id': 'cbdcig'}, HTTP_BIN, 'test', 'tester')
     event = TrainingEvent({'iteration': 100, 'loss': 0.5, 'accuracy': 0.6}, 'iteration')
     payload = server._format_train_request(event)
     self.assertTrue('train.cbdcig' in payload)
     self.assertTrue('"accuracy": 0.6' in payload)