def test_labelLocs(self): s = Slider(self.win, size=(1, 0.1), labels=('a', 'b', 'c', 'd', 'e')) assert s.labelLocs[0][0] == -.5 and s.labelLocs[0][1] == -.1 assert s.labelLocs[1][0] == -.25 and s.labelLocs[1][1] == -.1 assert s.labelLocs[2][0] == .0 and s.labelLocs[2][1] == -.1 assert s.labelLocs[3][0] == .25 and s.labelLocs[3][1] == -.1 assert s.labelLocs[4][0] == .5 and s.labelLocs[4][1] == -.1
def test_tickLocs(self): s = Slider(self.win, size=(1, 0.1), ) assert s.tickLocs[0][0] == -.5 and s.tickLocs[0][1] == 0.0 assert s.tickLocs[1][0] == -.25 and s.tickLocs[1][1] == 0.0 assert s.tickLocs[2][0] == .0 and s.tickLocs[2][1] == 0.0 assert s.tickLocs[3][0] == .25 and s.tickLocs[3][1] == 0.0 assert s.tickLocs[4][0] == .5 and s.tickLocs[4][1] == 0.0
def test_getRT(self): s = Slider(self.win, size=(1, 0.1)) testRT = .89 s.recordRating(2, testRT) assert s.history[-1][1] == s.getRT() assert type(s.getRT()) == float assert s.getRT() == testRT
def test_ratingToPos(self): s = Slider( self.win, size=(1, 0.1), ) assert s._ratingToPos(3)[0][0] == 0 assert s._ratingToPos(1)[0][0] == -.5 assert s._ratingToPos(5)[0][0] == .5
def test_posToRatingToPos(self): s = Slider( self.win, size=(1, 0.1), ) assert s._posToRating((0, 0)) == 3 assert s._posToRating((-.5, 0)) == 1 assert s._posToRating((.5, 0)) == 5
def test_granularity(self): s = Slider(self.win, size=(1, 0.1), granularity=1) minRating, maxRating = 1, 5 assert s.granularity == 1 assert s._granularRating(1) == minRating assert s._granularRating(5) == maxRating assert s._granularRating(0) == minRating assert s._granularRating(6) == maxRating
def test_color(self): colors = ['black', 'red'] for color in colors: s = Slider(self.win, color=color) assert s.line._foreColor == Color(color, s.colorSpace) assert s.tickLines._colors == Color(color, s.colorSpace) for l in s.labelObjs: assert l.color == color
def test_color(self): colors = [['red', 'blue', 'yellow'], ['blue', 'yellow', 'red'], ['yellow', 'red', 'blue']] for color in colors: s = Slider(self.win, color=color[0], fillColor=color[1], borderColor=color[2]) for l in s.labelObjs: assert l._foreColor == Color(color[0], s.colorSpace) assert s.marker._fillColor == Color(color[1], s.colorSpace) assert s.line._foreColor == Color(color[2], s.colorSpace) assert s.tickLines._colors == Color(color[2], s.colorSpace)
def test_color(self): colors = ['black', 'red'] for color in colors: s = Slider(self.win, color=color) assert s.line.color == color assert s.tickLines.colors == color for l in s.labelObjs: assert l.color == color
def test_getRating(self): s = Slider(self.win, size=(1, 0.1)) minRating, maxRating = 1, 5 s.rating = 1 assert s.getRating() == minRating s.rating = 5 assert s.getRating() == maxRating s.rating = 0 assert s.getRating() == minRating s.rating = 6 assert s.getRating() == maxRating
def test_reset(self): s = Slider(self.win, size=(1, 0.1)) s.markerPos = 1 s.history = [1] s.rating = 1 s.rt = 1 s.status = constants.STARTED s.reset() assert s.markerPos == None assert s.history == [] assert s.rating == None assert s.rt == None assert s.status == constants.NOT_STARTED
def test_markerPos(self): s = Slider(self.win, size=(1, 0.1)) s._updateMarkerPos = False minPos, maxPos = 1, 5 assert s._updateMarkerPos != True s.markerPos = 1 assert s.markerPos == minPos s.markerPos = 5 assert s.markerPos == maxPos s.markerPos = 0 assert s.markerPos == minPos s.markerPos = 6 assert s.markerPos == maxPos assert s._updateMarkerPos == True
def test_recordRating(self): s = Slider(self.win, size=(1, 0.1)) minRating, maxRating = 1, 5 counter = 0 for rates in range(0, 7): s.recordRating(rates, random.random()) counter += 1 ratings = [rating[0] for rating in s.history] RT = [rt[1] for rt in s.history] assert len(s.history) == counter assert len(ratings) == counter assert min(ratings) == minRating assert max(ratings) == maxRating assert len(RT) == counter assert max(RT) <= 1 assert min(RT) >= 0
def setup_class(self): self.win = Window([128, 128], pos=[50, 50], allowGUI=False, autoLog=False) self.obj = Slider(self.win, units="height", size=(1, 0.1), pos=(0, 0.5), style='radio') self.obj.markerPos = 1 # Pixel which is the border color self.borderPoint = (0, 127) self.borderUsed = True # Pixel which is the fill color self.fillPoint = (0, 0) self.fillUsed = True # Pixel which is the fore color self.forePoint = (0, 0) self.foreUsed = False
def test_change_color(self): s = Slider(self.win, color='black') with pytest.raises(AttributeError): s.color = 'blue'
def test_pos(self): s = Slider(self.win, size=(1, 0.1)) positions = [(.05, .05), (0.2, .2)] for newPos in positions: s.pos = newPos assert array_equal(s.pos, newPos)
def test_elements(self): s = Slider(self.win, size=(1, 0.1)) assert type(s.line) == type(GratingStim(self.win)) assert type(s.tickLines) == type(ElementArrayStim(self.win)) assert type(s.marker) == type(Circle(self.win)) assert type(s.validArea) == type(Rect(self.win))
def test_horiz(self): # Define cases exemplars = [ { 'size': (1, 0.2), 'ori': 0, 'horiz': True, 'tag': 'horiz' }, # Wide slider, no rotation { 'size': (0.2, 1), 'ori': 0, 'horiz': False, 'tag': 'vert' }, # Tall slider, no rotation { 'size': (1, 0.2), 'ori': 90, 'horiz': False, 'tag': 'vert' }, # Wide slider, 90deg rotation { 'size': (0.2, 1), 'ori': 90, 'horiz': True, 'tag': 'horiz' }, # Tall slider, 90deg rotation ] tykes = [ { 'size': (1, 0.2), 'ori': 25, 'horiz': True, 'tag': 'accute_horiz' }, # Wide slider, accute rotation { 'size': (0.2, 1), 'ori': 25, 'horiz': False, 'tag': 'accute_vert' }, # Tall slider, accute rotation { 'size': (1, 0.2), 'ori': 115, 'horiz': False, 'tag': 'obtuse_horiz' }, # Wide slider, obtuse rotation { 'size': (0.2, 1), 'ori': 115, 'horiz': True, 'tag': 'obtuse_vert' }, # Tall slider, obtuse rotation ] # Try each case self.win.flip() for case in exemplars + tykes: # Make sure horiz is set as intended obj = Slider(self.win, labels=["a", "b", "c", "d"], ticks=[1, 2, 3, 4], labelHeight=0.2, labelColor='red', size=case['size'], ori=case['ori']) assert obj.horiz == case['horiz'] # Make sure slider looks as intended obj.draw() filename = f"test_slider_horiz_{case['tag']}.png" # self.win.getMovieFrame(buffer='back').save(Path(utils.TESTS_DATA_PATH) / filename) utils.compareScreenshot(Path(utils.TESTS_DATA_PATH) / filename, self.win, crit=10) self.win.flip()
def test_marker_scaling_factor(self): markerScalingFactors = [1, 1.0] for thisScalingFactor in markerScalingFactors: s = Slider(self.win, markerScalingFactor=thisScalingFactor) assert s.markerScalingFactor == thisScalingFactor
def test_lineLength(self): s = Slider(self.win, size=(1, 0.1)) assert s._lineL == 1
def test_tick_and_label_locs(self): exemplars = [ { 'ticks': [1, 2, 3, 4, 5], 'labels': ["a", "b", "c", "d", "e"], 'tag': "simple" }, { 'ticks': [1, 2, 3, 9, 10], 'labels': ["a", "b", "c", "d", "e"], 'tag': "clustered" }, { 'ticks': [1, 2, 3, 4, 5], 'labels': ["", "b", "c", "d", ""], 'tag': "blanks" }, { 'ticks': None, 'labels': ["a", "b", "c", "d", "e"], 'tag': "noticks" }, { 'ticks': [1, 2, 3, 4, 5], 'labels': None, 'tag': "nolabels" }, ] tykes = [ { 'ticks': [1, 2, 3], 'labels': ["a", "b", "c", "d", "e"], 'tag': "morelabels" }, { 'ticks': [1, 2, 3, 4, 5], 'labels': ["a", "b", "c"], 'tag': "moreticks" }, { 'ticks': [1, 9, 10], 'labels': ["a", "b", "c", "d", "e"], 'tag': "morelabelsclustered" }, { 'ticks': [1, 7, 8, 9, 10], 'labels': ["a", "b", "c", "d"], 'tag': "moreticksclustered" }, ] # Test all cases self.win.flip() for case in exemplars + tykes: # Make vertical slider vert = Slider(self.win, size=(0.1, 0.5), pos=(-0.25, 0), units="height", labels=case['labels'], ticks=case['ticks']) vert.draw() # Make horizontal slider horiz = Slider(self.win, size=(0.5, 0.1), pos=(0.2, 0), units="height", labels=case['labels'], ticks=case['ticks']) horiz.draw() # Compare screenshot filename = "test_slider_ticklabelloc_%(tag)s.png" % case #self.win.getMovieFrame(buffer='back').save(Path(utils.TESTS_DATA_PATH) / filename) utils.compareScreenshot( Path(utils.TESTS_DATA_PATH) / filename, self.win) self.win.flip()
def test_size(self): sizes = [(1, 0.1), (1.5, 0.5)] for size in sizes: s = Slider(self.win, size=size) assert s.size == size
def test_tickWidth(self): s = Slider(self.win, size=(1, 0.1)) assert s._lineW == (1 * s._lineAspectRatio)
def test_change_size(self): s = Slider(self.win, size=(1, 0.1)) with pytest.raises(AttributeError): s.size = (1.5, 0.5)
def test_horiz(self): s = Slider(self.win, size=(1, 0.1)) assert s.horiz == True s = Slider(self.win, size=(0.1, 1)) assert s.horiz == False
def test_change_marker_scaling_factor(self): s = Slider(self.win, markerScalingFactor=1.0) with pytest.raises(AttributeError): s.markerScalingFactor = 0.5
def test_change_color(self): s = Slider(self.win, color='black') s.color = 'blue'