Exemplo n.º 1
0
 def setUp(self):
     """
     Record all open windows
     :return:
     """
     self.ahk = AsyncAHK()
     self.before_windows = asyncio.run(self.ahk.windows())
     im = Image.new('RGB', (20, 20))
     for coord in product(range(20), range(20)):
         im.putpixel(coord, (255, 0, 0))
     self.im = im
     im.show()
     time.sleep(2)
Exemplo n.º 2
0
class TestWinGetAsync(IsolatedAsyncioTestCase):
    def setUp(self):
        self.ahk = AsyncAHK()
        self.p = subprocess.Popen('notepad')
        time.sleep(1)
        self.win = asyncio.run(self.ahk.win_get(title='Untitled - Notepad'))
        self.assertIsNotNone(self.win)

    def tearDown(self):
        self.p.terminate()
        asyncio.run(asyncio.sleep(0.5))

    async def test_get_calculator(self):
        assert await self.win.position

    async def a_win_get(self):
        win = await self.ahk.win_get(title='Untitled - Notepad')
        await win.position

    def test_win_close(self):
        asyncio.run(self.win.close())
        self.assertRaises(WindowNotFoundError, asyncio.run, self.a_win_get())

    async def test_find_window_func(self):
        async def func(win):
            return b'Untitled' in await win.title

        assert self.win == await self.ahk.find_window(func=func)

    async def test_getattr_window_subcommand(self):
        assert isinstance(await self.win.pid, str)
Exemplo n.º 3
0
class TestScreen(IsolatedAsyncioTestCase):
    def setUp(self):
        """
        Record all open windows
        :return:
        """
        self.ahk = AsyncAHK()
        self.before_windows = asyncio.run(self.ahk.windows())
        im = Image.new('RGB', (20, 20))
        for coord in product(range(20), range(20)):
            im.putpixel(coord, (255, 0, 0))
        self.im = im
        im.show()
        time.sleep(2)

    async def asyncTearDown(self):
        for win in await self.ahk.windows():
            if win not in self.before_windows:
                await win.close()
                break

    async def test_pixel_search(self):
        result = await self.ahk.pixel_search(0xFF0000)
        self.assertIsNotNone(result)

    async def test_image_search(self):
        self.im.save('testimage.png')
        position = await self.ahk.image_search('testimage.png')
        self.assertIsNotNone(position)

    async def test_pixel_get_color(self):
        x, y = await self.ahk.pixel_search(0xFF0000)
        result = await self.ahk.pixel_get_color(x, y)
        self.assertIsNotNone(result)
        self.assertEqual(int(result, 16), 0xFF0000)
Exemplo n.º 4
0
 def setUp(self):
     """
     Record all open windows
     :return:
     """
     self.ahk = AsyncAHK()
     # self._normal_ahk = AHK()
     # self.before_windows = self._normal_ahk.windows()
     self.p = subprocess.Popen('notepad')
     time.sleep(1)
Exemplo n.º 5
0
 def setUp(self):
     self.ahk = AsyncAHK()
     self.p = subprocess.Popen('notepad')
     time.sleep(1)
     self.win = asyncio.run(self.ahk.win_get(title='Untitled - Notepad'))
     self.assertIsNotNone(self.win)
Exemplo n.º 6
0
class TestWindowAsync(IsolatedAsyncioTestCase):
    win: AsyncWindow

    def setUp(self):
        self.ahk = AsyncAHK()
        self.p = subprocess.Popen('notepad')
        time.sleep(1)
        self.win = asyncio.run(self.ahk.win_get(title='Untitled - Notepad'))
        self.assertIsNotNone(self.win)

    async def a_transparent(self):
        self.assertEqual(await self.win.get_transparency(), 255)

        await self.win.set_transparency(220)
        self.assertEqual(await self.win.get_transparency(), 220)

        self.win.transparent = 255
        await asyncio.sleep(0.5)
        self.assertEqual(await self.win.transparent, 255)

    def test_transparent(self):
        asyncio.run(self.a_transparent())

    #
    def test_pinned(self):
        asyncio.run(self.a_pinned())

    async def a_pinned(self):
        self.assertFalse(await self.win.always_on_top)

        await self.win.set_always_on_top(True)
        self.assertTrue(await self.win.is_always_on_top())

        self.win.always_on_top = False
        await asyncio.sleep(1)
        self.assertFalse(await self.win.always_on_top)

    async def test_close(self):
        await self.win.close()
        await asyncio.sleep(0.2)
        self.assertFalse(await self.win.exists())
        self.assertFalse(await self.win.exist)

    async def test_show_hide(self):
        await self.win.hide()
        await asyncio.sleep(0.5)
        self.assertFalse(await self.win.exist)

        await self.win.show()
        await asyncio.sleep(0.5)
        self.assertTrue(await self.win.exist)

    async def test_kill(self):
        await self.win.kill()
        await asyncio.sleep(0.5)
        self.assertFalse(await self.win.exist)

    async def test_max_min(self):
        self.assertTrue(await self.win.non_max_non_min)
        self.assertFalse(await self.win.is_minmax())

        await self.win.maximize()
        await asyncio.sleep(1)
        self.assertTrue(await self.win.maximized)
        self.assertTrue(await self.win.is_maximized())

        await self.win.minimize()
        await asyncio.sleep(1)
        self.assertTrue(await self.win.minimized)
        self.assertTrue(await self.win.is_minimized())

        await self.win.restore()
        await asyncio.sleep(0.5)
        self.assertTrue(await self.win.maximized)
        self.assertTrue(await self.win.is_maximized())

    #
    async def test_names(self):
        self.assertEqual(await self.win.class_name, b'Notepad')
        self.assertEqual(await self.win.get_class_name(), b'Notepad')

        self.assertEqual(await self.win.title, b'Untitled - Notepad')
        self.assertEqual(await self.win.get_title(), b'Untitled - Notepad')

        self.assertEqual(await self.win.text, b'')
        self.assertEqual(await self.win.get_text(), b'')

    async def test_title_setter(self):
        starting_title = await self.win.title

        await self.win.set_title('new title')
        assert await self.win.get_title() != starting_title

    async def test_find_window(self):
        win = await self.ahk.find_window(title=b'Untitled - Notepad')
        assert win.id == self.win.id

    async def test_find_window_nonexistent_is_none(self):
        win = await self.ahk.find_window(title=b'This should not exist')
        assert win is None

    async def test_winget_nonexistent_window_is_none(self):
        win = await self.ahk.win_get(title='This should not exist')
        assert win is None

    async def test_winwait_nonexistent_raises_timeout_error(self):
        with pytest.raises(TimeoutError):
            win = await self.ahk.win_wait(title='This should not exist')

    async def test_winwait_existing_window(self):
        win = await self.ahk.win_wait(title='Untitled - Notepad')
        assert win.id == self.win.id

    def tearDown(self):
        self.p.terminate()
        asyncio.run(asyncio.sleep(0.5))
Exemplo n.º 7
0
 def setUp(self) -> None:
     self.ahk = AsyncAHK()
Exemplo n.º 8
0
 def setUp(self):
     self.ahk = AsyncAHK()
     self._normal_ahk = AHK()
     self.thread = None
     self.hotkey = None