Skip to content

Commit

Permalink
Merge pull request #4267 from dalthviz/fixes_issue_4257
Browse files Browse the repository at this point in the history
PR: Add missing parameter to copy contents with the format defined in array editor
  • Loading branch information
ccordoba12 authored Mar 21, 2017
2 parents 291aa84 + 653946c commit 260735e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions spyder/widgets/variableexplorer/arrayeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from qtpy.compat import from_qvariant, to_qvariant
from qtpy.QtCore import (QAbstractTableModel, QItemSelection,
QItemSelectionRange, QModelIndex, Qt, Slot)
from qtpy.QtGui import QColor, QCursor, QDoubleValidator
from qtpy.QtGui import QColor, QCursor, QDoubleValidator, QKeySequence
from qtpy.QtWidgets import (QAbstractItemDelegate, QApplication, QCheckBox,
QComboBox, QDialog, QDialogButtonBox, QGridLayout,
QHBoxLayout, QInputDialog, QItemDelegate, QLabel,
Expand Down Expand Up @@ -492,7 +492,7 @@ def _sel_to_text(self, cell_range):
output = io.StringIO()
try:
np.savetxt(output, _data[row_min:row_max+1, col_min:col_max+1],
delimiter='\t')
delimiter='\t', fmt=self.model().get_format())
except:
QMessageBox.warning(self, _("Warning"),
_("It was not possible to copy values for "
Expand Down
25 changes: 24 additions & 1 deletion spyder/widgets/variableexplorer/tests/test_arrayeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import numpy as np
from numpy.testing import assert_array_equal
import pytest
from qtpy.QtCore import Qt

# Local imports
from spyder.utils.qthelpers import qapplication
from spyder.widgets.variableexplorer.arrayeditor import ArrayEditor


Expand All @@ -28,9 +28,32 @@ def launch_arrayeditor(data, title="", xlabels=None, ylabels=None):
dlg.accept() # trigger slot connected to OK button
return dlg.get_value()

def setup_arrayeditor(qbot, data, title="", xlabels=None, ylabels=None):
"""Setups an arrayeditor."""
dlg = ArrayEditor()
dlg.setup_and_check(data, title, xlabels=xlabels, ylabels=ylabels)
dlg.show()
qbot.addWidget(dlg)
return dlg

# --- Tests
# -----------------------------------------------------------------------------
def test_arrayeditor_format(qtbot):
"""Changes the format of the array and validates its selected content."""
arr = np.array([1, 2, 3], dtype=np.float32)
dlg = setup_arrayeditor(qtbot, arr, "test array float32")
qtbot.keyClick(dlg.arraywidget.view, Qt.Key_Down, modifier=Qt.ShiftModifier)
qtbot.keyClick(dlg.arraywidget.view, Qt.Key_Down, modifier=Qt.ShiftModifier)
contents = dlg.arraywidget.view._sel_to_text(dlg.arraywidget.view.selectedIndexes())
assert contents == "1.000\n2.000\n"
dlg.arraywidget.view.model().set_format("%.18e")
assert dlg.arraywidget.view.model().get_format() == "%.18e"
qtbot.keyClick(dlg.arraywidget.view, Qt.Key_Down, modifier=Qt.ShiftModifier)
qtbot.keyClick(dlg.arraywidget.view, Qt.Key_Down, modifier=Qt.ShiftModifier)
contents = dlg.arraywidget.view._sel_to_text(dlg.arraywidget.view.selectedIndexes())
assert contents == "1.000000000000000000e+00\n2.000000000000000000e+00\n"


def test_arrayeditor_with_string_array(qtbot):
arr = np.array(["kjrekrjkejr"])
assert arr == launch_arrayeditor(arr, "string array")
Expand Down

0 comments on commit 260735e

Please sign in to comment.