Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
 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]
Ejemplo n.º 3
0
 def test6_download_main(self, mock_dl):
     download_main('hydrobasins_all_levels', 'eu', False)
     mock_dl.assert_called_once_with('eu')
Ejemplo n.º 4
0
 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]
Ejemplo n.º 5
0
 def test4_download_main(self, mock_dl):
     download_main('hydrosheds_dem_30s', 'as', False)
     mock_dl.assert_called_once_with('as')
Ejemplo n.º 6
0
 def test3_download_main_bad_region(self):
     with self.assertRaises(BasmatiError):
         download_main('hydrobasins_all_levels', 'moon', False)
Ejemplo n.º 7
0
 def test2_download_main_bad_dataset(self):
     with self.assertRaises(BasmatiError):
         download_main('hydrobasins_', 'as', False)
Ejemplo n.º 8
0
 def test1_download_main_no_HYDROSHEDS_DIR_env(self):
     with self.assertRaises(BasmatiError):
         download_main('hydrobasins_all_levels', 'as', False)