Beispiel #1
0
 def testHasData(self):
     '''
     check has data and populate functionality
     '''
     loc = Locator()
     if os.path.isfile(loc.db_file):
         os.remove(loc.db_file)
     # reinit sqlDB
     loc = Locator()
     self.assertFalse(loc.db_has_data())
     loc.populate_db()
     self.assertTrue(loc.db_has_data())
 def testHasData(self):
     '''
     check has data and populate functionality
     '''
     testDownload=False
     if self.inCI() or testDownload:
         with tempfile.TemporaryDirectory() as cacheRootDir:
             config=StorageConfig(cacheRootDir=cacheRootDir, cacheDirName='geograpy3')
             config.cacheFile = f"{config.getCachePath()}/{LocationContext.db_filename}"
             loc=Locator(storageConfig=config)
             if os.path.isfile(loc.db_file):
                 os.remove(loc.db_file)
             # reinit sqlDB
             loc=Locator(storageConfig=config)
             self.assertFalse(loc.db_has_data())
             loc.populate_db()
             self.assertTrue(loc.db_has_data())
Beispiel #3
0
 def testRegionMatching(self):
     '''
     test region matches
     '''
     locator = Locator()
     if not locator.db_has_data():
         locator.populate_db()
     countryList = CountryManager.fromErdem()
     config = LocationContext.getDefaultConfig()
     regionManager = RegionManager(config=config)
     regionManager.fromCache()
     for country in countryList.countries:
         locationListWithDistances = country.getNClosestLocations(
             regionManager, 3)
         if self.debug:
             print(f"{country}{country.lat:.2f},{country.lon:.2f}")
         for i, locationWithDistance in enumerate(
                 locationListWithDistances):
             location, distance = locationWithDistance
             if self.debug:
                 print(f"    {i}:{location}-{distance:.0f} km")
     pass