def setUp(self):
    self.log_dir = tempfile.mkdtemp()

    # We use numpy.random to generate images. We seed to avoid non-determinism
    # in this test.
    numpy.random.seed(42)

    # Create old-style image summaries for run "foo".
    tf.reset_default_graph()
    sess = tf.Session()
    placeholder = tf.placeholder(tf.uint8)
    tf.summary.image(name="baz", tensor=placeholder)
    merged_summary_op = tf.summary.merge_all()
    foo_directory = os.path.join(self.log_dir, "foo")
    writer = tf.summary.FileWriter(foo_directory)
    writer.add_graph(sess.graph)
    for step in xrange(2):
      writer.add_summary(sess.run(merged_summary_op, feed_dict={
          placeholder: (numpy.random.rand(1, 16, 42, 3) * 255).astype(
              numpy.uint8)
      }), global_step=step)
    writer.close()

    # Create new-style image summaries for run bar.
    tf.reset_default_graph()
    sess = tf.Session()
    placeholder = tf.placeholder(tf.uint8)
    summary.op(name="quux", images=placeholder,
               description="how do you pronounce that, anyway?")
    merged_summary_op = tf.summary.merge_all()
    bar_directory = os.path.join(self.log_dir, "bar")
    writer = tf.summary.FileWriter(bar_directory)
    writer.add_graph(sess.graph)
    for step in xrange(2):
      writer.add_summary(sess.run(merged_summary_op, feed_dict={
          placeholder: (numpy.random.rand(1, 6, 8, 3) * 255).astype(
              numpy.uint8)
      }), global_step=step)
    writer.close()

    # Start a server with the plugin.
    multiplexer = event_multiplexer.EventMultiplexer({
        "foo": foo_directory,
        "bar": bar_directory,
    })
    context = base_plugin.TBContext(
        logdir=self.log_dir, multiplexer=multiplexer)
    plugin = images_plugin.ImagesPlugin(context)
    wsgi_app = application.TensorBoardWSGIApp(
        self.log_dir, [plugin], multiplexer, reload_interval=0)
    self.server = werkzeug_test.Client(wsgi_app, wrappers.BaseResponse)
    self.routes = plugin.get_plugin_apps()
示例#2
0
    def setUp(self):
        self.log_dir = tempfile.mkdtemp()

        # We use numpy.random to generate audio. We seed to avoid non-determinism
        # in this test.
        numpy.random.seed(42)

        # Create audio summaries for run foo.
        tf.reset_default_graph()
        sess = tf.Session()
        placeholder = tf.placeholder(tf.float32)
        tf.summary.audio(name="baz", tensor=placeholder, sample_rate=44100)
        merged_summary_op = tf.summary.merge_all()
        foo_directory = os.path.join(self.log_dir, "foo")
        writer = tf.summary.FileWriter(foo_directory)
        writer.add_graph(sess.graph)
        for step in xrange(2):
            # The floats (sample data) range from -1 to 1.
            writer.add_summary(sess.run(
                merged_summary_op,
                feed_dict={placeholder: numpy.random.rand(42, 22050) * 2 - 1}),
                               global_step=step)
        writer.close()

        # Create audio summaries for run bar.
        tf.reset_default_graph()
        sess = tf.Session()
        placeholder = tf.placeholder(tf.float32)
        tf.summary.audio(name="quux", tensor=placeholder, sample_rate=44100)
        merged_summary_op = tf.summary.merge_all()
        bar_directory = os.path.join(self.log_dir, "bar")
        writer = tf.summary.FileWriter(bar_directory)
        writer.add_graph(sess.graph)
        for step in xrange(2):
            # The floats (sample data) range from -1 to 1.
            writer.add_summary(sess.run(
                merged_summary_op,
                feed_dict={placeholder: numpy.random.rand(42, 11025) * 2 - 1}),
                               global_step=step)
        writer.close()

        # Start a server with the plugin.
        multiplexer = event_multiplexer.EventMultiplexer({
            "foo": foo_directory,
            "bar": bar_directory,
        })
        plugin = audio_plugin.AudioPlugin()
        wsgi_app = application.TensorBoardWSGIApp(self.log_dir, [plugin],
                                                  multiplexer,
                                                  reload_interval=0)
        self.server = werkzeug_test.Client(wsgi_app, wrappers.BaseResponse)
        self.routes = plugin.get_plugin_apps(multiplexer, self.log_dir)
