예제 #1
0
class TestSliceFinderFilter(unittest.TestCase):
    def setUp(self):
        self.gui = GUI(GeistFakeBackend())

    def test_index(self):
        screen = self.gui.capture_locations()[0]
        self.locs = LocationList([Location(0, 0, w=10, h=10, parent=screen),
                                  Location(0, 8, w=10, h=10, parent=screen),
                                  Location(0, 2, w=10, h=10, parent=screen),
                                  Location(6, 8, w=10, h=10, parent=screen)])
        expected = LocationList([Location(0, 0, w=10, h=10, parent=screen),
                                 Location(0, 8, w=10, h=10, parent=screen)])
        finder = SliceFinderFilter(self.locs)
        actual = self.gui.find_all(finder[:2])
        self.assertListEqual(actual, expected)

    def test_slice(self):
        screen = self.gui.capture_locations()[0]
        self.locs = LocationList([Location(0, 0, w=10, h=10, parent=screen),
                                  Location(0, 8, w=10, h=10, parent=screen),
                                  Location(0, 2, w=10, h=10, parent=screen),
                                  Location(6, 8, w=10, h=10, parent=screen)])
        expected = LocationList([Location(0, 0, w=10, h=10, parent=screen),
                                 Location(0, 8, w=10, h=10, parent=screen)])
        finder = SliceFinderFilter(self.locs)
        actual = self.gui.find_all(finder[slice(0, 2)])
        self.assertListEqual(actual, expected)
예제 #2
0
class TestViewer(unittest.TestCase):
    def setUp(self):
        self.repo = DirectoryRepo('test_repo')
        self.gui = GUI(GeistFakeBackend(image=np.array([[[255,0,0],[240,10,10],[0,255,0],[0,0,255]]])))
        self.V = Viewer(self.gui, self.repo)
        self.screen = self.gui.capture_locations()[0]
        self.red = np.array([[[255,0,0]]])
        self.more_reds = np.array([[[255,0,0],[240,10,10]]])


    def test_get_colour(self):
        red = self.V._get_colour(self.red)
        result = self.gui.find_all(BinaryRegionFinder(red))
        expected = [Location(0,0, w=1, h=1, parent=self.screen)]
        self.assertListEqual(result, expected)


    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=1, parent=self.screen)]
        self.assertListEqual(result, expected)


    def test_save(self):
        self.V._save('test_file', np.array([0]))
        self.assertIn('test_file', self.repo.entries)


    def test_save_overwrite(self):
        self.V._save('test_file', np.array([0]))
        with self.assertRaises(KeyError):
            self.V._save('test_file', np.array([1]))


    def test_save_force(self):
        self.V._save('test_file', np.array([0]))
        self.V._save('test_file', np.array([1]), force=True)
        self.assertEqual(self.repo['test_file'].image, np.array([1]))


    def tearDown(self):
        if 'test_file' in self.repo.entries:
            del self.repo['test_file']
예제 #3
0
class TestViewer(unittest.TestCase):
    def setUp(self):
        self.repo = DirectoryRepo('test_repo')
        self.gui = GUI(
            GeistFakeBackend(image=np.array(
                [[[255, 0, 0], [240, 10, 10], [0, 255, 0], [0, 0, 255]],
                 [[255, 0, 0], [240, 10, 10], [0, 255, 0], [0, 0, 255]],
                 [[255, 0, 0], [240, 10, 10], [0, 255, 0], [0, 0, 255]],
                 [[255, 0, 0], [240, 10, 10], [0, 255, 0], [0, 0, 255]]])))
        self.V = Viewer(self.gui, self.repo)
        self.screen = self.gui.capture_locations()[0]
        self.red = np.array([[[255, 0, 0]]])
        self.more_reds = np.array([[[255, 0, 0], [240, 10, 10]]])

    def test_get_colour(self):
        red = self.V._get_colour(self.red)
        result = self.gui.find_all(BinaryRegionFinder(red))
        expected = [Location(0, 0, w=1, h=4, parent=self.screen)]
        self.assertListEqual(result, expected)

    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 test_save(self):
        self.V._save('test_file', np.array([0]))
        self.assertIn('test_file', self.repo.entries)

    def test_save_overwrite(self):
        self.V._save('test_file', np.array([0]))
        with self.assertRaises(KeyError):
            self.V._save('test_file', np.array([1]))

    def test_save_force(self):
        self.V._save('test_file', np.array([0]))
        self.V._save('test_file', np.array([1]), force=True)
        self.assertEqual(self.repo['test_file'].image, np.array([1]))

    def tearDown(self):
        if 'test_file' in self.repo.entries:
            del self.repo['test_file']
