コード例 #1
0
    def testCaptureProfile(self):
        profiler = TFProfiler()
        environ = dict(QUERY_STRING="?service_addr=myhost1,myhost2&someotherdata=5")
        start_response = None

        resp = profiler.capture_profile_wrapper(environ, start_response)
        assert resp[0].status_code == 200
コード例 #2
0
    def testSetup(self):
        import tensorflow

        with mock.patch.object(
            tensorflow.profiler.experimental.server, "start", return_value=None
        ) as server_mock:
            TFProfiler.setup()

            assert server_mock.call_count == 1
コード例 #3
0
    def testCaptureProfileNoCluster(self):
        profiler = TFProfiler()

        environ = dict(QUERY_STRING="?service_addr=myhost1,myhost2&someotherdata=5")
        start_response = None
        tf_profiler.environment_variables.cluster_spec = {"cluster": {}}

        resp = profiler.capture_profile_wrapper(environ, start_response)

        assert resp.status_code == 500
コード例 #4
0
    def testCanInitializeTFInstalled(self):
        orig_find_spec = importlib.util.find_spec

        def tf_import_mock(name, *args, **kwargs):
            if name == "tensorflow":
                return None
            return orig_find_spec(name, *args, **kwargs)

        with mock.patch("importlib.util.find_spec", side_effect=tf_import_mock):
            assert not TFProfiler.can_initialize()
コード例 #5
0
    def testCanInitializeNoProfilePlugin(self):
        orig_find_spec = importlib.util.find_spec

        def plugin_import_mock(name, *args, **kwargs):
            if name == "tensorboard_plugin_profile":
                return None
            return orig_find_spec(name, *args, **kwargs)

        with mock.patch("importlib.util.find_spec", side_effect=plugin_import_mock):
            assert not TFProfiler.can_initialize()
コード例 #6
0
    def testGetRoutes(self):
        profiler = TFProfiler()

        routes = profiler.get_routes()
        assert isinstance(routes, dict)
コード例 #7
0
 def testPostSetupChecks(self):
     assert TFProfiler.post_setup_check()
コード例 #8
0
 def testPostSetupChecksFail(self):
     tf_profiler.environment_variables.cluster_spec = {}
     assert not TFProfiler.post_setup_check()
コード例 #9
0
 def testCanInitialize(self):
     assert TFProfiler.can_initialize()
コード例 #10
0
    def testCanInitializeOldTFVersion(self):
        import tensorflow

        with mock.patch.dict(tensorflow.__dict__, {"__version__": "2.3.0"}):
            assert not TFProfiler.can_initialize()
コード例 #11
0
 def testCanInitializeNoClusterSpec(self):
     tf_profiler.environment_variables.cluster_spec = None
     assert not TFProfiler.can_initialize()
コード例 #12
0
 def testCanInitializeJobIdUnset(self):
     tf_profiler.environment_variables.cloud_ml_job_id = None
     assert not TFProfiler.can_initialize()
コード例 #13
0
 def testCanInitializeTBResourceNameUnset(self):
     tf_profiler.environment_variables.tensorboard_resource_name = None
     assert not TFProfiler.can_initialize()
コード例 #14
0
 def testCanInitializeTBAPIuriUnset(self):
     tf_profiler.environment_variables.tensorboard_api_uri = None
     assert not TFProfiler.can_initialize()
コード例 #15
0
 def testCanInitializeTBLogDirUnset(self):
     tf_profiler.environment_variables.tensorboard_log_dir = None
     assert not TFProfiler.can_initialize()
コード例 #16
0
 def testCanInitializeProfilerPortUnset(self):
     tf_profiler.environment_variables.tf_profiler_port = None
     assert not TFProfiler.can_initialize()