示例#1
0
    def test_b01setandget_timeref(self):
        dbt: DBTools = None
        dbname = 'python1test'

        try:

            dbt = DBTools(dbid=dbname)
            dbt.open()
            aa: Tuple[int, float, Dtc, str] = dbt.set_timeref(cmt='testing')
            bb = dbt.get_timeref()
            self.assertEqual(aa, bb)
            idx: int = aa[0]  # 1
            self.assertEqual(1, idx)
            timestamp: float = aa[1]
            time: Dtc = aa[2]
            utc1: Dtc = Dtc.fromtimestamp(timestamp, timezone.utc)
            local: Dtc = utc1.astimezone()
            self.assertEqual(time, local)

            cmta: str = aa[3]  # 'testing'
            self.assertEqual('testing', cmta)

        except:
            self.fail('unexpected exception')
        finally:
            dbt.close_and_disconnect()
示例#2
0
 def setUpClass(cls):
     dbt: DBTools = None
     dbname = 'python1test'
     try:
         dbt = DBTools(dbid=dbname)
         dbt.open()
         dbt.resetdb()
     except Exception as ex:
         print('unexpected exception')
         a = 0
     finally:
         dbt.close_and_disconnect()
     pass
示例#3
0
    def test_a00instat(self):
        dbname = 'python1test'
        dm = DBTools(dbid=dbname)
        self.assertEqual(
            f'Schema is {dbname}, opened = False, connected = True', str(dm))
        self.assertEqual(
            f'DBTools: Schema is {dbname}, opened = False, connected = True',
            repr(dm))
        dm.close_and_disconnect()
        self.assertEqual(
            f'DBTools: Schema is {dbname}, opened = False, connected = False',
            repr(dm))
        dm.close_and_disconnect()
        dm.close_and_disconnect()

        dm = DBTools(dbid=dbname)
        try:
            self.assertTrue(dm.open())
            dm.close_and_disconnect()

        except:
            self.fail('unexpected exception')
            a = 0
        finally:
            try:
                dm.close_and_disconnect()
            except:
                self.fail('unexpected exception')
示例#4
0
    def test_a01open(self):
        dbname = 'python1test'
        dm = DBTools(dbid=dbname)

        dm.open()
        self.assertEqual(
            f'Schema is {dbname}, opened = True, connected = True', str(dm))
        self.assertEqual(
            f'DBTools: Schema is {dbname}, opened = True, connected = True',
            repr(dm))
        try:
            dm.open()
            self.fail('did not cause exception on second open')
        except Exception as ex:
            self.assertEqual('database already opened', str(ex))
            a = 0
        dm.close_and_disconnect()
        self.assertEqual(
            f'Schema is {dbname}, opened = False, connected = False', str(dm))
        self.assertEqual(
            f'DBTools: Schema is {dbname}, opened = False, connected = False',
            repr(dm))
        try:
            dm.close_and_disconnect()
        except:
            self.fail(
                'should not have caused an exception on 2nd close_and_disconnect'
            )

        dm.open()
        self.assertEqual(
            f'Schema is {dbname}, opened = False, connected = False', str(dm))