Esempio n. 1
0
    def test_reversi__end(self):
        class TestWindow:
            def __init__(self):
                class Start:
                    def __init__(self):
                        class Event:
                            def is_set(self):
                                return True

                            def clear(self):
                                print('clear')

                        self.event = Event()

                self.start = Start()

            def set_state(self, state):
                print(state)

        app = Reversi()
        app.window = TestWindow()

        # REINIT
        app._setting_changed = lambda: False

        with captured_stdout() as stdout:
            app._Reversi__end()

        lines = stdout.getvalue().splitlines()
        self.assertEqual(lines[0], 'normal')
        self.assertEqual(lines[1], 'clear')

        with self.assertRaises(IndexError):
            print(lines[2])

        self.assertEqual(app.state, Reversi.REINIT)

        # INIT
        app.window.start.event.is_set = lambda: False
        app._setting_changed = lambda: True

        with captured_stdout() as stdout:
            app._Reversi__end()

        lines = stdout.getvalue().splitlines()
        self.assertEqual(lines[0], 'normal')

        with self.assertRaises(IndexError):
            print(lines[1])

        self.assertEqual(app.state, Reversi.INIT)
Esempio n. 2
0
    def test_reversi_setting_changed(self):
        class TestWindow:
            def __init__(self):
                class Menu:
                    def __init__(self):
                        class Event:
                            def is_set(self):
                                return False

                            def clear(self):
                                print('clear')

                        self.event = Event()
                        self.size = 8
                        self.black_player = 'BLACK2'
                        self.white_player = 'WHITE2'
                        self.assist = True
                        self.language = 'Japanese'

                self.menu = Menu()

                self.size = 4
                self.player = {'black': 'BLACK', 'white': 'WHITE'}
                self.assist = False
                self.language = 'English'

        app = Reversi()
        app.window = TestWindow()

        # return False
        with captured_stdout() as stdout:
            ret = app._setting_changed()

        lines = stdout.getvalue().splitlines()

        with self.assertRaises(IndexError):
            print(lines[0])

        self.assertEqual(app.window.size, 4)
        self.assertEqual(app.window.player['black'], 'BLACK')
        self.assertEqual(app.window.player['white'], 'WHITE')
        self.assertEqual(app.window.assist, False)
        self.assertEqual(app.window.language, 'English')
        self.assertEqual(ret, False)

        # return True
        app.window.menu.event.is_set = lambda: True

        with captured_stdout() as stdout:
            ret = app._setting_changed()

        lines = stdout.getvalue().splitlines()
        self.assertEqual(lines[0], 'clear')

        with self.assertRaises(IndexError):
            print(lines[1])

        self.assertEqual(app.window.size, 8)
        self.assertEqual(app.window.player['black'], 'BLACK2')
        self.assertEqual(app.window.player['white'], 'WHITE2')
        self.assertEqual(app.window.assist, True)
        self.assertEqual(app.window.language, 'Japanese')
        self.assertEqual(ret, True)
Esempio n. 3
0
    def test_reversi_demo_animation(self):
        class TestWindow:
            def __init__(self):
                class Board:
                    def __init__(self):
                        self.size = 8

                    def remove_disc(self, color, x, y):
                        print('remove_disc', color, x, y)

                    def put_disc(self, color, x, y):
                        print('put_disc', color, x, y)

                self.board = Board()

        app = Reversi(turn_disc_wait=0.001)
        app.window = TestWindow()

        # setting_changed Falase
        app._setting_changed = lambda: False
        with captured_stdout() as stdout:
            ret = app._demo_animation()

        lines = stdout.getvalue().splitlines()

        self.assertEqual(lines[0], 'remove_disc black 4 3')
        self.assertEqual(lines[1], 'put_disc turnblack 4 3')
        self.assertEqual(lines[2], 'remove_disc turnblack 4 3')
        self.assertEqual(lines[3], 'put_disc white 4 3')
        self.assertEqual(lines[4], 'remove_disc white 4 3')
        self.assertEqual(lines[5], 'put_disc turnwhite 4 3')
        self.assertEqual(lines[6], 'remove_disc turnwhite 4 3')
        self.assertEqual(lines[7], 'put_disc black 4 3')
        self.assertEqual(lines[8], 'remove_disc black 3 4')
        self.assertEqual(lines[9], 'put_disc turnblack 3 4')
        self.assertEqual(lines[10], 'remove_disc turnblack 3 4')
        self.assertEqual(lines[11], 'put_disc white 3 4')
        self.assertEqual(lines[12], 'remove_disc white 3 4')
        self.assertEqual(lines[13], 'put_disc turnwhite 3 4')
        self.assertEqual(lines[14], 'remove_disc turnwhite 3 4')
        self.assertEqual(lines[15], 'put_disc black 3 4')
        self.assertEqual(lines[16], 'remove_disc white 3 3')
        self.assertEqual(lines[17], 'put_disc turnwhite 3 3')
        self.assertEqual(lines[18], 'remove_disc turnwhite 3 3')
        self.assertEqual(lines[19], 'put_disc black 3 3')
        self.assertEqual(lines[20], 'remove_disc black 3 3')
        self.assertEqual(lines[21], 'put_disc turnblack 3 3')
        self.assertEqual(lines[22], 'remove_disc turnblack 3 3')
        self.assertEqual(lines[23], 'put_disc white 3 3')
        self.assertEqual(lines[24], 'remove_disc white 4 4')
        self.assertEqual(lines[25], 'put_disc turnwhite 4 4')
        self.assertEqual(lines[26], 'remove_disc turnwhite 4 4')
        self.assertEqual(lines[27], 'put_disc black 4 4')
        self.assertEqual(lines[28], 'remove_disc black 4 4')
        self.assertEqual(lines[29], 'put_disc turnblack 4 4')
        self.assertEqual(lines[30], 'remove_disc turnblack 4 4')
        self.assertEqual(lines[31], 'put_disc white 4 4')

        with self.assertRaises(IndexError):
            print(lines[32])

        self.assertEqual(ret, True)

        # setting_changed True
        app._setting_changed = lambda: True
        with captured_stdout() as stdout:
            ret = app._demo_animation()

        lines = stdout.getvalue().splitlines()

        with self.assertRaises(IndexError):
            print(lines[0])

        self.assertEqual(ret, False)