def setup(self): self.app = wx.App() self.BulkInsert = BulkInsert(None) path = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) self.CSVPath = os.path.join(path, 'example_files', 'exampleBulkInsert.csv') self.CSVPath2 =os.path.join(path, 'example_files', 'exampleBulkInsert_win.csv') self.CSVPath3 =os.path.join(path, 'example_files', 'CSVUploadTemplate_Mac.csv') self.template_paths = [self.CSVPath, self.CSVPath2, self.CSVPath3]
def setup(self): self.app = wx.App() self.BulkInsert = BulkInsert(None) self.CSVPath = os.path.join('.', 'example_files', 'exampleBulkInsert.csv') self.CSVPath2 =os.path.join('.', 'example_files', 'exampleBulkInsert_win.csv') self.CSVPath3 =os.path.join('.', 'example_files', 'CSVUploadTemplate_Mac.csv') self.template_paths = [self.CSVPath, self.CSVPath2, self.CSVPath3]
class TestBulkInsert: def setup(self): self.app = wx.App() self.BulkInsert = BulkInsert(None) self.CSVPath = os.path.join('.', 'example_files', 'exampleBulkInsert.csv') self.CSVPath2 = os.path.join('.', 'example_files', 'exampleBulkInsert_win.csv') self.CSVPath3 = os.path.join('.', 'example_files', 'CSVUploadTemplate_Mac.csv') self.template_paths = [self.CSVPath, self.CSVPath2, self.CSVPath3] def teardown(self): pass def test_obtainFilePath(self): assert self.BulkInsert assert self.CSVPath def test_readDataFromCSV(self): assert self.BulkInsert assert self.CSVPath for i in self.template_paths: example = self.BulkInsert.readDataFromCSV(i) if not isinstance(example, bool): assert not example.empty else: assert example # assert len(example) == 1 # test reading def test_loadIntoDataFrame(self): assert self.BulkInsert assert self.CSVPath result = self.BulkInsert.readDataFromCSV(self.CSVPath) assert not result.empty def test_onUpload(self): assert self.BulkInsert assert isinstance(self.BulkInsert.col, list) assert self.CSVPath
class TestBulkInsert: def setup(self): self.app = wx.App() self.BulkInsert = BulkInsert(None) path = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) self.CSVPath = os.path.join(path, 'example_files', 'exampleBulkInsert.csv') self.CSVPath2 =os.path.join(path, 'example_files', 'exampleBulkInsert_win.csv') self.CSVPath3 =os.path.join(path, 'example_files', 'CSVUploadTemplate_Mac.csv') self.template_paths = [self.CSVPath, self.CSVPath2, self.CSVPath3] def teardown(self): pass def test_obtainFilePath(self): assert self.BulkInsert assert self.CSVPath def test_readDataFromCSV(self): assert self.BulkInsert assert self.CSVPath for i in self.template_paths: example = self.BulkInsert.readDataFromCSV(i) if not isinstance(example, bool): assert not example.empty else: assert example # assert len(example) == 1 # test reading def test_loadIntoDataFrame(self): assert self.BulkInsert assert self.CSVPath result = self.BulkInsert.readDataFromCSV(self.CSVPath) assert not result.empty def test_onUpload(self): assert self.BulkInsert assert isinstance(self.BulkInsert.col, list) assert self.CSVPath
def __init__(self, parent, **kwargs): if 'recordService' in kwargs: self.recordService = kwargs['recordService'] clsAddPoints.AddPoints.__init__(self, parent, **kwargs) self.frame = BulkInsert(self)
class AddPoints(clsAddPoints.AddPoints): def __init__(self, parent, **kwargs): if 'recordService' in kwargs: self.recordService = kwargs['recordService'] clsAddPoints.AddPoints.__init__(self, parent, **kwargs) self.frame = BulkInsert(self) def checkIfEditing(self): # Deleting a cell being edited doesn't finish editing if self.olv.cellEditor: self.olv._PossibleFinishCellEdit() # Handlers for AddPoints events. def onAddBtn(self, event): """ :param event: :return: """ self.checkIfEditing() self.olv.AddObject(self.olv.sampleRow()) event.Skip() def onClearAllBtn(self, event): """ :param event: :return: """ if len(self.olv.GetObjects()) < 1: wx.MessageBox("Nothing to remove here", " ", wx.OK) return msg = GMD.GenericMessageDialog(None, 'Are you sure you want to delete your work?', 'Clear Everything?', wx.YES_NO | wx.ICON_WARNING |wx.NO_DEFAULT ) value = msg.ShowModal() if value == wx.ID_YES: self._clearAll() return def _clearAll(self): self.checkIfEditing() self.olv.SetObjects(None) def onDeleteBtn(self, event): """ :param event: :return: """ self.checkIfEditing() try: if self.selectedObject: if len(self.selectedObject) > 1: length = len(self.selectedObject) msg = GMD.GenericMessageDialog(None, 'Are you sure you want to delete %d items' % length, 'Clear items?', wx.YES_NO | wx.ICON_WARNING | wx.NO_DEFAULT) value = msg.ShowModal() if value == wx.ID_YES: self.customRemove(self.selectedObject) else: self.customRemove(self.selectedObject) except TypeError as e: msg = GMD.GenericMessageDialog(None, 'Are you sure you want to delete your work?', 'Clear items?', wx.YES_NO | wx.ICON_WARNING | wx.NO_DEFAULT) value = msg.ShowModal() if value == wx.ID_YES: self.customRemove(self.selectedObject) #self.sb.SetStatusText("Removing %s" % self.sb.SetStatusText("Removing %s" % self.selectedObject.dataValue)) self.selectedObject = None event.Skip() def customRemove(self, object): """ :param object: :return: """ obj = self.olv.GetObjects() if isinstance(object, list): for x in object: obj.remove(x) else: obj.remove(object) self.olv.SetObjects(obj) def onUploadBtn(self, event): """ :param event: :return: """ self.checkIfEditing() if not self.frame.IsShown(): self.frame.CenterOnParent() self.frame.ShowModal() self.frame.SetFocus() else: self.frame.Hide() event.Skip() def onInfoBtn(self, event): """ :param event: :return: """ self.checkIfEditing() message = "DataValue: FLOAT\n" \ "Date: YYYY-MM-DD\n" \ "Time: HH:MM:SS\n" \ "UTCOffSet: INT (Range [-12,12])\n" \ "CensorCode: gt|nc|lt|nd|pnq\n" \ "ValueAccuracy: FLOAT\n" \ "OffSetValue: INT\n" \ "OffSetType: STRING\n" \ "QualifierCode: STRING\n" \ "LabSampleCode: STRING\n" dlg = GMD.GenericMessageDialog(self, message, "Format Guide", agwStyle=wx.ICON_INFORMATION | wx.OK | GMD.GMD_USE_GRADIENTBUTTONS) dlg.ShowModal() event.Skip() def onFinishedBtn(self, event): """ :param event: :return: """ self.checkIfEditing() #try: points, isIncorrect = self.parseTable() #except: # return message = "" if not points and not isIncorrect: #print "Leaving..." self.Close() return elif not points: message = "Unfortunately there are no points to add, " \ "please check that the data was entered correctly " \ "and try again. " dlg = GMD.GenericMessageDialog(None, message, "Nothing to add", agwStyle=wx.ICON_WARNING | wx.CANCEL | wx.OK | GMD.GMD_USE_GRADIENTBUTTONS) dlg.SetOKCancelLabels(ok="Return to AddPoint Menu", cancel="Quit to ODMTools") value = dlg.ShowModal() if value == wx.ID_OK: return else: self.Close() return elif isIncorrect: message = "Are you ready to add points? " \ "There are rows that are incorrectly formatted, " \ "those rows will not be added. Continue?" else: message = "Are you ready to add points? " \ "Ready to add points to the database?" msg = GMD.GenericMessageDialog(None, message, 'Add Points?', wx.YES_NO | wx.ICON_QUESTION | wx.NO_DEFAULT | GMD.GMD_USE_GRADIENTBUTTONS) value = msg.ShowModal() if value == wx.ID_NO: return self.recordService.add_points(points) self.Close() event.Skip() def onSelected(self, event): """ :param event: :return: """ obj = event.GetEventObject() object = obj.innerList[obj.FocusedItem] object = self.olv.GetSelectedObjects() try: if len(object) > 1: self.selectedObject = object else: self.selectedObject = object[0] except TypeError as e: pass except IndexError as e: pass event.Skip() def parseTable(self): """ :return: """ series = self.recordService.get_series() objects = self.olv.GetObjects() isIncorrect = False points = [] for i in objects: if self.olv.isCorrect(i): row = [None] * 10 if i.valueAccuracy != "NULL": row[1] = i.valueAccuracy if i.offSetType != "NULL": row[6] = i.offSetType if i.qualifierCode != "NULL": row[8] = i.qualifierCode if i.labSampleCode != "NULL": row[9] = i.labSampleCode row[0] = i.dataValue dt = self.combineDateTime(i.date, i.time) row[2] = dt ## UTC Offset row[3] = i.utcOffSet ## Calculate UTC time based off the localdatetime and utcOffSet row[4] = dt - datetime.timedelta(hours=int(i.utcOffSet)) row[7] = i.censorCode row.extend([ series.site_id, series.variable_id, series.method_id, series.source_id, series.quality_control_level_id ] ) points.append(tuple(row)) else: isIncorrect = True return points, isIncorrect def combineDateTime(self, date, time): """ Combines date and time into datetime.datetime :param date: :type datetime.date or str: :param time: :type str: :return: :type datetime.datetime: """ newTime = datetime.datetime.strptime(time, "%H:%M:%S").time() newDate = date if not isinstance(date, datetime.date): newDate = datetime.datetime.strptime(date, "%Y-%m-%d").date() return datetime.datetime.combine(newDate, newTime) def onCheck(self, event): object = event.object