<commit_before>import unittest
from geist import Location, LocationList, GUI, LocationOperatorFinder
from geist.backends.fake import GeistFakeBackend
from geist.layoutfinders import below, left_of
from tests import logger as base_logger

logger = base_logger.getChild('operators')


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


operator_suite = unittest.TestLoader().loadTestsFromTestCase(TestOperators)
all_tests = unittest.TestSuite([operator_suite])<commit_msg>Add tests for some operators<commit_after>import unittest
from geist import Location, LocationList, GUI, LocationOperatorFinder
from geist.backends.fake import GeistFakeBackend
from geist.layoutfinders import below, left_of, right_of
from tests import logger as base_logger

logger = base_logger.getChild('operators')


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)


operator_suite = unittest.TestLoader().loadTestsFromTestCase(TestOperators)
all_tests = unittest.TestSuite([operator_suite])
{'fraction_non_alphanumeric': 0.11590296495956873, 'fraction_numerical': 0.025696316262354, 'mean_word_length': 2.4358024691358025, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1038733', 'n_tokens_mistral': 1798, 'n_tokens_neox': 1711, 'n_words': 346}