<s> from pandasqt . compat import Qt , QtCore , QtGui <EOL> import pytest <EOL> import pytestqt <EOL> import decimal <EOL> import numpy <EOL> import pandas <EOL> from pandasqt . models . ColumnDtypeModel import ColumnDtypeModel , DTYPE_ROLE <EOL> from pandasqt . models . SupportedDtypes import SupportedDtypes <EOL> from pandasqt . views . CustomDelegates import DtypeComboDelegate <EOL> @ pytest . fixture ( ) <EOL> def dataframe ( ) : <EOL> data = [ <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] , <EOL> [ <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> ] , <EOL> [ <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> ] <EOL> ] <EOL> columns = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> dataFrame = pandas . DataFrame ( data , columns = columns ) <EOL> return dataFrame <EOL> @ pytest . fixture ( ) <EOL> def language_values ( ) : <EOL> return SupportedDtypes . _all <EOL> class TestColumnDType ( object ) : <EOL> def test_customDTypeModel_check_init ( self ) : <EOL> model = ColumnDtypeModel ( ) <EOL> assert model . dataFrame ( ) . empty == True <EOL> assert model . editable ( ) == False <EOL> model = ColumnDtypeModel ( editable = True ) <EOL> assert model . editable ( ) == True <EOL> def test_headerData ( self ) : <EOL> model = ColumnDtypeModel ( ) <EOL> ret = model . headerData ( <NUM_LIT:0> , Qt . Horizontal ) <EOL> assert ret == '<STR_LIT>' <EOL> ret = model . headerData ( <NUM_LIT:1> , Qt . Horizontal ) <EOL> assert ret == '<STR_LIT>' <EOL> ret = model . headerData ( <NUM_LIT:2> , Qt . Horizontal ) <EOL> assert ret == None <EOL> ret = model . headerData ( <NUM_LIT:0> , Qt . Horizontal , Qt . EditRole ) <EOL> assert ret == None <EOL> ret = model . headerData ( <NUM_LIT:0> , Qt . Vertical ) <EOL> assert ret == None <EOL> def test_data ( self , dataframe ) : <EOL> model = ColumnDtypeModel ( dataFrame = dataframe ) <EOL> index = model . index ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> ret = index . data ( ) <EOL> assert ret == '<STR_LIT>' <EOL> ret = index . data ( Qt . EditRole ) <EOL> assert ret == '<STR_LIT>' <EOL> ret = index . data ( DTYPE_ROLE ) <EOL> assert ret == None <EOL> index = index . sibling ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> ret = index . data ( DTYPE_ROLE ) <EOL> assert ret == numpy . dtype ( numpy . int64 ) <EOL> assert index . data ( ) == '<STR_LIT>' == SupportedDtypes . description ( ret ) <EOL> index = index . sibling ( <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> assert index . data ( DTYPE_ROLE ) == None <EOL> index = QtCore . QModelIndex ( ) <EOL> assert model . data ( index ) == None <EOL> index = model . index ( <NUM_LIT:2> , <NUM_LIT:0> ) <EOL> ret = index . data ( ) <EOL> assert ret == '<STR_LIT>' <EOL> def test_setData ( self , dataframe , language_values , qtbot ) : <EOL> model = ColumnDtypeModel ( dataFrame = dataframe ) <EOL> index = model . index ( <NUM_LIT:3> , <NUM_LIT:1> ) <EOL> model . setEditable ( True ) <EOL> datetime = ( ) <EOL> for ( expected_type , string ) in language_values : <EOL> if expected_type == numpy . dtype ( '<STR_LIT>' ) : <EOL> datetime = ( string , expected_type ) <EOL> continue <EOL> else : <EOL> model . setData ( index , string ) <EOL> assert index . data ( DTYPE_ROLE ) == expected_type <EOL> assert model . setData ( index , '<STR_LIT:bool>' , Qt . DisplayRole ) == False <EOL> with pytest . raises ( Exception ) as err : <EOL> model . setData ( index , datetime [ <NUM_LIT:0> ] ) <EOL> assert "<STR_LIT>" in str ( err . value ) <EOL> for data in [ <EOL> [ "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" ] <EOL> ] : <EOL> df = pandas . DataFrame ( data , columns = [ "<STR_LIT>" ] ) <EOL> model = ColumnDtypeModel ( dataFrame = df ) <EOL> index = model . index ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> model . setEditable ( True ) <EOL> assert model . setData ( index , "<STR_LIT>" ) == True <EOL> with qtbot . waitSignal ( model . changeFailed ) : <EOL> model . setData ( index , '<STR_LIT:bool>' ) <EOL> def test_flags ( self , dataframe ) : <EOL> model = ColumnDtypeModel ( dataFrame = dataframe ) <EOL> model . setEditable ( True ) <EOL> index = model . index ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> assert model . flags ( index ) == Qt . ItemIsEnabled | Qt . ItemIsSelectable <EOL> index = index . sibling ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> assert model . flags ( index ) == Qt . ItemIsSelectable | Qt . ItemIsEnabled | Qt . ItemIsEditable <EOL> index = index . sibling ( <NUM_LIT:15> , <NUM_LIT:1> ) <EOL> assert model . flags ( index ) == Qt . NoItemFlags <EOL> def test_columnCount ( self ) : <EOL> model = ColumnDtypeModel ( ) <EOL> assert model . columnCount ( ) == <NUM_LIT:2> <EOL> def test_rowCount ( self , dataframe ) : <EOL> model = ColumnDtypeModel ( ) <EOL> assert model . rowCount ( ) == <NUM_LIT:0> <EOL> model . setDataFrame ( dataframe ) <EOL> assert model . rowCount ( <NUM_LIT:5> ) <EOL> def test_setDataFrame ( self , dataframe ) : <EOL> model = ColumnDtypeModel ( ) <EOL> model . setDataFrame ( dataframe ) <EOL> assert model . rowCount ( <NUM_LIT:5> ) <EOL> with pytest . raises ( TypeError ) as err : <EOL> model . setDataFrame ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:list>' , '<STR_LIT>' ] ) <EOL> assert '<STR_LIT>' in str ( err . value ) <EOL> class TestDtypeComboDelegate ( object ) : <EOL> def test_editing ( self , dataframe , qtbot ) : <EOL> model = ColumnDtypeModel ( dataFrame = dataframe ) <EOL> model . setEditable ( True ) <EOL> tableView = QtGui . QTableView ( ) <EOL> qtbot . addWidget ( tableView ) <EOL> tableView . setModel ( model ) <EOL> delegate = DtypeComboDelegate ( tableView ) <EOL> tableView . setItemDelegateForColumn ( <NUM_LIT:1> , delegate ) <EOL> tableView . show ( ) <EOL> index = model . index ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> preedit_data = index . data ( DTYPE_ROLE ) <EOL> tableView . edit ( index ) <EOL> editor = tableView . findChildren ( QtGui . QComboBox ) [ <NUM_LIT:0> ] <EOL> selectedIndex = editor . currentIndex ( ) <EOL> editor . setCurrentIndex ( selectedIndex + <NUM_LIT:1> ) <EOL> postedit_data = index . data ( DTYPE_ROLE ) <EOL> assert preedit_data != postedit_data <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> pytest . main ( ) </s>