示例#3
0
 def testNgComponentPluginWithIncompatibleSetElementName(self):
     plugins = [
         FakePlugin(
             plugin_name="quux",
             is_ng_component=True,
             element_name_value="incompatible",
         ),
     ]
     app = application.TensorBoardWSGI(plugins)
     server = werkzeug_test.Client(app, wrappers.Response)
     with self.assertRaisesRegex(ValueError,
                                 "quux.*declared.*both Angular.*legacy"):
         server.get("/data/plugins_listing")
示例#4
0
    def test_successful_response_passes_through(self):
        @application._handling_errors
        @wrappers.Request.application
        def app(request):
            return wrappers.Response(
                "All is well", 200, content_type="text/html"
            )

        server = werkzeug_test.Client(app, wrappers.BaseResponse)
        response = server.get("/")
        self.assertEqual(response.get_data(), b"All is well")
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.headers.get("Content-Type"), "text/html")
示例#5
0
    def test_passes_through_non_wsgi_args(self):
        class C(object):
            @application._handling_errors
            def __call__(self, environ, start_response):
                start_response('200 OK', [('Content-Type', 'text/html')])
                yield b'All is well'

        app = C()
        server = werkzeug_test.Client(app, wrappers.BaseResponse)
        response = server.get('/')
        self.assertEqual(response.get_data(), b'All is well')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.headers.get('Content-Type'), 'text/html')
示例#6
0
    def test_empty_path_prefix(self):
        app = path_prefix.PathPrefixMiddleware(self._echo_app, "")
        server = werkzeug_test.Client(app, werkzeug.wrappers.BaseResponse)

        with self.subTest("at empty"):
            self._assert_ok(server.get(""), path="", script="")

        with self.subTest("at root"):
            self._assert_ok(server.get("/"), path="/", script="")

        with self.subTest("at subpath"):
            response = server.get("/foo/bar")
            self._assert_ok(server.get("/foo/bar"), path="/foo/bar", script="")
 def testNgComponentPluginWithIncompatiblEsModulePath(self):
     plugins = [
         FakePlugin(
             plugin_name="quux",
             is_ng_component=True,
             es_module_path_value="//incompatible",
         ),
     ]
     app = application.TensorBoardWSGI(plugins)
     server = werkzeug_test.Client(app, wrappers.BaseResponse)
     with six.assertRaisesRegex(self, ValueError,
                                "quux.*declared.*both Angular.*iframed"):
         server.get("/data/plugins_listing")
示例#8
0
 def _start_logdir_based_server(self, temp_dir):
   self.logdir = temp_dir
   self.multiplexer = event_multiplexer.EventMultiplexer(
       size_guidance=application.DEFAULT_SIZE_GUIDANCE,
       purge_orphaned_data=True)
   context = base_plugin.TBContext(
       assets_zip_provider=get_test_assets_zip_provider(),
       logdir=self.logdir,
       multiplexer=self.multiplexer,
       window_title='title foo')
   self.logdir_based_plugin = core_plugin.CorePlugin(context)
   app = application.TensorBoardWSGI([self.logdir_based_plugin])
   self.logdir_based_server = werkzeug_test.Client(app, wrappers.BaseResponse)
    def setUp(self):
        # pylint: disable=g-import-not-at-top
        # Pre-import modules to patch them in advance.
        from google.appengine.ext.vmruntime import vmconfig

        # Instantiate an app with a simple fake configuration.
        with patch.object(wsgi_config, 'get_module_config_filename'):
            with patch.object(wsgi_config,
                              'get_module_config',
                              return_value=FAKE_APPINFO_EXTERNAL):
                with patch.object(vmconfig,
                                  'BuildVmAppengineEnvConfig',
                                  return_value=FAKE_APPENGINE_CONFIG):
                    import wsgi
                    self.app = wsgi.meta_app
        self.client = test.Client(self.app, wrappers.Response)
        # Separate client for concurrent tests.
        self.spare_client = test.Client(self.app, wrappers.Response)

        # Clear the global event flags (only used in concurrency tests).
        concurrent_request_is_started.clear()
        concurrent_request_should_proceed.clear()
