Ejemplo n.º 1
0
 def covid19Transformer(self):
     if self == InputFileFactory.CONFIRMED_US:
         return Covid19USTransformer()
     elif self == InputFileFactory.CONFIRMED_GLOBAL:
         return Covid19GlobalTransformer()
     else:
         return None
Ejemplo n.º 2
0
    def test_process_line(self):
        t1 = Covid19USTransformer()

        self.assertEqual(0, len(t1._colsToRead))
        self.assertEqual(0, len(t1._dateList))
        self.assertEqual(0, len(t1._objColl))
        t1.processLine(self._header.split(','), True)
        self.assertEqual(72, len(t1._colsToRead))
        self.assertEqual(69, len(t1._dateList))
        self.assertEqual(0, len(t1._objColl))

        for line in self._inputListFromFile:
            lineAsList = TestCovid19USTransformer._createListFromCSVLine(line)
            t1.processLine(lineAsList, False)
        self.assertEqual(72, len(t1._colsToRead))
        self.assertEqual(69, len(t1._dateList))
        self.assertEqual(len(self._inputListFromFile), len(t1._objColl))

        i = 0
        for obj in t1.getCollection():
            self.assertEqual(str(self._verificationObjects[i]), str(obj))
            # print('{0}: {1}'.format(i, str(obj)))
            i = i + 1
        self.assertEqual(72, len(t1._colsToRead))
        self.assertEqual(69, len(t1._dateList))
        self.assertEqual(len(self._inputListFromFile), len(t1._objColl))
Ejemplo n.º 3
0
 def test3():
     t1 = Covid19USTransformer()
     self.assertEqual(0, len(t1._colsToRead))
     t1.processHeader(['abc'])
     self.assertEqual(0, len(t1._colsToRead))
     t1.processHeader(['iso3'])
     self.assertEqual(1, len(t1._colsToRead))
     t1.processHeader(['iso3', 'Province_State'])
     self.assertEqual(2, len(t1._colsToRead))
     t1.processHeader(['iso3', 'Province_State', 'abracadabra'])
     self.assertEqual(2, len(t1._colsToRead))
     self.assertEqual(0, len(t1._dateList))
Ejemplo n.º 4
0
    def test_add_to_collection(self):
        t1 = Covid19USTransformer()
        self.assertEqual(0, len(t1._objColl))
        t1.processHeader(self._header.split(','))
        colList = t1.listOfIndexesOfColumnsToRead()

        for line in self._inputListFromFile:
            lineAsList = TestCovid19USTransformer._createListFromCSVLine(line)
            rawDataList = []
            for col in colList:
                rawDataList.append(lineAsList[col])
            t1.addToCollection(t1.createObject(tuple(rawDataList)))
        self.assertEqual(len(self._inputListFromFile), len(t1._objColl))

        i = 0
        for obj in t1._objColl:
            self.assertEqual(str(self._verificationObjects[i]), str(obj))
            i = i + 1
Ejemplo n.º 5
0
    def test_create_object(self):
        t1 = Covid19USTransformer()
        headerAsTuple = tuple(self._header.split(','))
        firstDatePos = headerAsTuple.index('Combined_Key') + 1
        numDateCols = len(headerAsTuple) - firstDatePos
        t1.processHeader(self._header.split(','))
        colList = t1.listOfIndexesOfColumnsToRead()
        self.assertEqual(numDateCols + 3, len(colList))

        for i in range(0, len(self._inputListFromFile)):
            line = self._inputListFromFile[i]
            lineAsList = TestCovid19USTransformer._createListFromCSVLine(line)
            # print("xx = ", str(lineAsList))
            rawDataList = []
            for col in colList:
                rawDataList.append(lineAsList[col])

            # print(str(tuple(rawDataList)))
            o1 = t1.createObject(tuple(rawDataList))
            self.assertIsNotNone(o1)
            self.assertEqual(str(self._verificationObjects[i]), str(o1))

            i = i + 1
Ejemplo n.º 6
0
 def test4():
     t1 = Covid19USTransformer()
     self.assertEqual(0, len(t1._colsToRead))
     # '"UID,iso2,iso3,code3,FIPS,Admin2,Province_State,Country_Region,Lat,Long_,Combined_Key,1/22/2020...'
     # Before 'Combined_Key'.  'Combined_Key' is index #10.
     t1.processHeader(self._header.split(',')[:10])
     self.assertEqual(3, len(t1._colsToRead))
     self.assertEqual(0, len(t1._dateList))
     # Include 'Combined_Key'.  'Combined_Key' is index #10.
     t1.processHeader(self._header.split(',')[:11])
     self.assertEqual(3, len(t1._colsToRead))
     self.assertEqual(0, len(t1._dateList))
     # # Include date after 'Combined_Key'.
     t1.processHeader(self._header.split(',')[:12])
     self.assertEqual(4, len(t1._colsToRead))
     self.assertEqual(1, len(t1._dateList))
     t1.processHeader(self._header.split(',')[:13])
     self.assertEqual(5, len(t1._colsToRead))
     self.assertEqual(2, len(t1._dateList))
     # All date columns.
     t1.processHeader(self._header.split(','))
     self.assertEqual(72, len(t1._colsToRead))
     self.assertEqual(69, len(t1._dateList))
Ejemplo n.º 7
0
    def test_columns_to_read(self):
        t1 = Covid19USTransformer()
        colAsTuple = tuple(self._header.split(','))
        t1.processHeader(colAsTuple)
        self.assertEqual(0, len(t1._objColl))

        headerAsTuple = tuple(self._header.split(','))
        firstDatePos = headerAsTuple.index('Combined_Key') + 1
        self.assertTrue(firstDatePos > 1)
        numDateCols = len(headerAsTuple) - firstDatePos
        self.assertTrue(numDateCols > 0)

        l1 = t1.listOfIndexesOfColumnsToRead()
        self.assertEqual(numDateCols + 3, len(l1))
        self.assertEqual(0, len(t1._objColl))
        self.assertEqual(numDateCols, len(t1._dateList))

        l1AsTuple = tuple(l1)

        countryCol = headerAsTuple.index('iso3')
        self.assertTrue(countryCol >= 0)
        self.assertTrue(l1AsTuple.index(countryCol) >= 0)

        stateCol = headerAsTuple.index('Province_State')
        self.assertTrue(stateCol >= 0)
        self.assertTrue(l1AsTuple.index(stateCol) >= 0)

        countyCol = headerAsTuple.index('Admin2')
        self.assertTrue(countyCol >= 0)
        self.assertTrue(l1AsTuple.index(countyCol) >= 0)

        # Check all date column header numbers are included.
        for i in range(firstDatePos, len(headerAsTuple)):
            self.assertTrue(l1AsTuple.index(i) >= 0)

        self.assertEqual(tuple(self._dateList), tuple(t1._dateList))
Ejemplo n.º 8
0
 def test2():
     t1 = Covid19USTransformer()
     self.assertEqual(0, len(t1._colsToRead))
     t1.processHeader([])
     self.assertEqual(0, len(t1._colsToRead))
     self.assertEqual(0, len(t1._dateList))