Example #1
0
	def read(self,frame):
		self.visitor=Visitor()
		frame.GetSource(self.visitor)
		self.logger.debug("read str.....")
		if self.l==1:
			t=RepeatableTimer(2,self.loop)
			t.start()
		print("read"+str(self.l))
Example #2
0
class TestGUI(TestCase):
    def setUp(self):
        self.timer = RepeatableTimer(0.3)
        self.gui = FakeGUI(Subject(), self.timer)

    def tearDown(self):
        self.timer.stop()

    def test_start_button_onclick(self):
        with mock.patch('RepeatableTimer.RepeatableTimer.start') as mock_start:
            self.gui.start_button_onclick()
            self.assertEqual(self.gui.start_button['state'], 'disabled',
                             'button should be disabled')
            mock_start.assert_called_once_with()

    def test_update(self):
        self.gui.update(round=3, map=[[1]])
        label_text = self.gui.round_label['text']
        round_now = int(label_text[(label_text.index(':') + 1)])
        self.assertEqual(round_now, 3, 'Should update round')

    def test_draw(self):
        with mock.patch(
                'tkinter.Canvas.create_rectangle') as mock_create_rectangle:
            self.gui.draw([
                [1, 0, 1, 1],
                [0, 0, 1, 1],
                [0, 1, 1, 1],
                [0, 0, 0, 1],
            ])

            calls = [
                mock.call(0, 0, 360.0, 360.0, outline='white', fill='white')
            ]

            calls_pos = [
                [0, 0, 89, 89],
                [180, 0, 269, 89],
                [270, 0, 359, 89],
                [180, 90, 269, 179],
                [270, 90, 359, 179],
                [90, 180, 179, 269],
                [180, 180, 269, 269],
                [270, 180, 359, 269],
                [270, 270, 359, 359],
            ]

            calls += list(
                map(lambda x: mock.call(*x, outline='white', fill='black'),
                    calls_pos))

            mock_create_rectangle.assert_has_calls(calls)
class TestGUI(TestCase):
    def setUp(self):
        self.timer = RepeatableTimer(0.3)
        self.gui = FakeGUI(Subject(), self.timer)

    def tearDown(self):
        self.timer.stop()

    def test_start_button_onclick(self):
        with mock.patch('RepeatableTimer.RepeatableTimer.start') as mock_start:
            self.gui.start_button_onclick()
            self.assertEqual(self.gui.start_button['state'],
                             'disabled', 'button should be disabled')
            mock_start.assert_called_once_with()

    def test_update(self):
        self.gui.update(round=3, map=[[1]])
        label_text = self.gui.round_label['text']
        round_now = int(label_text[(label_text.index(':') + 1)])
        self.assertEqual(round_now, 3, 'Should update round')

    def test_draw(self):
        with mock.patch('tkinter.Canvas.create_rectangle') as mock_create_rectangle:
            self.gui.draw([
                [1, 0, 1, 1],
                [0, 0, 1, 1],
                [0, 1, 1, 1],
                [0, 0, 0, 1],
            ])

            calls = [mock.call(0, 0, 360.0, 360.0, outline='white', fill='white')]

            calls_pos = [
                [0, 0, 89, 89],
                [180, 0, 269, 89],
                [270, 0, 359, 89],
                [180, 90, 269, 179],
                [270, 90, 359, 179],
                [90, 180, 179, 269],
                [180, 180, 269, 269],
                [270, 180, 359, 269],
                [270, 270, 359, 359],
            ]

            calls += list(map(lambda x: mock.call(*x, outline='white', fill='black'),
                              calls_pos))

            mock_create_rectangle.assert_has_calls(calls)
 def setUp(self):
     self.timer = RepeatableTimer(0.3)
     self.gui = FakeGUI(Subject(), self.timer)
Example #5
0
 def setUp(self):
     self.timer = RepeatableTimer(0.3)
     self.gui = FakeGUI(Subject(), self.timer)
Example #6
0
def main():
    timer = RepeatableTimer(0.3)
    model = Model(timer)
    GUI(model, timer)