Exemplo n.º 1
0
    def setupInputsFromArgs(args_):
        """
        Takes in Covid19Args and returns a list of tuples.
        Tuple contains -
          1. Input Type
          2. File name with path.
        Note if args_ has 'download' set to True, no explicitly specified input files will be considered.
        :param args_: Covid19Args
        :return: List of tuples containing input type and file name.
        """
        assert isinstance(args_, Covid19Args)
        inputList = []
        if args_.download:
            # TODO downloadFilenamesWithPath is a static call.
            downloadFilenamesWithPath = Covid19Args.downloadFilenamesWithPath()
            for fileType in downloadFilenamesWithPath.keys():
                assert isinstance(fileType, InputFileFactory)
                inputfile = Covid19InputDownloader.downloadFile(
                    fileType.downloadURL(),
                    downloadFilenamesWithPath[fileType])
                # Create tuple as InputFileType, filename.
                inputList.append((fileType, inputfile))
        else:
            # US Input file.
            if args_.inputfile is not None:
                inputList.append(
                    (InputFileFactory.CONFIRMED_US, args_.inputfile)),

            if args_.globalInputfile is not None:
                inputList.append(
                    (InputFileFactory.CONFIRMED_GLOBAL, args_.globalInputfile))

        return inputList
Exemplo n.º 2
0
 def test_downloadFilename(self):
     timeSuffix = 2014
     today = datetime.today().strftime('%Y%m%d')
     downloadFilenamesWithPath = Covid19Args.downloadFilenamesWithPath(
         timeSuffix)
     self.assertEqual(len(InputFileFactory),
                      len(downloadFilenamesWithPath.keys()))
     for fileType in InputFileFactory:
         checkFilename = '{0}/{1}_{2}{3}.csv'.format(
             Covid19Constants.DOWNLOAD_FOLDER,
             fileType.downloadFilePrefix(), today, timeSuffix)
         self.assertEqual(checkFilename,
                          downloadFilenamesWithPath[fileType])
Exemplo n.º 3
0
        def testForDownload():
            args = Covid19Args()
            args.setup()
            argList = [
                '--input', 'aaa', '--download', '--location',
                'bbb/ccc/ddd, eee/fff/ggg', '--templateOutput', 'hhh',
                '--output', 'jjj'
            ]

            args.parse(argList)
            self.assertTrue(args.download)
            tupList = Covid19ControllerUtils.setupInputsFromArgs(args)
            filesFromArgs = Covid19Args.downloadFilenamesWithPath()
            self.assertEqual(len(filesFromArgs.keys()), len(tupList))
            for tup in tupList:
                fileType = tup[0]
                self.assertIn(fileType, filesFromArgs.keys())
                self.assertEqual(filesFromArgs[fileType], tup[1])
            fileTypeSet = set(filesFromArgs.keys())
            typeListFromTupeList = []
            for item in tupList:
                typeListFromTupeList.append(item[0])
            self.assertEqual(fileTypeSet, set(typeListFromTupeList))