Example #1
0
 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()
Example #2
0
 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()