def setup(obsColl_): i = 0 for item in locList: covidObj = Covid19CSV(item[0], item[1], item[2]) dates = list(dateList[i]) values = valueList[i] covidObj.setDate2Value(dates, values) Covid19TransformUtils.addCSVToObsCollection( covidObj, obsColl_) i = i + 1
def test3(): cObj = Covid19CSV('aa', 'bb', 'cc') cObj.setDate2Value(['1/1/20'], (10, )) oColl = ObsCollection() Covid19TransformUtils.addCSVToObsCollection(cObj, oColl) self.assertEqual(1, oColl.numObservations()) self.assertEqual(1, len(oColl.locations())) locations = list(oColl.locations()) self.assertEqual('aa', locations[0]._country) self.assertEqual('bb', locations[0]._state) self.assertEqual('cc', locations[0]._county) obsList = oColl.getObservations(locations[0]) self.assertEqual(1, len(obsList)) self.assertEqual(datetime.strptime('1/1/2020', '%m/%d/%Y'), obsList[0]._obsDate._value) self.assertEqual(10, obsList[0]._value)
def _createVerificationObject(hdr_, str_): # Input string may have embedded commas in a field. # 'aaa, bbb, "ccc, ddd", eee' strAsList = list(csv.reader([str_], delimiter=',', quotechar='"', skipinitialspace=True))[0] strAsTuple = tuple(strAsList) obj = Covid19CSV(strAsTuple[1], strAsTuple[0], '') hdrAsTuple = tuple(hdr_.split(',')) dateAsList = [] for i in range(4, len(hdrAsTuple)): dateAsList.append(hdrAsTuple[i]) valAsList = [] for i in range(4, len(strAsTuple)): valAsList.append(strAsTuple[i]) obj.setDate2Value(dateAsList, tuple(valAsList)) # print(str(obj)) return obj
def test_set_date2value(self): o1 = Covid19CSV('abc', 'def', 'ghi') self.assertEqual(o1._country, 'abc') self.assertEqual(o1._state, 'def') self.assertEqual(o1._county, 'ghi') self.assertEqual(len(o1._dateList), 0) self.assertEqual(len(o1._date2Value.keys()), 0) self.assertEqual(len(self._date2Val.keys()), self._NUM_ENTRIES) self.assertEqual(len(self._dateList), self._NUM_ENTRIES) self.assertEqual(len(self._valueTuple), self._NUM_ENTRIES) o1.setDate2Value(self._dateList, self._valueTuple) self.assertEqual(len(o1._dateList), self._NUM_ENTRIES) self.assertEqual(len(o1._date2Value.keys()), self._NUM_ENTRIES) self.assertTrue(self._compare2Hashes(self._date2Val, o1._date2Value)) o1.setDate2Value(self._dateList[:len(self._dateList) - 1], self._valueTuple) self.assertEqual(self._NUM_ENTRIES - 1, len(o1._dateList)) self.assertEqual(self._NUM_ENTRIES - 1, len(o1._date2Value.keys())) o1.setDate2Value(self._dateList, self._valueTuple[:len(self._valueTuple) - 1]) self.assertEqual(self._NUM_ENTRIES - 1, len(o1._dateList)) self.assertEqual(self._NUM_ENTRIES - 1, len(o1._date2Value.keys()))
def test1(): cObj = Covid19CSV('aa', 'bb', 'cc') oColl = ObsCollection() Covid19TransformUtils.addCSVToObsCollection(cObj, oColl) self.assertEqual(0, oColl.numObservations()) self.assertEqual(0, len(oColl.locations()))
def createObject(self, colsAsTuple_): obj1 = Covid19CSV(colsAsTuple_[0], colsAsTuple_[1], '') obj1.setDate2Value(self._dateList, colsAsTuple_[2:]) return obj1