示例#10
0
 def setUp(self):
     plugins = [
         FakePlugin(None,
                    plugin_name='foo',
                    is_active_value=True,
                    routes_mapping={}),
         FakePlugin(None,
                    plugin_name='bar',
                    is_active_value=False,
                    routes_mapping={}),
     ]
     app = application.TensorBoardWSGI(plugins)
     self.server = werkzeug_test.Client(app, wrappers.BaseResponse)
 def test_download_url_csv(self):
     wsgi_app = application.TensorBoardWSGI([self.plugin])
     server = werkzeug_test.Client(wsgi_app, wrappers.BaseResponse)
     response = server.get(
         "/data/plugin/custom_scalars/download_data?run=%s&tag=%s&format=csv"
         % ("foo", "squares/scalar_summary"))
     self.assertEqual(200, response.status_code)
     self.assertEqual("text/csv; charset=utf-8",
                      response.headers["Content-Type"])
     payload = response.get_data()
     s = io.StringIO(payload.decode("utf-8"))
     reader = csv.reader(s)
     self.assertEqual(["Wall time", "Step", "Value"], next(reader))
     self.assertEqual(len(list(reader)), 4)
示例#12
0
 def setUp(self):
     super(CorePluginDbModeTest, self).setUp()
     self.db_path = os.path.join(self.get_temp_dir(), "db.db")
     self.db_uri = "sqlite:" + self.db_path
     db_connection_provider = application.create_sqlite_connection_provider(
         self.db_uri)
     context = base_plugin.TBContext(
         assets_zip_provider=get_test_assets_zip_provider(),
         db_connection_provider=db_connection_provider,
         db_uri=self.db_uri,
     )
     self.plugin = core_plugin.CorePlugin(context)
     app = application.TensorBoardWSGI([self.plugin])
     self.server = werkzeug_test.Client(app, wrappers.BaseResponse)
示例#13
0
 def setUp(self):
     super(CorePluginResourceTest, self).setUp()
     self.logdir = self.get_temp_dir()
     self.multiplexer = event_multiplexer.EventMultiplexer()
     provider = data_provider.MultiplexerDataProvider(
         self.multiplexer, self.logdir)
     context = base_plugin.TBContext(
         assets_zip_provider=get_test_assets_zip_provider(),
         logdir=self.logdir,
         data_provider=provider,
     )
     self.plugin = core_plugin.CorePlugin(context)
     app = application.TensorBoardWSGI([self.plugin])
     self.server = werkzeug_test.Client(app, wrappers.BaseResponse)
 def test_download_url_json(self):
     wsgi_app = application.TensorBoardWSGI([self.plugin])
     server = werkzeug_test.Client(wsgi_app, wrappers.BaseResponse)
     response = server.get(
         "/data/plugin/custom_scalars/download_data?run=%s&tag=%s" %
         ("foo", "squares/scalar_summary"))
     self.assertEqual(200, response.status_code)
     self.assertEqual("application/json", response.headers["Content-Type"])
     body = json.loads(response.get_data())
     self.assertEqual(4, len(body))
     for step, entry in enumerate(body):
         # The time stamp should be reasonable.
         self.assertGreater(entry[0], 0)
         self.assertEqual(step, entry[1])
         np.testing.assert_allclose(step * step, entry[2])
    def setUp(self):
        super(InteractiveDebuggerPluginTest, self).setUp()

        self._dummy_logdir = tempfile.mkdtemp()
        dummy_multiplexer = event_multiplexer.EventMultiplexer({})
        self._debugger_port = portpicker.pick_unused_port()
        self._debugger_url = "grpc://localhost:%d" % self._debugger_port
        context = base_plugin.TBContext(logdir=self._dummy_logdir,
                                        multiplexer=dummy_multiplexer)
        self._debugger_plugin = interactive_debugger_plugin.InteractiveDebuggerPlugin(
            context)
        self._debugger_plugin.listen(self._debugger_port)

        wsgi_app = application.TensorBoardWSGI([self._debugger_plugin])
        self._server = werkzeug_test.Client(wsgi_app, wrappers.BaseResponse)