예제 #4
0
파일: test_viewer.py 프로젝트: bibi-L/Geist
class TestViewer(unittest.TestCase):
    def setUp(self):
        self.repo = DirectoryRepo('test_repo')
        self.gui = GUI(GeistFakeBackend(image=np.array([[[255,0,0],[240,10,10],[0,255,0],[0,0,255]]])))
        self.V = Viewer(self.gui, self.repo)
        self.screen = self.gui.capture_locations()[0]
        self.red = np.array([[[255,0,0]]])
        self.more_reds = np.array([[[255,0,0],[240,10,10]]])
    
    
    def test_get_colour(self):
        red = self.V._get_colour(self.red)
        result = self.gui.find_all(BinaryRegionFinder(red))
        expected = [Location(0,0, w=1, h=1, parent=self.screen)]
        self.assertListEqual(result, expected)
    
    
    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=1, parent=self.screen)]
        self.assertListEqual(result, expected)
예제 #5
0
class TestSortingFinder(unittest.TestCase):
    def setUp(self):
        self.gui = GUI(GeistFakeBackend())

    def test_sort(self):
        screen = self.gui.capture_locations()[0]
        self.locs = LocationList([Location(0, 0, w=10, h=10, parent=screen),
                                  Location(0, 8, w=10, h=10, parent=screen),
                                  Location(0, 2, w=10, h=10, parent=screen),
                                  Location(6, 8, w=10, h=10, parent=screen)])
        self.key = lambda loc: loc.y
        expected = sorted(self.locs, key=self.key)
        finder = SortingFinder(self.locs, key=self.key)
        actual = self.gui.find_all(finder)
        self.assertListEqual(actual, expected)
예제 #6
0
class TestLocationFinderFilter(unittest.TestCase):
    def setUp(self):
        self.gui = GUI(GeistFakeBackend())

    def test_filter(self):
        screen = self.gui.capture_locations()[0]
        self.locs = LocationList([Location(0, 0, w=10, h=10, parent=screen),
                                  Location(0, 8, w=10, h=10, parent=screen),
                                  Location(0, 2, w=10, h=10, parent=screen),
                                  Location(6, 8, w=10, h=10, parent=screen)])
        filter = lambda loc: loc.y == 8
        expected = LocationList([Location(0, 8, w=10, h=10, parent=screen),
                                 Location(6, 8, w=10, h=10, parent=screen)])
        finder = LocationFinderFilter(filter, self.locs)
        actual = self.gui.find_all(finder)
        self.assertListEqual(actual, expected)
예제 #7
0
class TestOperators(unittest.TestCase):
    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_below(self):
        expected = LocationList([
            Location(0, 24, w=5, h=5, parent=self.screen),
            Location(22, 24, w=5, h=5, parent=self.screen)
        ])
        finder = LocationOperatorFinder(LocationList(self.locs_b), below,
                                        self.locs_a)
        actual = self.gui.find_all(finder)
        self.assertListEqual(actual, expected)

    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_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 test_and(self):
        below_and_left = below & left_of
        expected = [Location(0, 24, w=5, h=5, parent=self.screen)]
        finder = LocationOperatorFinder(self.locs_b, below_and_left,
                                        self.locs_a)
        actual = self.gui.find_all(finder)
        self.assertListEqual(actual, expected)

    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_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)
예제 #8
0
class TestOperators(unittest.TestCase):
    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_below(self):
        expected = LocationList([
            Location(0, 24, w=5, h=5, parent=self.screen),
            Location(22, 24, w=5, h=5, parent=self.screen)])
        finder = LocationOperatorFinder(LocationList(self.locs_b), below,
                                        self.locs_a)
        actual = self.gui.find_all(finder)
        self.assertListEqual(actual, expected)

    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_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 test_and(self):
        below_and_left = below & left_of
        expected = [Location(0, 24, w=5, h=5, parent=self.screen)]
        finder = LocationOperatorFinder(self.locs_b, below_and_left,
                                        self.locs_a)
        actual = self.gui.find_all(finder)
        self.assertListEqual(actual, expected)

    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_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)