def test_3_disconnect(self): dbfile = DB(self.file, mode='w').connect() dbfile.disconnect() self.assertFalse(dbfile._conx, 'SQL database file not disconnected') self.assertFalse(dbfile._c, 'SQL database file not disconnected') # Trying to disconnect again with self.assertRaises(ex.ConnectionError): dbfile.disconnect()
def setUpClass(cls): cls.dbfile = DB(FILE, mode='w').open() value = np.array([(1, 1.1, 'a'), (2, 2.2, 'b'), (3, 3.3, 'c'), (4, 4.4, 'd')], dtype=[('col1', int), ('col2', float), ('col3', str)]) cls.dbfile['A'] = value cls.x = [value, cls.dbfile['A']] cls.dbfile.commit()
def setUpClass(cls): cls.dbfile = DB(FILE, mode='w').open() value = np.array([[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10], [11, 12]], [[13, 14], [15, 16], [17, 18]], [[19, 20], [21, 22], [23, 24]]]) cls.dbfile['A'] = value cls.x = [value, cls.dbfile['A']] cls.dbfile.commit()
def test_2_connect(self): # connect is called within __init__ dbfile = DB(self.file, mode='w').connect() # Trying to connect when it's already connected with self.assertRaises(ex.ConnectionError): dbfile.connect() # Connection objects are set self.assertTrue(dbfile._conx, 'SQL database file not connected') self.assertTrue(dbfile._c, 'SQL database file not connected')
def setUpClass(cls): cls.dbfile = DB(FILE, mode='w').open() value = { 'a': { 'a1': 0, 'a2': 1, 'a3': 2 }, 'b': { 'b1': 4, 'b2': 5 }, 'c': 6 } cls.dbfile['A'] = value cls.x = [value, cls.dbfile['A']]
def setUpClass(cls): cls.dbfile = DB(FILE, mode='w').open()
def setUpClass(cls): cls.dbfile = DB(FILE, mode='w').open() value = {'a': 0, 'b': 1, 'c': 2} cls.dbfile['A'] = value cls.x = [value, cls.dbfile['A']]
def setUpClass(cls): cls.dbfile = DB(FILE, mode='w').open() for k, v in cls.value.items(): cls.dbfile[k] = v
def test_false(self): dbfile = DB(FILE, mode='w').connect() self.assertFalse(dbfile.exists())
def test_true(self): dbfile = DB(FILE, mode='w').open() self.assertTrue(dbfile.exists()) dbfile2 = DB(FILE, mode='+').connect() self.assertTrue(dbfile2.exists())
def setUpClass(cls): cls.dbfile = DB(FILE, mode='w').open() value = np.array([10, 11, 12]) cls.dbfile['A'] = value cls.x = [value, cls.dbfile['A']]
def setUpClass(cls): cls.dbfile = DB(FILE, mode='w').open() value = [[10, 11, 12], [13, 14], 15] cls.dbfile['A'] = value cls.x = [value, cls.dbfile['A']]
def test_6_init_mode_x(self): open(self.file, 'a').close() with self.assertRaises(FileExistsError): DB(self.file, mode='x')
def test_5_init_mode_r(self): with self.assertRaises(FileNotFoundError): DB(self.file, mode='r')
def test_4_init_mode_w(self): open(self.file, 'a').close() DB(self.file, mode='w') self.assertFalse(os.path.exists(self.file))
def test_1_open(self): DB(self.file, mode='w').open()