def testListOfCities(self): ''' test sqlite3 with some 120000 city records ''' listOfRecords=Sample.getCities() for fixDates in [True,False]: retrievedList=self.checkListOfRecords(listOfRecords,'City',fixDates=fixDates) self.assertEqual(len(listOfRecords),len(retrievedList))
def testCities(self): ''' test a list of cities ''' cityList=Sample.getCities() self.assertEqual(128769,(len(cityList))) cityIter=iter(cityList) #limit=len(cityList) limit=1000 if getpass.getuser()=="travis": limit=4000 for i in range(limit): city=next(cityIter) city['dgraph.type']='City' lat=float(city['lat']) lng=float(city['lng']) city['location']={'type': 'Point', 'coordinates': [lng,lat] } #print("%d: %s" % (i,city)) dgraph=self.getDGraph() dgraph.drop_all() schema=''' name: string @index(exact) . country: string . lat: float . lng: float . location: geo . type City { name lat lng location country }''' dgraph.addSchema(schema) startTime=time.time() dgraph.addData(obj=cityList,limit=limit,batchSize=250) query='''{ # get cities cities(func: has(name)) { country name lat lng location } } ''' elapsed=time.time()-startTime print ("dgraph:adding %d records took %5.3f s => %5.f records/s" % (limit,elapsed,limit/elapsed)) startTime=time.time() queryResult=dgraph.query(query) elapsed=time.time()-startTime print ("dgraph:query of %d records took %5.3f s => %5.f records/s" % (limit,elapsed,limit/elapsed)) self.assertTrue('cities' in queryResult) qCityList=queryResult['cities'] self.assertEqual(limit,len(qCityList)) dgraph.close()
def testBackup(self): ''' test creating a backup of the SQL database ''' if sys.version_info >= (3, 7): listOfRecords=Sample.getCities() self.checkListOfRecords(listOfRecords,'City',fixDates=True,doClose=False) backupDB="/tmp/testSqlite.db" showProgress=200 if self.debug else 0 self.sqlDB.backup(backupDB,profile=self.debug,showProgress=showProgress) size=os.stat(backupDB).st_size if self.debug: print ("size of backup DB is %d" % size) self.assertTrue(size>600000) self.sqlDB.close() # restore ramDB=SQLDB.restore(backupDB, SQLDB.RAM, profile=self.debug,showProgress=showProgress) entityInfo=EntityInfo(listOfRecords[:50],'City',debug=self.debug) allCities=ramDB.queryAll(entityInfo) self.assertEqual(len(allCities),len(listOfRecords))
def testIssue24_IntegrateTabulate(self): ''' https://github.com/WolfgangFahl/pyLoDStorage/issues/24 test https://pypi.org/project/tabulate/ support ''' show=self.debug #show=True royals=Royals(load=True) for fmt in ["latex","grid","mediawiki","github"]: table=tabulate(royals.royals,headers="keys",tablefmt=fmt) if show: print (table) cities=Sample.getCities() counter=Counter() for city in cities: counter[city["country"]]+=1; tabulateCounter=TabulateCounter(counter) for fmt in ["latex","grid","mediawiki","github"]: table=tabulateCounter.mostCommonTable(tablefmt=fmt,limit=7) if show: print(table) pass