示例#16
0
    def test_public_errors_serve_response(self):
        @application._handling_errors
        @wrappers.Request.application
        def app(request):
            raise errors.NotFoundError('no scalar data for run=foo, tag=bar')

        server = werkzeug_test.Client(app, wrappers.BaseResponse)
        response = server.get('/')
        self.assertEqual(
            response.get_data(),
            b'Not found: no scalar data for run=foo, tag=bar',
        )
        self.assertEqual(response.status_code, 404)
        self.assertStartsWith(response.headers.get('Content-Type'),
                              'text/plain')
示例#17
0
 def test_download_url_json(self):
     plugin = self.load_plugin([self._RUN_WITH_SCALARS])
     wsgi_app = application.TensorBoardWSGI([plugin])
     server = werkzeug_test.Client(wsgi_app, wrappers.BaseResponse)
     response = server.get(
         "/data/plugin/scalars/scalars?run=%s&tag=%s"
         % (
             self._RUN_WITH_SCALARS,
             "%s/scalar_summary" % self._SCALAR_TAG,
         )
     )
     self.assertEqual(200, response.status_code)
     self.assertEqual("application/json", response.headers["Content-Type"])
     payload = json.loads(response.get_data())
     self.assertEqual(len(payload), self._STEPS)
示例#18
0
 def _send_request(self, path_prefix, pathname):
     multiplexer = event_multiplexer.EventMultiplexer()
     logdir = self.get_temp_dir()
     provider = data_provider.MultiplexerDataProvider(multiplexer, logdir)
     context = base_plugin.TBContext(
         assets_zip_provider=get_test_assets_zip_provider(),
         logdir=logdir,
         data_provider=provider,
         window_title="",
         flags=FakeFlags(path_prefix=path_prefix),
     )
     plugin = core_plugin.CorePlugin(context)
     app = application.TensorBoardWSGI([plugin], path_prefix=path_prefix)
     server = werkzeug_test.Client(app, wrappers.BaseResponse)
     return server.get(pathname)
 def setUp(self):
   self.logdir = self.get_temp_dir()
   self.addCleanup(shutil.rmtree, self.logdir)
   self._generate_test_data(run_name='run1')
   self.multiplexer = event_multiplexer.EventMultiplexer(
       size_guidance=application.DEFAULT_SIZE_GUIDANCE,
       purge_orphaned_data=True)
   self._context = base_plugin.TBContext(
       assets_zip_provider=application.get_default_assets_zip_provider(),
       logdir=self.logdir,
       multiplexer=self.multiplexer)
   self.plugin = core_plugin.CorePlugin(self._context)
   app = application.TensorBoardWSGIApp(
       self.logdir, [self.plugin], self.multiplexer, 0)
   self.server = werkzeug_test.Client(app, wrappers.BaseResponse)
示例#20
0
    def testEnvironmentDebugOnExplicitly(self):
        multiplexer = event_multiplexer.EventMultiplexer()
        logdir = self.get_temp_dir()
        provider = data_provider.MultiplexerDataProvider(multiplexer, logdir)
        context = base_plugin.TBContext(
            assets_zip_provider=get_test_assets_zip_provider(),
            logdir=logdir,
            data_provider=provider,
            window_title="title foo",
        )
        plugin = core_plugin.CorePlugin(context, include_debug_info=True)
        app = application.TensorBoardWSGI([plugin])
        server = werkzeug_test.Client(app, wrappers.BaseResponse)

        parsed_object = self._get_json(server, "/data/environment")
        self.assertIn("debug", parsed_object)
