def testSqliteDb(self):
     db_uri = 'sqlite:' + os.path.join(self.get_temp_dir(), 'db')
     db_connection_provider = application.create_sqlite_connection_provider(
         db_uri)
     with contextlib.closing(db_connection_provider()) as conn:
         with conn:
             with contextlib.closing(conn.cursor()) as c:
                 c.execute('create table peeps (name text)')
                 c.execute('insert into peeps (name) values (?)',
                           ('justine', ))
     db_connection_provider = application.create_sqlite_connection_provider(
         db_uri)
     with contextlib.closing(db_connection_provider()) as conn:
         with contextlib.closing(conn.cursor()) as c:
             c.execute('select name from peeps')
             self.assertEqual(('justine', ), c.fetchone())
Beispiel #2
0
 def testTransactionRollback_doesntDoAnythingIfIsolationLevelIsNone(self):
     # NOTE: This is a terrible idea. Don't do this.
     db_uri = (
         "sqlite:"
         + os.path.join(self.get_temp_dir(), "db")
         + "?isolation_level=null"
     )
     db_connection_provider = application.create_sqlite_connection_provider(
         db_uri
     )
     with contextlib.closing(db_connection_provider()) as conn:
         with conn:
             with contextlib.closing(conn.cursor()) as c:
                 c.execute("create table peeps (name text)")
         try:
             with conn:
                 with contextlib.closing(conn.cursor()) as c:
                     c.execute(
                         "insert into peeps (name) values (?)", ("justine",)
                     )
                 raise IOError("hi")
         except IOError:
             pass
         with contextlib.closing(conn.cursor()) as c:
             c.execute("select name from peeps")
             self.assertEqual(("justine",), c.fetchone())
 def testSqliteDb(self):
     db_uri = "sqlite:" + os.path.join(self.get_temp_dir(), "db")
     db_connection_provider = application.create_sqlite_connection_provider(
         db_uri)
     with contextlib.closing(db_connection_provider()) as conn:
         with conn:
             with contextlib.closing(conn.cursor()) as c:
                 c.execute("create table peeps (name text)")
                 c.execute("insert into peeps (name) values (?)",
                           ("justine", ))
     db_connection_provider = application.create_sqlite_connection_provider(
         db_uri)
     with contextlib.closing(db_connection_provider()) as conn:
         with contextlib.closing(conn.cursor()) as c:
             c.execute("select name from peeps")
             self.assertEqual(("justine", ), c.fetchone())
 def set_up_db(self):
     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(
         db_connection_provider=db_connection_provider, db_uri=self.db_uri)
     self.core_plugin = core_plugin.CorePlugin(context)
     self.plugin = scalars_plugin.ScalarsPlugin(context)
Beispiel #5
0
 def create_multiplexer(self):
     db_path = os.path.join(self.get_temp_dir(), "db.db")
     db_uri = "sqlite:%s" % db_path
     db_connection_provider = application.create_sqlite_connection_provider(
         db_uri)
     return db_import_multiplexer.DbImportMultiplexer(
         db_uri=db_uri,
         db_connection_provider=db_connection_provider,
         purge_orphaned_data=True,
         max_reload_threads=1,
     )
 def _start_db_based_server(self):
   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,
       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)
Beispiel #7
0
 def testSqliteUriErrors(self):
   with self.assertRaises(ValueError):
     application.create_sqlite_connection_provider("lol:cat")
   with self.assertRaises(ValueError):
     application.create_sqlite_connection_provider("sqlite::memory:")
   with self.assertRaises(ValueError):
     application.create_sqlite_connection_provider("sqlite://foo.example/bar")
Beispiel #8
0
 def testSqliteUriErrors(self):
   with self.assertRaises(ValueError):
     application.create_sqlite_connection_provider("lol:cat")
   with self.assertRaises(ValueError):
     application.create_sqlite_connection_provider("sqlite::memory:")
   with self.assertRaises(ValueError):
     application.create_sqlite_connection_provider("sqlite://foo.example/bar")
Beispiel #9
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)
 def testTransactionRollback(self):
     db_uri = 'sqlite:' + os.path.join(self.get_temp_dir(), 'db')
     db_connection_provider = application.create_sqlite_connection_provider(
         db_uri)
     with contextlib.closing(db_connection_provider()) as conn:
         with conn:
             with contextlib.closing(conn.cursor()) as c:
                 c.execute('create table peeps (name text)')
         try:
             with conn:
                 with contextlib.closing(conn.cursor()) as c:
                     c.execute('insert into peeps (name) values (?)',
                               ('justine', ))
                 raise IOError('hi')
         except IOError:
             pass
         with contextlib.closing(conn.cursor()) as c:
             c.execute('select name from peeps')
             self.assertIsNone(c.fetchone())
Beispiel #11
0
 def testTransactionRollback(self):
     db_uri = "sqlite:" + os.path.join(self.get_temp_dir(), "db")
     db_connection_provider = application.create_sqlite_connection_provider(
         db_uri)
     with contextlib.closing(db_connection_provider()) as conn:
         with conn:
             with contextlib.closing(conn.cursor()) as c:
                 c.execute("create table peeps (name text)")
         try:
             with conn:
                 with contextlib.closing(conn.cursor()) as c:
                     c.execute("insert into peeps (name) values (?)",
                               ("justine", ))
                 raise IOError("hi")
         except IOError:
             pass
         with contextlib.closing(conn.cursor()) as c:
             c.execute("select name from peeps")
             self.assertIsNone(c.fetchone())
 def testTransactionRollback_doesntDoAnythingIfIsolationLevelIsNone(self):
     # NOTE: This is a terrible idea. Don't do this.
     db_uri = ('sqlite:' + os.path.join(self.get_temp_dir(), 'db') +
               '?isolation_level=null')
     db_connection_provider = application.create_sqlite_connection_provider(
         db_uri)
     with contextlib.closing(db_connection_provider()) as conn:
         with conn:
             with contextlib.closing(conn.cursor()) as c:
                 c.execute('create table peeps (name text)')
         try:
             with conn:
                 with contextlib.closing(conn.cursor()) as c:
                     c.execute('insert into peeps (name) values (?)',
                               ('justine', ))
                 raise IOError('hi')
         except IOError:
             pass
         with contextlib.closing(conn.cursor()) as c:
             c.execute('select name from peeps')
             self.assertEqual(('justine', ), c.fetchone())