def basmati_cmd(argv: List[str] = sys.argv) -> None: args = _parse_args(argv) loglevel = 'DEBUG' if args.debug else 'INFO' if sys.platform.startswith('win'): args.bw = True logger = setup_logger(loglevel, not args.bw, args.warn) logger.debug(argv) logger.debug(args) try: # Dispatch command. # N.B. args should always be dereferenced at this point, # not passed into any subsequent functions. if args.subcmd_name == 'demo': demo_main() elif args.subcmd_name in ['download', 'dl']: download_main(args.dataset, args.region, args.delete_zip) elif args.subcmd_name == 'version': print(get_version(form='long' if args.long else 'short')) except BasmatiError as be: logger.error(be) raise except Exception as e: logger.error(e) raise
def test7_download_main(self, mock_dl): download_main('hydrobasins_all_levels', 'ALL', False) mock_dl.mock_calls = [call(r) for r in HYDROBASINS_REGIONS]
def test6_download_main(self, mock_dl): download_main('hydrobasins_all_levels', 'eu', False) mock_dl.assert_called_once_with('eu')
def test5_download_main(self, mock_dl): download_main('hydrosheds_dem_30s', 'ALL', False) mock_dl.mock_calls = [call(r) for r in HYDROBASINS_REGIONS]
def test4_download_main(self, mock_dl): download_main('hydrosheds_dem_30s', 'as', False) mock_dl.assert_called_once_with('as')
def test3_download_main_bad_region(self): with self.assertRaises(BasmatiError): download_main('hydrobasins_all_levels', 'moon', False)
def test2_download_main_bad_dataset(self): with self.assertRaises(BasmatiError): download_main('hydrobasins_', 'as', False)
def test1_download_main_no_HYDROSHEDS_DIR_env(self): with self.assertRaises(BasmatiError): download_main('hydrobasins_all_levels', 'as', False)