def test_header(self, qtbot): csvwidget = CSVImportDialog() qtbot.addWidget(csvwidget) csvwidget.show() assert csvwidget._header == None checkboxes = csvwidget.findChildren(QtGui.QCheckBox) checkboxes[0].toggle() assert csvwidget._header == 0
def test_preview(self, qtbot, csv_file): csvwidget = CSVImportDialog() qtbot.addWidget(csvwidget) csvwidget.show() labels = csvwidget.findChildren(QtGui.QLabel) lineedits = csvwidget.findChildren(QtGui.QLineEdit) qtbot.keyClicks(lineedits[0], csv_file) groupboxes = csvwidget.findChildren(QtGui.QGroupBox) radiobuttons = groupboxes[0].findChildren(QtGui.QRadioButton) lineedits = groupboxes[0].findChildren(QtGui.QLineEdit) for button in radiobuttons: qtbot.mouseClick(button, QtCore.Qt.LeftButton) if lineedits[0].isEnabled(): qtbot.keyPress(lineedits[0], ';') assert csvwidget._previewTableView.model() is not None def _assert(x, path): path = str(path) assert x assert isinstance(x, DataFrameModel) assert path assert isinstance(path, basestring) csvwidget.load.connect(_assert) with qtbot.waitSignal(csvwidget.load): csvwidget.accepted()
def test_encoding(self, qtbot): csvwidget = CSVImportDialog() qtbot.addWidget(csvwidget) csvwidget.show() comboboxes = csvwidget.findChildren(QtGui.QComboBox) comboboxes[0] assert comboboxes[0].itemText(comboboxes[0].currentIndex()) == 'ASCII' qtbot.mouseClick(comboboxes[0], QtCore.Qt.LeftButton) qtbot.keyPress(comboboxes[0], QtCore.Qt.Key_Down) assert csvwidget._encodingKey != 'iso_ir_6'
def test_delimiter(self, qtbot): csvwidget = CSVImportDialog() qtbot.addWidget(csvwidget) csvwidget.show() groupboxes = csvwidget.findChildren(QtGui.QGroupBox) radiobuttons = groupboxes[0].findChildren(QtGui.QRadioButton) lineedits = groupboxes[0].findChildren(QtGui.QLineEdit) for button in radiobuttons: qtbot.mouseClick(button, QtCore.Qt.LeftButton) if lineedits[0].isEnabled(): qtbot.keyPress(lineedits[0], ' ') assert lineedits[0].text() == '' qtbot.keyPress(lineedits[0], 'a') assert lineedits[0].text() == 'a' assert csvwidget._delimiter == groupboxes[0].currentSelected()
def test_accept_reject(self, qtbot): csvwidget = CSVImportDialog() qtbot.addWidget(csvwidget) csvwidget.show() buttons = csvwidget.findChildren(QtGui.QPushButton) for button in buttons: qtbot.mouseClick(button, QtCore.Qt.LeftButton) assert csvwidget.isVisible() == False csvwidget.show()
def test_fileinput(self, qtbot, csv_file): csvwidget = CSVImportDialog() qtbot.addWidget(csvwidget) csvwidget.show() labels = csvwidget.findChildren(QtGui.QLabel) assert labels[0].text() == u'Choose File' lineedits = csvwidget.findChildren(QtGui.QLineEdit) qtbot.keyClicks(lineedits[0], csv_file) assert csvwidget._previewTableView.model() is not None assert csvwidget._delimiter == u';' assert csvwidget._header is None
def test_read_write(self, qtbot, csv_file, tmp): importWidget = CSVImportDialog() qtbot.addWidget(importWidget) importWidget.show() import_lineedits = importWidget.findChildren(QtGui.QLineEdit) qtbot.keyClicks(import_lineedits[0], csv_file) groupboxes = importWidget.findChildren(QtGui.QGroupBox) radiobuttons = groupboxes[0].findChildren(QtGui.QRadioButton) for button in radiobuttons: if str(button.text()) == 'Semicolon': qtbot.mouseClick(button, QtCore.Qt.LeftButton) break checkboxes = importWidget.findChildren(QtGui.QCheckBox) checkboxes[0].toggle() model_in = importWidget._previewTableView.model() # convert critical datetime column: column_model = model_in.columnDtypeModel() index = column_model.index(4, 1) column_model.setData(index, 'date and time') ## # now we export the data and load it again ## exportWidget = CSVExportDialog(model_in) qtbot.addWidget(exportWidget) exportWidget.show() lineedits = exportWidget.findChildren(QtGui.QLineEdit) qtbot.keyClicks(lineedits[0], tmp) groupboxes = exportWidget.findChildren(QtGui.QGroupBox) radiobuttons = groupboxes[0].findChildren(QtGui.QRadioButton) for button in radiobuttons: if str(button.text()) == 'Semicolon': qtbot.mouseClick(button, QtCore.Qt.LeftButton) break checkboxes = exportWidget.findChildren(QtGui.QCheckBox) checkboxes[0].toggle() buttons = exportWidget.findChildren(QtGui.QPushButton) with qtbot.waitSignal(exportWidget.exported, timeout=3000): for button in buttons: if str(button.text()) == 'Export Data': qtbot.mouseClick(button, QtCore.Qt.LeftButton) break import_lineedits[0].clear() qtbot.keyClicks(import_lineedits[0], tmp) buttons = importWidget.findChildren(QtGui.QPushButton) with qtbot.waitSignal(importWidget.load, timeout=3000): for button in buttons: if str(button.text()) == 'Load Data': model_out_in = importWidget._previewTableView.model() qtbot.mouseClick(button, QtCore.Qt.LeftButton) break column_model = model_out_in.columnDtypeModel() index = column_model.index(4, 1) column_model.setData(index, 'date and time') comparator = model_in.dataFrame() == model_out_in.dataFrame() assert all(comparator) df = model_out_in.dataFrame() assert not df.empty
def test_init(self, qtbot): csvwidget = CSVImportDialog() qtbot.addWidget(csvwidget) csvwidget.show() assert csvwidget.isModal() assert csvwidget.windowTitle() == u'Import CSV'
def __init__(self, parent=None): super(TestWidget, self).__init__(parent) self.resize(1680, 756) self.move(0, 0) self.df = pandas.DataFrame() self.dataModel = None # init the data view's self.dataTableView = DataTableWidget(self) # self.dataTableView.setSortingEnabled(True) # self.dataTableView.setAlternatingRowColors(True) self.dataListView = QtGui.QListView(self) self.dataListView.setAlternatingRowColors(True) self.dataComboBox = QtGui.QComboBox(self) # make combobox to choose the model column for dataComboBox and dataListView self.chooseColumnComboBox = QtGui.QComboBox(self) self.buttonCsvData = QtGui.QPushButton("load csv data") self.buttonRandomData = QtGui.QPushButton("load random data") importDialog = CSVImportDialog(self) importDialog.load.connect(self.updateModel) self.buttonCsvData.clicked.connect(lambda: importDialog.show()) self.buttonRandomData.clicked.connect( lambda: self.setDataFrame(getRandomData(rows=100, columns=100))) self.exportDialog = CSVExportDialog(self) self.buttonCSVExport = QtGui.QPushButton("export to csv") self.buttonCSVExport.clicked.connect(self._exportModel) self.buttonLayout = QtGui.QHBoxLayout() self.buttonLayout.addWidget(self.buttonCsvData) self.buttonLayout.addWidget(self.buttonCSVExport) self.buttonLayout.addWidget(self.buttonRandomData) self.mainLayout = QtGui.QVBoxLayout() self.setLayout(self.mainLayout) self.mainLayout.addLayout(self.buttonLayout) self.mainLayout.addWidget(self.dataTableView) self.spinbox = QtGui.QSpinBox() self.mainLayout.addWidget(self.spinbox) self.spinbox.setMaximum(99999999999) self.spinbox.setValue(99999999999) self.rightLayout = QtGui.QVBoxLayout() self.chooseColumLayout = QtGui.QHBoxLayout() self.mainLayout.addLayout(self.rightLayout) self.rightLayout.addLayout(self.chooseColumLayout) self.chooseColumLayout.addWidget(QtGui.QLabel("Choose column:")) self.chooseColumLayout.addWidget(self.chooseColumnComboBox) self.rightLayout.addWidget(self.dataListView) self.rightLayout.addWidget(self.dataComboBox) self.tableViewColumnDtypes = QtGui.QTableView(self) self.rightLayout.addWidget(QtGui.QLabel('dtypes')) self.rightLayout.addWidget(self.tableViewColumnDtypes) self.buttonGoToColumn = QtGui.QPushButton("go to column") self.rightLayout.addWidget(self.buttonGoToColumn) self.buttonGoToColumn.clicked.connect(self.goToColumn) self.buttonSetFilter = QtGui.QPushButton("set filter") self.rightLayout.addWidget(self.buttonSetFilter) self.buttonSetFilter.clicked.connect(self.setFilter) self.buttonClearFilter = QtGui.QPushButton("clear filter") self.rightLayout.addWidget(self.buttonClearFilter) self.buttonClearFilter.clicked.connect(self.clearFilter) self.lineEditFilterCondition = QtGui.QLineEdit("freeSearch('am')") self.rightLayout.addWidget(self.lineEditFilterCondition) self.chooseColumnComboBox.currentIndexChanged.connect( self.setModelColumn) self.dataListView.mouseReleaseEvent = self.mouseReleaseEvent self.dropLineEdit = DropLineEdit("drop data from table here", self) self.rightLayout.addWidget(self.dropLineEdit) self.dropWidget = ComplexDropWidget(self) self.dropWidget.dropRecieved.connect(self.processDataDrops) self.rightLayout.addWidget(self.dropWidget)