@@ -81,10 +81,10 @@ class FakePlugin(base_plugin.TBPlugin):
8181 """A plugin with no functionality."""
8282
8383 def __init__ (self ,
84- context ,
85- plugin_name ,
86- is_active_value ,
87- routes_mapping ,
84+ context = None ,
85+ plugin_name = 'foo' ,
86+ is_active_value = True ,
87+ routes_mapping = {} ,
8888 element_name_value = None ,
8989 es_module_path_value = None ,
9090 construction_callback = None ):
@@ -138,19 +138,14 @@ def frontend_metadata(self):
138138class ApplicationTest (tb_test .TestCase ):
139139 def setUp (self ):
140140 plugins = [
141+ FakePlugin (plugin_name = 'foo' ),
141142 FakePlugin (
142- None , plugin_name = 'foo' , is_active_value = True , routes_mapping = {}),
143- FakePlugin (
144- None ,
145143 plugin_name = 'bar' ,
146144 is_active_value = False ,
147- routes_mapping = {},
148145 element_name_value = 'tf-bar-dashboard' ,
149146 ),
150147 FakePlugin (
151- None ,
152148 plugin_name = 'baz' ,
153- is_active_value = True ,
154149 routes_mapping = {
155150 '/esmodule' : lambda req : None ,
156151 },
@@ -216,19 +211,14 @@ class ApplicationBaseUrlTest(tb_test.TestCase):
216211 path_prefix = '/test'
217212 def setUp (self ):
218213 plugins = [
214+ FakePlugin (plugin_name = 'foo' ),
219215 FakePlugin (
220- None , plugin_name = 'foo' , is_active_value = True , routes_mapping = {}),
221- FakePlugin (
222- None ,
223216 plugin_name = 'bar' ,
224217 is_active_value = False ,
225- routes_mapping = {},
226218 element_name_value = 'tf-bar-dashboard' ,
227219 ),
228220 FakePlugin (
229- None ,
230221 plugin_name = 'baz' ,
231- is_active_value = True ,
232222 routes_mapping = {
233223 '/esmodule' : lambda req : None ,
234224 },
@@ -298,89 +288,73 @@ def testPluginsListing(self):
298288
299289class ApplicationPluginNameTest (tb_test .TestCase ):
300290
301- def _test (self , name , should_be_okay ):
302- temp_dir = tempfile .mkdtemp (prefix = self .get_temp_dir ())
303- self .addCleanup (shutil .rmtree , temp_dir )
304- multiplexer = event_multiplexer .EventMultiplexer (
305- size_guidance = application .DEFAULT_SIZE_GUIDANCE ,
306- purge_orphaned_data = True )
307- plugins = [
308- FakePlugin (
309- None , plugin_name = 'foo' , is_active_value = True , routes_mapping = {}),
310- FakePlugin (
311- None , plugin_name = name , is_active_value = True , routes_mapping = {}),
312- FakePlugin (
313- None , plugin_name = 'bar' , is_active_value = False , routes_mapping = {}),
314- ]
315- if should_be_okay :
316- application .TensorBoardWSGIApp (
317- temp_dir , plugins , multiplexer , reload_interval = 0 ,
318- path_prefix = '' )
319- else :
320- with six .assertRaisesRegex (self , ValueError , r'invalid name' ):
321- application .TensorBoardWSGIApp (
322- temp_dir , plugins , multiplexer , reload_interval = 0 ,
323- path_prefix = '' )
291+ def testSimpleName (self ):
292+ application .TensorBoardWSGI (
293+ plugins = [FakePlugin (plugin_name = 'scalars' )])
294+
295+ def testComprehensiveName (self ):
296+ application .TensorBoardWSGI (
297+ plugins = [FakePlugin (plugin_name = 'Scalar-Dashboard_3000.1' )])
298+
299+ def testNameIsNone (self ):
300+ with six .assertRaisesRegex (self , ValueError , r'no plugin_name' ):
301+ application .TensorBoardWSGI (
302+ plugins = [FakePlugin (plugin_name = None )])
324303
325304 def testEmptyName (self ):
326- self ._test ('' , False )
305+ with six .assertRaisesRegex (self , ValueError , r'invalid name' ):
306+ application .TensorBoardWSGI (
307+ plugins = [FakePlugin (plugin_name = '' )])
327308
328309 def testNameWithSlashes (self ):
329- self ._test ('scalars/data' , False )
310+ with six .assertRaisesRegex (self , ValueError , r'invalid name' ):
311+ application .TensorBoardWSGI (
312+ plugins = [FakePlugin (plugin_name = 'scalars/data' )])
330313
331314 def testNameWithSpaces (self ):
332- self ._test ('my favorite plugin' , False )
315+ with six .assertRaisesRegex (self , ValueError , r'invalid name' ):
316+ application .TensorBoardWSGI (
317+ plugins = [FakePlugin (plugin_name = 'my favorite plugin' )])
333318
334- def testSimpleName (self ):
335- self . _test ( 'scalars' , True )
336-
337- def testComprehensiveName ( self ):
338- self . _test ( 'Scalar-Dashboard_3000.1' , True )
319+ def testDuplicateName (self ):
320+ with six . assertRaisesRegex ( self , ValueError , r'Duplicate' ):
321+ application . TensorBoardWSGI (
322+ plugins = [ FakePlugin ( plugin_name = 'scalars' ),
323+ FakePlugin ( plugin_name = 'scalars' )] )
339324
340325
341326class ApplicationPluginRouteTest (tb_test .TestCase ):
342327
343- def _test (self , route , should_be_okay ):
344- temp_dir = tempfile .mkdtemp (prefix = self .get_temp_dir ())
345- self .addCleanup (shutil .rmtree , temp_dir )
346- multiplexer = event_multiplexer .EventMultiplexer (
347- size_guidance = application .DEFAULT_SIZE_GUIDANCE ,
348- purge_orphaned_data = True )
349- plugins = [
350- FakePlugin (
351- None ,
352- plugin_name = 'foo' ,
353- is_active_value = True ,
354- routes_mapping = {route : lambda environ , start_response : None }),
355- ]
356- if should_be_okay :
357- application .TensorBoardWSGIApp (
358- temp_dir , plugins , multiplexer , reload_interval = 0 , path_prefix = '' )
359- else :
360- with six .assertRaisesRegex (self , ValueError , r'invalid route' ):
361- application .TensorBoardWSGIApp (
362- temp_dir , plugins , multiplexer , reload_interval = 0 , path_prefix = '' )
328+ def _make_plugin (self , route ):
329+ return FakePlugin (
330+ plugin_name = 'foo' ,
331+ routes_mapping = {route : lambda environ , start_response : None })
363332
364333 def testNormalRoute (self ):
365- self ._test ('/runs' , True )
334+ application . TensorBoardWSGI ([ self ._make_plugin ('/runs' )] )
366335
367336 def testWildcardRoute (self ):
368- self ._test ('/foo/*' , True )
337+ application . TensorBoardWSGI ([ self ._make_plugin ('/foo/*' )] )
369338
370339 def testNonPathComponentWildcardRoute (self ):
371- self ._test ('/foo*' , False )
340+ with six .assertRaisesRegex (self , ValueError , r'invalid route' ):
341+ application .TensorBoardWSGI ([self ._make_plugin ('/foo*' )])
372342
373343 def testMultiWildcardRoute (self ):
374- self ._test ('/foo/*/bar/*' , False )
344+ with six .assertRaisesRegex (self , ValueError , r'invalid route' ):
345+ application .TensorBoardWSGI ([self ._make_plugin ('/foo/*/bar/*' )])
375346
376347 def testInternalWildcardRoute (self ):
377- self ._test ('/foo/*/bar' , False )
348+ with six .assertRaisesRegex (self , ValueError , r'invalid route' ):
349+ application .TensorBoardWSGI ([self ._make_plugin ('/foo/*/bar' )])
378350
379351 def testEmptyRoute (self ):
380- self ._test ('' , False )
352+ with six .assertRaisesRegex (self , ValueError , r'invalid route' ):
353+ application .TensorBoardWSGI ([self ._make_plugin ('' )])
381354
382355 def testSlashlessRoute (self ):
383- self ._test ('runaway' , False )
356+ with six .assertRaisesRegex (self , ValueError , r'invalid route' ):
357+ application .TensorBoardWSGI ([self ._make_plugin ('runaway' )])
384358
385359
386360class GetEventFileActiveFilterTest (tb_test .TestCase ):
@@ -426,9 +400,9 @@ def assertPlatformSpecificLogdirParsing(self, pathObj, logdir, expected):
426400 pathObj: a custom replacement object for `os.path`, typically
427401 `posixpath` or `ntpath`
428402 logdir: the string to be parsed by
429- :func:`~application.TensorBoardWSGIApp. parse_event_files_spec`
403+ :func:`~application.parse_event_files_spec`
430404 expected: the expected dictionary as returned by
431- :func:`~application.TensorBoardWSGIApp. parse_event_files_spec`
405+ :func:`~application.parse_event_files_spec`
432406
433407 """
434408
@@ -662,32 +636,6 @@ def testEmptyWildcardRouteWithSlash(self):
662636 self ._test_route ('/data/plugin/bar/wildcard/' , 404 )
663637
664638
665- class ApplicationConstructionTest (tb_test .TestCase ):
666-
667- def testExceptions (self ):
668- logdir = '/fake/foo'
669- multiplexer = event_multiplexer .EventMultiplexer ()
670-
671- # Fails if there is an unnamed plugin
672- with self .assertRaises (ValueError ):
673- # This plugin lacks a name.
674- plugins = [
675- FakePlugin (
676- None , plugin_name = None , is_active_value = True , routes_mapping = {}),
677- ]
678- application .TensorBoardWSGIApp (logdir , plugins , multiplexer , 0 , '' )
679-
680- # Fails if there are two plugins with same name
681- with self .assertRaises (ValueError ):
682- plugins = [
683- FakePlugin (
684- None , plugin_name = 'foo' , is_active_value = True , routes_mapping = {}),
685- FakePlugin (
686- None , plugin_name = 'foo' , is_active_value = True , routes_mapping = {}),
687- ]
688- application .TensorBoardWSGIApp (logdir , plugins , multiplexer , 0 , '' )
689-
690-
691639class DbTest (tb_test .TestCase ):
692640
693641 def testSqliteDb (self ):
0 commit comments