本文整理汇总了Python中DatabaseHandler.DatabaseHandler类的典型用法代码示例。如果您正苦于以下问题:Python DatabaseHandler类的具体用法?Python DatabaseHandler怎么用?Python DatabaseHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DatabaseHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_address_without_route_returns_address_when_routes_empty
def test_get_address_without_route_returns_address_when_routes_empty(self):
handler = DatabaseHandler('unit_test_db.sqlite3')
handler.add_address(location=MapLocation(latitude=5, longitude=6, id=1))
address_generator = handler.get_address_generator()
self.assertEqual(MapLocation(latitude=5, longitude=6, id=1),
address_generator.next(),
"Only MapLocation in addresses was not returned")
示例2: test_get_address_without_route_returns_with_correct_id
def test_get_address_without_route_returns_with_correct_id(self):
handler = DatabaseHandler('unit_test_db.sqlite3')
handler.add_address(MapLocation(latitude=2, longitude=2, id=222))
address_generator = handler.get_address_generator()
self.assertEqual(MapLocation(latitude=2, longitude=2, id=222),
address_generator.next(),
"MapLocation should return correct id")
示例3: test_add_routes_table_adds_table
def test_add_routes_table_adds_table(self,
mock_init_db):
handler = DatabaseHandler('unit_test_db.sqlite3')
handler._add_routes_table()
c = handler.conn.cursor()
c.execute("SELECT NAME FROM sqlite_master WHERE "
"TYPE='table' AND NAME='routes'")
self.assertTrue(c.fetchone(), "routes table not created")
示例4: test_add_address_adds_to_address_table
def test_add_address_adds_to_address_table(self,
mock_init_db):
handler = DatabaseHandler('unit_test_db.sqlite3')
handler._add_addresses_table()
handler.add_address(location=MapLocation(latitude=0.56, longitude=9.5))
c = handler.conn.cursor()
c.execute("SELECT latitude, longitude FROM addresses")
row = c.fetchone()
self.assertEqual((0.56, 9.5), row)
示例5: test_add_stop_uses_MapLocation_id_if_nonzero
def test_add_stop_uses_MapLocation_id_if_nonzero(self,
mock_init_db):
handler = DatabaseHandler('unit_test_db.sqlite3')
handler._add_stops_table()
stop_location = MapLocation(latitude=0.48, longitude=179, id=888)
handler.add_stop(stop_location)
c = handler.conn.cursor()
c.execute("SELECT * FROM stops")
self.assertEqual(888, c.fetchone()[0])
示例6: test_add_address_uses_MapLocation_id_if_nonzero
def test_add_address_uses_MapLocation_id_if_nonzero(self,
mock_init_db):
handler = DatabaseHandler('unit_test_db.sqlite3')
handler._add_addresses_table()
address_location = MapLocation(latitude=0.33, longitude=4, id=100)
handler.add_address(address_location)
c = handler.conn.cursor()
c.execute("SELECT * FROM addresses")
self.assertEqual(100, c.fetchone()[0])
示例7: test_construct_db_calls_add_stop_table
def test_construct_db_calls_add_stop_table(self):
handler = DatabaseHandler('unit_test_db.sqlite3')
mock_add_addresses = Mock()
handler._add_addresses_table = mock_add_addresses
mock_add_stops = Mock()
handler._add_stops_table = mock_add_stops
handler.initialize_db()
self.assertTrue(mock_add_stops.called,
"initialize_db did not call _add_stops_table")
示例8: initDb
def initDb(pathDb):
db = DatabaseHandler(u'qt_sql_default_connection', pathDb)
queries = [
('CREATE TABLE folders (name TEXT PRIMARY KEY, os TEXT, computerName TEXT)', None),
('CREATE TABLE files (hash TEXT, absPath TEXT, name TEXT, path TEXT, size NUM, searchTag NUM)', None),
('CREATE TABLE tags (searchTag NUM UNIQUE, timestamp NUM, computerName TEXT)', None),
('CREATE TABLE lastSearch (searchTag UNIQUE, lastPercent NUM, lastPath TEXT)', None)
]
db.processQueries(queries)
return
示例9: test_add_stop_adds_to_stops_table
def test_add_stop_adds_to_stops_table(self,
mock_init_db):
handler = DatabaseHandler('unit_test_db.sqlite3')
handler._add_stops_table()
map_location = MapLocation(latitude=-0.55, longitude=80)
handler.add_stop(location=map_location)
c = handler.conn.cursor()
c.execute("SELECT latitude, longitude FROM stops")
row = c.fetchone()
self.assertEqual((-.55, 80), row)
示例10: test_handler_add_stops_from_file_inserts_one_record
def test_handler_add_stops_from_file_inserts_one_record(self,
mock_init_db):
handler = DatabaseHandler('unit_test_db.sqlite3')
with open('test_file.csv', 'w') as f:
f.write('latitude,longitude\n')
f.write('15.35,-1.5\n')
handler.add_stops_from_file('test_file.csv')
c = handler.conn.cursor()
c.execute("SELECT latitude, longitude FROM stops")
row = c.fetchone()
self.assertEqual((15.35, -1.5), row)
示例11: test_get_address_without_route_generator_new_address_second_time
def test_get_address_without_route_generator_new_address_second_time(self):
handler = DatabaseHandler('unit_test_db.sqlite3')
handler.add_address(location=MapLocation(latitude=1, longitude=1))
handler.add_address(location=MapLocation(latitude=2, longitude=2))
address_generator = handler.get_address_generator()
self.assertEqual(MapLocation(latitude=1, longitude=1, id=1),
address_generator.next(),
"first returned MapLocation was not correct")
self.assertEqual(MapLocation(latitude=2, longitude=2, id=2),
address_generator.next(),
"second returned MapLocation was not correct")
示例12: test_output_routes_calls_correct_function_when_closest_stop_true
def test_output_routes_calls_correct_function_when_closest_stop_true(self):
handler = DatabaseHandler(full=False)
handler.routes_dataframe = Mock()
handler.routes_dataframe_closest_stops = Mock()
handler.output_routes(file_path="test_file.csv",
closest_stops_only=True)
handler.routes_dataframe_closest_stops.assert_called_once_with()
self.assertEqual(0, handler.routes_dataframe.call_count,
"routes_dataframe should not be called")
示例13: test_get_all_stops_returns_list_of_MapLocations
def test_get_all_stops_returns_list_of_MapLocations(self,
mock_init_db):
handler = DatabaseHandler('unit_test_db.sqlite3')
handler._add_stops_table()
handler.add_stop(MapLocation(latitude=5, longitude=6))
handler.add_stop(MapLocation(latitude=3, longitude=-5))
stops = handler.get_all_stops()
self.assertEqual((5, 6), (stops[0].latitude, stops[0].longitude))
self.assertEqual((3, -5), (stops[1].latitude, stops[1].longitude))
示例14: test_add_route_adds_route
def test_add_route_adds_route(self):
handler = DatabaseHandler('unit_test_db.sqlite3')
handler.add_address(location=MapLocation(latitude=5, longitude=5))
handler.add_stop(location=MapLocation(latitude=2, longitude=2))
handler.add_route(address=1, stop=1, distance=10, time=20)
c = handler.conn.cursor()
c.execute("SELECT * FROM routes")
self.assertEqual((1, 1, 1, 10, 20), c.fetchone())
示例15: test_routes_dataframe_has_correct_values
def test_routes_dataframe_has_correct_values(self):
handler = DatabaseHandler('unit_test_db.sqlite3')
handler.initialize_db()
handler.add_address(MapLocation(latitude=11, longitude=50, id=11))
handler.add_stop(MapLocation(latitude=-10, longitude=3, id=800))
handler.add_route(address=11, stop=800, distance=10000, time=50000)
df = handler.routes_dataframe()
self.assertEqual(1, df.shape[0], "only one row should be output")
self.assertEqual(11, df.ix[0, 'address_latitude'],
'incorrect address latitude output')
self.assertEqual(50, df.ix[0, 'address_longitude'],
'incorrect address longitude output')
self.assertEqual(-10, df.ix[0, 'stop_latitude'],
'incorrect stop latitude output')
self.assertEqual(3, df.ix[0, 'stop_longitude'],
'incorrect stop longitude output')
self.assertEqual(10000, df.ix[0, 'distance'],
'incorrect distance output')
self.assertEqual(50000, df.ix[0, 'time'],
'incorrect time output')