Пример #1
0
 def covid19Transformer(self):
     if self == InputFileFactory.CONFIRMED_US:
         return Covid19USTransformer()
     elif self == InputFileFactory.CONFIRMED_GLOBAL:
         return Covid19GlobalTransformer()
     else:
         return None
    def test_process_line(self):
        t1 = Covid19GlobalTransformer()

        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(80, len(t1._colsToRead))
        self.assertEqual(78, len(t1._dateList))
        self.assertEqual(0, len(t1._objColl))

        for line in self._inputListFromFile:
            lineAsList = TestCovid19GlobalTransformer._createListFromCSVLine(line)
            t1.processLine(lineAsList, False)
        self.assertEqual(80, len(t1._colsToRead))
        self.assertEqual(78, 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(80, len(t1._colsToRead))
        self.assertEqual(78, len(t1._dateList))
        self.assertEqual(len(self._inputListFromFile), len(t1._objColl))
    def test_columns_to_read(self):
        t1 = Covid19GlobalTransformer()
        colAsTuple = tuple(self._header.split(','))
        t1.processHeader(colAsTuple)
        self.assertEqual(0, len(t1._objColl))

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

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

        l1AsTuple = tuple(l1)

        countryCol = headerAsTuple.index('Country/Region')
        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)

        # 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))
 def test3():
     t1 = Covid19GlobalTransformer()
     self.assertEqual(0, len(t1._colsToRead))
     t1.processHeader(['abc'])
     self.assertEqual(0, len(t1._colsToRead))
     t1.processHeader(['Country/Region'])
     self.assertEqual(1, len(t1._colsToRead))
     t1.processHeader(['Country/Region', 'Province/State'])
     self.assertEqual(2, len(t1._colsToRead))
     t1.processHeader(['iso3', 'Country/Region', 'Province/State'])
     self.assertEqual(2, len(t1._colsToRead))
     self.assertEqual(0, len(t1._dateList))
    def test_get_collection(self):
        t1 = Covid19GlobalTransformer()
        self.assertEqual(0, len(t1._objColl))
        t1.processHeader(self._header.split(','))
        colList = t1.listOfIndexesOfColumnsToRead()

        for line in self._inputListFromFile:
            lineAsList = TestCovid19GlobalTransformer._createListFromCSVLine(line)
            rawDataList = []
            for col in colList:
                rawDataList.append(lineAsList[col])
            t1.addToCollection(t1.createObject(tuple(rawDataList)))

        self.assertEqual(len(self._verificationObjects), len(t1.getCollection()))
        i = 0
        for obj in t1.getCollection():
            self.assertEqual(str(self._verificationObjects[i]), str(obj))
            i = i + 1
 def test4():
     t1 = Covid19GlobalTransformer()
     self.assertEqual(0, len(t1._colsToRead))
     # 'Province/State,Country/Region,Lat,Long,1/22/20,...'
     # 'Long' is index #3.
     t1.processHeader(self._header.split(',')[:3])
     self.assertEqual(2, len(t1._colsToRead))
     self.assertEqual(0, len(t1._dateList))
     # Include 'Long'.  'Long' is index #3.
     t1.processHeader(self._header.split(',')[:4])
     self.assertEqual(2, len(t1._colsToRead))
     self.assertEqual(0, len(t1._dateList))
     # # Include date after 'Long'.
     t1.processHeader(self._header.split(',')[:5])
     self.assertEqual(3, len(t1._colsToRead))
     self.assertEqual(1, len(t1._dateList))
     t1.processHeader(self._header.split(',')[:6])
     self.assertEqual(4, len(t1._colsToRead))
     self.assertEqual(2, len(t1._dateList))
     # All date columns.
     t1.processHeader(self._header.split(','))
     self.assertEqual(80, len(t1._colsToRead))
     self.assertEqual(78, len(t1._dateList))
    def test_create_object(self):
        t1 = Covid19GlobalTransformer()
        headerAsTuple = tuple(self._header.split(','))
        firstDatePos = headerAsTuple.index('Long') + 1
        numDateCols = len(headerAsTuple) - firstDatePos
        t1.processHeader(self._header.split(','))
        colIndexList = t1.listOfIndexesOfColumnsToRead()
        self.assertEqual(numDateCols + len(t1.listOfColumnNamesToRead()), len(colIndexList))

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

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

            i = i + 1
 def test2():
     t1 = Covid19GlobalTransformer()
     self.assertEqual(0, len(t1._colsToRead))
     t1.processHeader([])
     self.assertEqual(0, len(t1._colsToRead))
     self.assertEqual(0, len(t1._dateList))
 def test_col_names_icare(self):
     tx = Covid19GlobalTransformer()
     verifyList = ['Country/Region', 'Province/State']
     self.assertEqual(verifyList, tx.listOfColumnNamesToRead())
 def test_lastColumnBeforeDates(self):
     t1 = Covid19GlobalTransformer()
     self.assertEqual('Long', t1.lastColNameBeforeDates())
 def test_colNamesICare(self):
     colList = ['Country/Region', 'Province/State']
     t1 = Covid19GlobalTransformer()
     self.assertEqual(colList, t1.listOfColumnNamesToRead())
 def test_last_col_name_before_dates(self):
     tx = Covid19GlobalTransformer()
     self.assertEqual('Long', tx.lastColNameBeforeDates())