示例#21
0
 def setUp(self):
     plugins = [
         FakePlugin(plugin_name="foo"),
         FakePlugin(
             plugin_name="bar",
             is_active_value=False,
             element_name_value="tf-bar-dashboard",
         ),
         FakePlugin(
             plugin_name="baz",
             routes_mapping={"/esmodule": lambda req: None,},
             es_module_path_value="/esmodule",
         ),
     ]
     app = application.TensorBoardWSGI(plugins, path_prefix=self.path_prefix)
     self.server = werkzeug_test.Client(app, wrappers.BaseResponse)
示例#22
0
 def setUp(self):
     plugins = [
         FakePlugin(plugin_name='foo'),
         FakePlugin(
             plugin_name='bar',
             is_active_value=False,
             element_name_value='tf-bar-dashboard',
         ),
         FakePlugin(plugin_name='baz',
                    routes_mapping={
                        '/esmodule': lambda req: None,
                    },
                    es_module_path_value='/esmodule'),
     ]
     app = application.TensorBoardWSGI(plugins)
     self.server = werkzeug_test.Client(app, wrappers.BaseResponse)
示例#23
0
 def test_download_url_csv(self):
     plugin = self.load_plugin([self._RUN_WITH_SCALARS])
     wsgi_app = application.TensorBoardWSGI([plugin])
     server = werkzeug_test.Client(wsgi_app, wrappers.Response)
     response = server.get(
         "/data/plugin/scalars/scalars?run=%s&tag=%s&format=csv" % (
             self._RUN_WITH_SCALARS,
             "%s/scalar_summary" % self._SCALAR_TAG,
         ))
     self.assertEqual(200, response.status_code)
     self.assertEqual("text/csv; charset=utf-8",
                      response.headers["Content-Type"])
     payload = response.get_data()
     s = io.StringIO(payload.decode("utf-8"))
     reader = csv.reader(s)
     self.assertEqual(["Wall time", "Step", "Value"], next(reader))
     self.assertEqual(len(list(reader)), self._STEPS)
示例#24
0
 def startDbBasedServer(self, temp_dir):
     self.db_uri = 'sqlite:' + os.path.join(temp_dir, 'db.sqlite')
     db_module, db_connection_provider = application.get_database_info(
         self.db_uri)
     if db_connection_provider is not None:
         with contextlib.closing(db_connection_provider()) as db_conn:
             schema = db.Schema(db_conn)
             schema.create_tables()
             schema.create_indexes()
     context = base_plugin.TBContext(
         assets_zip_provider=get_test_assets_zip_provider(),
         db_module=db_module,
         db_connection_provider=db_connection_provider,
         db_uri=self.db_uri,
         window_title='title foo')
     self.db_based_plugin = core_plugin.CorePlugin(context)
     app = application.TensorBoardWSGI([self.db_based_plugin])
     self.db_based_server = werkzeug_test.Client(app, wrappers.BaseResponse)
    def make_request_and_maybe_assert_warn(
        self,
        headers,
        expected_warn_substr,
    ):
        @werkzeug.Request.application
        def _simple_app(req):
            return werkzeug.Response("OK", headers=headers)

        app = security_validator.SecurityValidatorMiddleware(_simple_app)
        server = werkzeug_test.Client(app, BaseResponse)

        with mock.patch.object(logger, "warning") as mock_warn:
            server.get("")

        if expected_warn_substr is None:
            mock_warn.assert_not_called()
        else:
            mock_warn.assert_called_with(_WARN_PREFIX + expected_warn_substr)
