def test_mouse_drag_x_dir(self): self.gui.drag(Location(200, 200), Location(0, 200)) positions = [(0, 200), (0, 200), (50, 200), (100, 200), (150, 200), (200, 200)] self.assertEquals(sorted(positions), sorted(self.backend.list_of_points)) self.assertTrue(self.backend.button_down_pressed) self.assertTrue(self.backend.button_up_pressed)
def test_mouse_drag_equal_dirs(self): self.gui.drag(Location(200, 200), Location(400, 400)) positions = [(200, 200), (240, 240), (280, 280), (320, 320), (360, 360), (400, 400), (400, 400)] self.assertEquals(sorted(positions), sorted(self.backend.list_of_points)) self.assertTrue(self.backend.button_down_pressed) self.assertTrue(self.backend.button_up_pressed)
def test_filter(self): in_location = self.gui.wait_find_one(Location(10, 10, 100, 100)) parent_x, parent_y = 40, 50 child_x, child_y = 100, 17 finder = FinderInFinder(Location(child_x, child_y, 100, 100), Location(parent_x, parent_y, 500, 500)) result = self.gui.wait_find_one(finder) self.assertEqual(parent_x + child_x, result.x) self.assertEqual(parent_y + child_y, result.y)
def test_invert(self): not_below = ~below expected = [ Location(0, 2, w=5, h=5, parent=self.screen), Location(22, 2, w=5, h=5, parent=self.screen) ] finder = LocationOperatorFinder(self.locs_b, not_below, self.locs_a) actual = self.gui.find_all(finder) self.assertListEqual(actual, expected)
def test_mouse_move_increment(self): self.gui.drag(Location(200, 200), Location(400, 400), mouse_move_increment=100) positions = [(200, 200), (300, 300), (400, 400), (400, 400)] self.assertEquals(sorted(positions), sorted(self.backend.list_of_points)) self.assertTrue(self.backend.button_down_pressed) self.assertTrue(self.backend.button_up_pressed)
def test_left_of(self): expected = LocationList([ Location(0, 2, w=5, h=5, parent=self.screen), Location(0, 24, w=5, h=5, parent=self.screen) ]) finder = LocationOperatorFinder(LocationList(self.locs_b), left_of, self.locs_a) actual = self.gui.find_all(finder) self.assertListEqual(actual, expected)
def test_mouse_works(self): capture_file = os.path.join(_DIR, 'test_mouse_works.log') backend = RecordingBackend(source_backend=GeistFakeBackend(), recording_filename=capture_file) gui = GUI(backend) gui.click(Location(10, 10)) backend = PlaybackBackend(recording_filename=capture_file) gui = GUI(backend) gui.click(Location(10, 10))
def test_right_of(self): self.maxDiff = None expected = LocationList([ Location(22, 2, w=5, h=5, parent=self.screen), Location(22, 24, w=5, h=5, parent=self.screen), ]) finder = LocationOperatorFinder(LocationList(self.locs_b), right_of, self.locs_a) actual = self.gui.find_all(finder) self.assertListEqual(actual, expected)
def setUp(self): self.gui = GUI(GeistFakeBackend()) self.screen = self.gui.capture_locations()[0] self.locs_a = LocationList( [Location(10, 13, w=5, h=5, parent=self.screen)]) self.locs_b = LocationList([ Location(0, 2, w=5, h=5, parent=self.screen), Location(0, 24, w=5, h=5, parent=self.screen), Location(22, 2, w=5, h=5, parent=self.screen), Location(22, 24, w=5, h=5, parent=self.screen) ])
def test_or(self): below_or_left = below | left_of expected = [ Location(0, 2, w=5, h=5, parent=self.screen), Location(0, 24, w=5, h=5, parent=self.screen), Location(22, 24, w=5, h=5, parent=self.screen) ] finder = LocationOperatorFinder(self.locs_b, below_or_left, self.locs_a) actual = self.gui.find_all(finder) self.assertListEqual(actual, expected)
def test_mouse_drag_y_dir(self): self.gui.drag(Location(200, 200), Location(201, 900)) # this overshoots on y then goes back, not ideal!! positions = [ (200, 200), (200, 250), (200, 300), (200, 350), (200, 400), (200, 450), (200, 500), (200, 550), (200, 600), (200, 650), (200, 700), (200, 750), (200, 800), (200, 850), (201, 900), (201, 900) ] self.assertEquals(sorted(positions), sorted(self.backend.list_of_points)) self.assertTrue(self.backend.button_down_pressed) self.assertTrue(self.backend.button_up_pressed)
def test_LocationChangeFinder(self): finder = LocationChangeFinder(self.location) new_location_image = np.array([[[0], [0]], [[0], [0]]]) new_location = Location(0, 0, 2, 2, image=new_location_image) location_found = list(finder.find(new_location))[0] self.assertTrue( np.array_equal(location_found.image, new_location.image))
def test_get_colour_range(self): reds = self.V._get_colour(self.more_reds) result = self.gui.find_all(BinaryRegionFinder(reds)) expected = [Location(0, 0, w=2, h=4, parent=self.screen)] self.assertListEqual(result, expected)
def setUp(self): # typically images are rgb, and fake backend expects this self.location_image = np.array([[[1], [1]], [[1], [1]]], dtype=int) self.location = Location(0, 0, 2, 2, image=self.location_image)