def test_dataframeeditor_edit_bool(qtbot, monkeypatch): """Test that bools are editible in df and false-y strs are detected.""" MockQMessageBox = Mock() attr_to_patch = ('spyder.widgets.variableexplorer' + '.dataframeeditor.QMessageBox') monkeypatch.setattr(attr_to_patch, MockQMessageBox) test_params = [numpy.bool_, numpy.bool, bool] test_strs = ['foo', 'false', 'f', '0', '0.', '0.0', '', ' '] expected_df = DataFrame([1, 0, 0, 0, 0, 0, 0, 0, 0], dtype=bool) for bool_type in test_params: test_df = DataFrame([0, 1, 1, 1, 1, 1, 1, 1, 0], dtype=bool_type) dialog = DataFrameEditor() assert dialog.setup_and_check(test_df, 'Test Dataframe') dialog.show() qtbot.waitForWindowShown(dialog) view = dialog.dataTable qtbot.keyClick(view, Qt.Key_Right) for test_str in test_strs: qtbot.keyClick(view, Qt.Key_Space) qtbot.keyClick(view.focusWidget(), Qt.Key_Backspace) qtbot.keyClicks(view.focusWidget(), test_str) qtbot.keyClick(view.focusWidget(), Qt.Key_Down) assert not MockQMessageBox.critical.called qtbot.wait(200) dialog.accept() qtbot.wait(500) try: assert (numpy.sum(expected_df[0].values == dialog.get_value(). values[:, 0]) == len(expected_df)) except AttributeError: assert (numpy.sum(expected_df[0].as_matrix() == dialog.get_value(). as_matrix()[:, 0]) == len(expected_df))
def test_dataframeeditor_edit_overflow(qtbot, monkeypatch): """ Test that entry of an overflowing integer is caught and handled properly. Integration regression test for issue #6114 . """ MockQMessageBox = Mock() attr_to_patch = ('spyder.widgets.variableexplorer' + '.dataframeeditor.QMessageBox') monkeypatch.setattr(attr_to_patch, MockQMessageBox) # Numpy doesn't raise the OverflowError for ints smaller than 64 bits if not os.name == 'nt': int32_bit_exponent = 66 else: int32_bit_exponent = 34 test_parameters = [(1, numpy.int32, int32_bit_exponent), (2, numpy.int64, 66)] expected_df = DataFrame([5, 6, 7, 3, 4]) for idx, int_type, bit_exponet in test_parameters: test_df = DataFrame(numpy.arange(0, 5), dtype=int_type) dialog = DataFrameEditor() assert dialog.setup_and_check(test_df, 'Test Dataframe') dialog.show() qtbot.waitForWindowShown(dialog) view = dialog.dataTable qtbot.keyClick(view, Qt.Key_Right) qtbot.keyClicks(view, '5') qtbot.keyClick(view, Qt.Key_Down) qtbot.keyClick(view, Qt.Key_Space) qtbot.keyClick(view.focusWidget(), Qt.Key_Backspace) qtbot.keyClicks(view.focusWidget(), str(int(2**bit_exponet))) qtbot.keyClick(view.focusWidget(), Qt.Key_Down) MockQMessageBox.critical.assert_called_with(ANY, "Error", ANY) assert MockQMessageBox.critical.call_count == idx qtbot.keyClicks(view, '7') qtbot.keyClick(view, Qt.Key_Up) qtbot.keyClicks(view, '6') qtbot.keyClick(view, Qt.Key_Down) qtbot.wait(200) dialog.accept() qtbot.wait(500) try: assert numpy.sum(expected_df[0].values == dialog.get_value().values) == len(expected_df) except AttributeError: assert numpy.sum(expected_df[0].as_matrix() == dialog.get_value(). as_matrix()) == len(expected_df)
def test_dataframeeditor_edit_bool(qtbot, monkeypatch): """Test that bools are editible in df and false-y strs are detected""" MockQMessageBox = Mock() attr_to_patch = ('spyder.widgets.variableexplorer' + '.dataframeeditor.QMessageBox') monkeypatch.setattr(attr_to_patch, MockQMessageBox) test_params = [numpy.bool_, numpy.bool, bool] test_strs = ['foo', 'false', 'f', '0', '0.', '0.0', '', ' '] expected_df = DataFrame([1, 0, 0, 0, 0, 0, 0, 0, 0], dtype=bool) for bool_type in test_params: test_df = DataFrame([0, 1, 1, 1, 1, 1, 1, 1, 0], dtype=bool_type) dialog = DataFrameEditor() assert dialog.setup_and_check(test_df, 'Test Dataframe') dialog.show() qtbot.waitForWindowShown(dialog) view = dialog.dataTable qtbot.keyPress(view, Qt.Key_Right) for test_str in test_strs: qtbot.keyPress(view, Qt.Key_Space) qtbot.keyPress(view.focusWidget(), Qt.Key_Backspace) qtbot.keyClicks(view.focusWidget(), test_str) qtbot.keyPress(view.focusWidget(), Qt.Key_Down) assert not MockQMessageBox.critical.called qtbot.keyPress(view, Qt.Key_Return) qtbot.wait(1000) assert (numpy.sum(expected_df[0].as_matrix() == dialog.get_value().as_matrix()[:, 0]) == len(expected_df))
def test_dataframeeditor_edit_complex(qtbot, monkeypatch): """ Test that editing complex dtypes is handled gracefully in df editor. Integration regression test for issue #6115 . """ MockQMessageBox = Mock() attr_to_patch = ('spyder.widgets.variableexplorer' + '.dataframeeditor.QMessageBox') monkeypatch.setattr(attr_to_patch, MockQMessageBox) test_params = [(1, numpy.complex128), (2, numpy.complex64), (3, complex)] for count, complex_type in test_params: test_df = DataFrame(numpy.arange(10, 15), dtype=complex_type) dialog = DataFrameEditor() assert dialog.setup_and_check(test_df, 'Test Dataframe') dialog.show() qtbot.waitForWindowShown(dialog) view = dialog.dataTable qtbot.keyClick(view, Qt.Key_Right) qtbot.keyClick(view, Qt.Key_Down) qtbot.keyClick(view, Qt.Key_Space) qtbot.keyClick(view.focusWidget(), Qt.Key_Backspace) qtbot.keyClicks(view.focusWidget(), "42") qtbot.keyClick(view.focusWidget(), Qt.Key_Down) MockQMessageBox.critical.assert_called_with(ANY, "Error", ANY) assert MockQMessageBox.critical.call_count == count * 2 - 1 qtbot.keyClick(view, Qt.Key_Down) qtbot.keyClick(view, '1') qtbot.keyClick(view.focusWidget(), Qt.Key_Down) MockQMessageBox.critical.assert_called_with( ANY, "Error", ("Editing dtype {0!s} not yet supported.".format( type(test_df.iloc[1, 0]).__name__))) assert MockQMessageBox.critical.call_count == count * 2 qtbot.wait(200) dialog.accept() qtbot.wait(500) try: assert numpy.sum( test_df[0].values == dialog.get_value().values) == len(test_df) except AttributeError: assert numpy.sum(test_df[0].as_matrix() == dialog.get_value().as_matrix()) == len(test_df)
def test_dataframeeditor_edit_overflow(qtbot, monkeypatch): """Test #6114: Entry of an overflow int is caught and handled properly""" MockQMessageBox = Mock() attr_to_patch = ('spyder.widgets.variableexplorer' + '.dataframeeditor.QMessageBox') monkeypatch.setattr(attr_to_patch, MockQMessageBox) # Numpy doesn't raise the OverflowError for ints smaller than 64 bits if platform.startswith('linux'): int32_bit_exponent = 66 else: int32_bit_exponent = 34 test_parameters = [(1, numpy.int32, int32_bit_exponent), (2, numpy.int64, 66)] expected_df = DataFrame([5, 6, 7, 3, 4]) for idx, int_type, bit_exponet in test_parameters: test_df = DataFrame(numpy.arange(0, 5), dtype=int_type) dialog = DataFrameEditor() assert dialog.setup_and_check(test_df, 'Test Dataframe') dialog.show() qtbot.waitForWindowShown(dialog) view = dialog.dataTable qtbot.keyPress(view, Qt.Key_Right) qtbot.keyClicks(view, '5') qtbot.keyPress(view, Qt.Key_Down) qtbot.keyPress(view, Qt.Key_Space) qtbot.keyPress(view.focusWidget(), Qt.Key_Backspace) qtbot.keyClicks(view.focusWidget(), str(int(2 ** bit_exponet))) qtbot.keyPress(view.focusWidget(), Qt.Key_Down) MockQMessageBox.critical.assert_called_with(ANY, "Error", ANY) assert MockQMessageBox.critical.call_count == idx qtbot.keyClicks(view, '7') qtbot.keyPress(view, Qt.Key_Up) qtbot.keyClicks(view, '6') qtbot.keyPress(view, Qt.Key_Down) qtbot.keyPress(view, Qt.Key_Return) assert numpy.sum(expected_df[0].as_matrix() == dialog.get_value().as_matrix()) == len(expected_df)
def test_dataframeeditor_edit_complex(qtbot, monkeypatch): """Test for #6115: editing complex dtypes raises error in df editor""" MockQMessageBox = Mock() attr_to_patch = ('spyder.widgets.variableexplorer' + '.dataframeeditor.QMessageBox') monkeypatch.setattr(attr_to_patch, MockQMessageBox) test_params = [(1, numpy.complex128), (2, numpy.complex64), (3, complex)] for count, complex_type in test_params: test_df = DataFrame(numpy.arange(10, 15), dtype=complex_type) dialog = DataFrameEditor() assert dialog.setup_and_check(test_df, 'Test Dataframe') dialog.show() qtbot.waitForWindowShown(dialog) view = dialog.dataTable qtbot.keyPress(view, Qt.Key_Right) qtbot.keyPress(view, Qt.Key_Down) qtbot.keyPress(view, Qt.Key_Space) qtbot.keyPress(view.focusWidget(), Qt.Key_Backspace) qtbot.keyClicks(view.focusWidget(), "42") qtbot.keyPress(view.focusWidget(), Qt.Key_Down) MockQMessageBox.critical.assert_called_with(ANY, "Error", ANY) assert MockQMessageBox.critical.call_count == count * 2 - 1 qtbot.keyPress(view, Qt.Key_Down) qtbot.keyClick(view, '1') qtbot.keyPress(view.focusWidget(), Qt.Key_Down) MockQMessageBox.critical.assert_called_with( ANY, "Error", ("Editing dtype {0!s} not yet supported." .format(type(test_df.iloc[1, 0]).__name__))) assert MockQMessageBox.critical.call_count == count * 2 qtbot.keyPress(view, Qt.Key_Return) qtbot.wait(1000) assert numpy.sum(test_df[0].as_matrix() == dialog.get_value().as_matrix()) == len(test_df)