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
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
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
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()
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()
def testGetRoutes(self): profiler = TFProfiler() routes = profiler.get_routes() assert isinstance(routes, dict)
def testPostSetupChecks(self): assert TFProfiler.post_setup_check()
def testPostSetupChecksFail(self): tf_profiler.environment_variables.cluster_spec = {} assert not TFProfiler.post_setup_check()
def testCanInitialize(self): assert TFProfiler.can_initialize()
def testCanInitializeOldTFVersion(self): import tensorflow with mock.patch.dict(tensorflow.__dict__, {"__version__": "2.3.0"}): assert not TFProfiler.can_initialize()
def testCanInitializeNoClusterSpec(self): tf_profiler.environment_variables.cluster_spec = None assert not TFProfiler.can_initialize()
def testCanInitializeJobIdUnset(self): tf_profiler.environment_variables.cloud_ml_job_id = None assert not TFProfiler.can_initialize()
def testCanInitializeTBResourceNameUnset(self): tf_profiler.environment_variables.tensorboard_resource_name = None assert not TFProfiler.can_initialize()
def testCanInitializeTBAPIuriUnset(self): tf_profiler.environment_variables.tensorboard_api_uri = None assert not TFProfiler.can_initialize()
def testCanInitializeTBLogDirUnset(self): tf_profiler.environment_variables.tensorboard_log_dir = None assert not TFProfiler.can_initialize()
def testCanInitializeProfilerPortUnset(self): tf_profiler.environment_variables.tf_profiler_port = None assert not TFProfiler.can_initialize()