示例#26
0
    def setUp(self):
        super(DebuggerV2PluginTest, self).setUp()
        self.logdir = self.get_temp_dir()
        context = base_plugin.TBContext(logdir=self.logdir)
        self.plugin = debugger_v2_plugin.DebuggerV2Plugin(context)
        wsgi_app = application.TensorBoardWSGI([self.plugin])
        self.server = werkzeug_test.Client(wsgi_app, wrappers.BaseResponse)
        # The multiplexer reads data asynchronously on a separate thread, so
        # as not to block the main thread of the TensorBoard backend. During
        # unit test, we disable the asynchronous behavior, so that we can
        # load the debugger data synchronously on the main thread and get
        # determinisic behavior in the tests.
        def run_in_background_mock(target):
            target()

        self.run_in_background_patch = tf.compat.v1.test.mock.patch.object(
            debug_data_multiplexer, "run_in_background", run_in_background_mock
        )
        self.run_in_background_patch.start()
示例#27
0
 def setUp(self):
     super(CorePluginTestBase, self).setUp()
     self.logdir = self.get_temp_dir()
     self.multiplexer = self.create_multiplexer()
     db_uri = None
     db_connection_provider = None
     if isinstance(self.multiplexer,
                   db_import_multiplexer.DbImportMultiplexer):
         db_uri = self.multiplexer.db_uri
         db_connection_provider = self.multiplexer.db_connection_provider
     context = base_plugin.TBContext(
         assets_zip_provider=get_test_assets_zip_provider(),
         logdir=self.logdir,
         multiplexer=self.multiplexer,
         db_uri=db_uri,
         db_connection_provider=db_connection_provider,
     )
     self.plugin = core_plugin.CorePlugin(context)
     app = application.TensorBoardWSGI([self.plugin])
     self.server = werkzeug_test.Client(app, wrappers.BaseResponse)
    def test_public_errors_serve_response(self):
        @application._handling_errors
        @wrappers.Request.application
        def app(request):
            raise errors.UnauthenticatedError(
                "who are you?", challenge='Digest realm="https://example.com"')

        server = werkzeug_test.Client(app, wrappers.BaseResponse)
        response = server.get("/")
        self.assertEqual(
            response.get_data(),
            b"Unauthenticated: who are you?",
        )
        self.assertEqual(response.status_code, 401)
        self.assertStartsWith(response.headers.get("Content-Type"),
                              "text/plain")
        self.assertEqual(
            response.headers.get("WWW-Authenticate"),
            'Digest realm="https://example.com"',
        )
示例#29
0
 def setUp(self):
     plugins = [
         FakePlugin(None,
                    plugin_name='foo',
                    is_active_value=True,
                    routes_mapping={}),
         FakePlugin(None,
                    plugin_name='bar',
                    is_active_value=False,
                    routes_mapping={}),
         FakePlugin(None,
                    plugin_name='baz',
                    is_active_value=True,
                    routes_mapping={
                        '/esmodule': lambda req: None,
                    },
                    es_module_path_value='/esmodule'),
     ]
     app = application.TensorBoardWSGI(plugins,
                                       path_prefix=self.path_prefix)
     self.server = werkzeug_test.Client(app, wrappers.BaseResponse)
示例#30
0
    def setUp(self):
        super(LitePluginTest, self).setUp()
        logdir = os.path.join(self.get_temp_dir(), "logdir")
        run_logdir = os.path.join(logdir, "0")
        saved_model_dir = os.path.join(logdir, "0", "exported_saved_model")
        model = lite_demo_model.generate_run(run_logdir, saved_model_dir)

        self.input_arrays = lite_demo_model.INPUT_TENSOR_ARRAYS
        self.output_arrays = lite_demo_model.OUTPUT_TENSOR_ARRAYS

        # Create a multiplexer for reading the data we just wrote.
        multiplexer = event_multiplexer.EventMultiplexer()
        multiplexer.AddRunsFromDirectory(logdir)
        multiplexer.Reload()
        context = base_plugin.TBContext(logdir=logdir, multiplexer=multiplexer)

        self.plugin = lite_plugin.LitePlugin(context)
        # TODO(tensorflow/tensorboard#2573): Remove TensorBoardWSGI wrapper.
        wsgi_app = application.TensorBoardWSGI([self.plugin])
        self.server = werkzeug_test.Client(wsgi_app, wrappers.BaseResponse)

        self.routes = self.plugin.get_plugin_apps()