Exemplo n.º 1
0
    def test_setData(self, dataframe, language_values, qtbot):
        model = ColumnDtypeModel(dataFrame=dataframe)
        index = model.index(3, 1)
        model.setEditable(True)

        # change all values except datetime
        datetime = ()
        for (expected_type, string) in language_values:
            if expected_type == numpy.dtype('<M8[ns]'):
                datetime = (string, expected_type)
                continue
            else:
                model.setData(index, string)
                assert index.data(DTYPE_ROLE) == expected_type

        assert model.setData(index, 'bool', Qt.DisplayRole) == False

        with pytest.raises(Exception) as err:
            model.setData(index, datetime[0])
        assert "Can't convert a boolean value into a datetime value" in str(err.value)

        # rewrite this with parameters
        for data in [
                ["2012-12-13"],
                ["2012-12-13 19:10"],
                ["2012-12-13 19:10:10"]
        ]:
            df = pandas.DataFrame(data, columns=["datetime"])
            model = ColumnDtypeModel(dataFrame=df)
            index = model.index(0, 0)
            model.setEditable(True)
            assert model.setData(index, "date and time") == True

        # convert datetime to anything else does not work and leave the
        # datatype unchanged. An error message is emitted.

        with qtbot.waitSignal(model.changeFailed):
            model.setData(index, 'bool')
Exemplo n.º 2
0
    def test_setData(self, dataframe, language_values, qtbot):
        model = ColumnDtypeModel(dataFrame=dataframe)
        index = model.index(3, 1)
        model.setEditable(True)

        # change all values except datetime
        datetime = ()
        for (expected_type, string) in language_values:
            if expected_type == numpy.dtype('<M8[ns]'):
                datetime = (string, expected_type)
                continue
            else:
                model.setData(index, string)
                assert index.data(DTYPE_ROLE) == expected_type

        assert model.setData(index, 'bool', Qt.DisplayRole) == False

        # change datatype to datetime
        assert model.setData(index, datetime[0]) == True
        # convert datetime to anything else does not work and leave the
        # datatype unchanged. An error message is emitted.

        with qtbot.waitSignal(model.changeFailed):
            model.setData(index, 'bool')
Exemplo n.º 3
0
    def test_setData(self, dataframe, language_values, qtbot):
        model = ColumnDtypeModel(dataFrame=dataframe)
        index = model.index(3, 1)
        model.setEditable(True)

        # change all values except datetime
        datetime = ()
        for (expected_type, string) in language_values:
            if expected_type == numpy.dtype('<M8[ns]'):
                datetime = (string, expected_type)
                continue
            else:
                model.setData(index, string)
                assert index.data(DTYPE_ROLE) == expected_type

        assert model.setData(index, 'bool', Qt.DisplayRole) == False

        # change datatype to datetime
        assert model.setData(index, datetime[0]) == True
        # convert datetime to anything else does not work and leave the
        # datatype unchanged. An error message is emitted.

        with qtbot.waitSignal(model.changeFailed):
            model.setData(index, 'bool')