<s> import unittest <EOL> import GafferTest <EOL> import GafferUI <EOL> class NumericSliderTest ( unittest . TestCase ) : <EOL> def testConstruction ( self ) : <EOL> s = GafferUI . NumericSlider ( value = <NUM_LIT:0> , min = <NUM_LIT:0> , max = <NUM_LIT:1> ) <EOL> self . assertEqual ( s . getPosition ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( s . getValue ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( s . getRange ( ) , ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> def testSetValue ( self ) : <EOL> s = GafferUI . NumericSlider ( value = <NUM_LIT:0> , min = <NUM_LIT:0> , max = <NUM_LIT:2> ) <EOL> self . assertEqual ( s . getPosition ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( s . getValue ( ) , <NUM_LIT:0> ) <EOL> s . setValue ( <NUM_LIT:0.5> ) <EOL> self . assertEqual ( s . getPosition ( ) , <NUM_LIT> ) <EOL> self . assertEqual ( s . getValue ( ) , <NUM_LIT:0.5> ) <EOL> def testSetRange ( self ) : <EOL> s = GafferUI . NumericSlider ( value = <NUM_LIT:1> , min = <NUM_LIT:0> , max = <NUM_LIT:2> ) <EOL> self . assertEqual ( s . getPosition ( ) , <NUM_LIT:0.5> ) <EOL> self . assertEqual ( s . getValue ( ) , <NUM_LIT:1> ) <EOL> s . setRange ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> self . assertEqual ( s . getPosition ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( s . getValue ( ) , <NUM_LIT:1> ) <EOL> def testSetZeroRange ( self ) : <EOL> s = GafferUI . NumericSlider ( value = <NUM_LIT:1> , min = <NUM_LIT:1> , max = <NUM_LIT:2> ) <EOL> self . assertEqual ( s . getPosition ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( s . getValue ( ) , <NUM_LIT:1> ) <EOL> s . setRange ( <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> self . assertEqual ( s . getValue ( ) , <NUM_LIT:1> ) <EOL> def testSetPosition ( self ) : <EOL> s = GafferUI . NumericSlider ( value = <NUM_LIT:0> , min = <NUM_LIT:0> , max = <NUM_LIT:2> ) <EOL> self . assertEqual ( s . getPosition ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( s . getValue ( ) , <NUM_LIT:0> ) <EOL> s . setPosition ( <NUM_LIT:0.5> ) <EOL> self . assertEqual ( s . getPosition ( ) , <NUM_LIT:0.5> ) <EOL> self . assertEqual ( s . getValue ( ) , <NUM_LIT:1> ) <EOL> def testValuesOutsideRangeAreClamped ( self ) : <EOL> s = GafferUI . NumericSlider ( value = <NUM_LIT:0.1> , min = <NUM_LIT:0> , max = <NUM_LIT:2> ) <EOL> cs = GafferTest . CapturingSlot ( s . valueChangedSignal ( ) , s . positionChangedSignal ( ) ) <EOL> s . setValue ( <NUM_LIT:3> ) <EOL> self . assertEqual ( s . getValue ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( s . getPosition ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( cs ) , <NUM_LIT:2> ) <EOL> s . setValue ( <NUM_LIT:3> ) <EOL> self . assertEqual ( s . getValue ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( s . getPosition ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( cs ) , <NUM_LIT:2> ) <EOL> def testPositionsOutsideRangeAreClamped ( self ) : <EOL> s = GafferUI . NumericSlider ( value = <NUM_LIT:0.1> , min = <NUM_LIT:0> , max = <NUM_LIT:2> ) <EOL> cs = GafferTest . CapturingSlot ( s . valueChangedSignal ( ) , s . positionChangedSignal ( ) ) <EOL> s . setPosition ( <NUM_LIT:2> ) <EOL> self . assertEqual ( s . getValue ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( s . getPosition ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( cs ) , <NUM_LIT:2> ) <EOL> s . setPosition ( <NUM_LIT:2> ) <EOL> self . assertEqual ( s . getValue ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( s . getPosition ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( cs ) , <NUM_LIT:2> ) <EOL> def testHardRange ( self ) : <EOL> s = GafferUI . NumericSlider ( value = <NUM_LIT:0.1> , min = <NUM_LIT:0> , max = <NUM_LIT:2> , hardMin = - <NUM_LIT:1> , hardMax = <NUM_LIT:3> ) <EOL> self . assertEqual ( s . getRange ( ) , ( <NUM_LIT:0> , <NUM_LIT:2> , - <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> cs = GafferTest . CapturingSlot ( s . valueChangedSignal ( ) , s . positionChangedSignal ( ) ) <EOL> s . setValue ( <NUM_LIT:3> ) <EOL> self . assertEqual ( s . getValue ( ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( s . getPosition ( ) , <NUM_LIT> ) <EOL> self . assertEqual ( len ( cs ) , <NUM_LIT:2> ) <EOL> s . setValue ( <NUM_LIT> ) <EOL> self . assertEqual ( s . getValue ( ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( s . getPosition ( ) , <NUM_LIT> ) <EOL> self . assertEqual ( len ( cs ) , <NUM_LIT:2> ) <EOL> s . setValue ( - <NUM_LIT:1> ) <EOL> self . assertEqual ( s . getValue ( ) , - <NUM_LIT:1> ) <EOL> self . assertEqual ( s . getPosition ( ) , - <NUM_LIT:0.5> ) <EOL> self . assertEqual ( len ( cs ) , <NUM_LIT:4> ) <EOL> s . setValue ( - <NUM_LIT:2> ) <EOL> self . assertEqual ( s . getValue ( ) , - <NUM_LIT:1> ) <EOL> self . assertEqual ( s . getPosition ( ) , - <NUM_LIT:0.5> ) <EOL> self . assertEqual ( len ( cs ) , <NUM_LIT:4> ) <EOL> def testSetRangeClampsValue ( self ) : <EOL> s = GafferUI . NumericSlider ( value = <NUM_LIT:0.5> , min = <NUM_LIT:0> , max = <NUM_LIT:2> ) <EOL> self . assertEqual ( s . getPosition ( ) , <NUM_LIT> ) <EOL> self . assertEqual ( s . getValue ( ) , <NUM_LIT:0.5> ) <EOL> s . setRange ( <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> self . assertEqual ( s . getPosition ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( s . getValue ( ) , <NUM_LIT:1> ) <EOL> def testMultipleValues ( self ) : <EOL> self . assertRaises ( Exception , GafferUI . NumericSlider , value = <NUM_LIT:0> , values = [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> s = GafferUI . NumericSlider ( values = [ <NUM_LIT:1> , <NUM_LIT> ] , min = <NUM_LIT:0> , max = <NUM_LIT:2> ) <EOL> self . assertEqual ( s . getValues ( ) , [ <NUM_LIT:1> , <NUM_LIT> ] ) <EOL> self . assertEqual ( s . getPositions ( ) , [ <NUM_LIT:0.5> , <NUM_LIT> ] ) <EOL> self . assertRaises ( ValueError , s . getValue ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
