Source code for yyagl.tests.test_computer_proxy

from pathlib import Path
import sys
if '' in sys.path: sys.path.remove('')
sys.path.append(str(Path(__file__).parent.parent.parent))
from unittest.mock import patch, create_autospec
from panda3d.core import loadPrcFileData
from unittest import TestCase
from yyagl.gameobject import GameObject
from yyagl.engine.engine import Engine
from yyagl.computer_proxy import ComputerProxy, compute_once, once_a_frame


[docs]class ExampleProxy(GameObject, ComputerProxy): def __init__(self): GameObject.__init__(self) ComputerProxy.__init__(self) self.reset()
[docs] def reset(self): self.cnt = 0
[docs] @compute_once def inc_cnt(self): self.cnt += 1
[docs] @once_a_frame def inc_cnt_frame(self): self.cnt += 1
[docs]class ComputerProxyTests(TestCase):
[docs] def setUp(self): loadPrcFileData('', 'window-type none') loadPrcFileData('', 'audio-library-name null') self.engine = Engine() self.example_proxy = ExampleProxy()
[docs] def tearDown(self): self.engine.destroy()
[docs] def test_init(self): self.assertIsInstance(self.example_proxy, ExampleProxy)
[docs] def test_compute_once(self): self.example_proxy.reset() self.example_proxy.inc_cnt() self.example_proxy.inc_cnt() self.assertEqual(self.example_proxy.cnt, 1)
[docs] def test_compute_once_a_frame(self): self.example_proxy.reset() self.example_proxy.on_start_frame() self.example_proxy.inc_cnt_frame() self.example_proxy.inc_cnt_frame() self.assertEqual(self.example_proxy.cnt, 1) self.example_proxy.on_start_frame() self.example_proxy.inc_cnt_frame() self.example_proxy.inc_cnt_frame() self.assertEqual(self.example_proxy.cnt, 2)