test_share.py 993B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # coding: utf-8
  2. from synergine2.share import SharedDataManager
  3. from tests import BaseTest
  4. class TestShare(BaseTest):
  5. def test_simple_share_with_class(self):
  6. shared = SharedDataManager()
  7. class Foo(object):
  8. counter = shared.create('counter', 0)
  9. foo = Foo()
  10. foo.counter = 42
  11. assert shared.get('counter') == 42
  12. foo.counter = 48
  13. assert shared.get('counter') == 48
  14. def test_dynamic_key(self):
  15. shared = SharedDataManager()
  16. class Foo(object):
  17. counter = shared.create(
  18. '{id}_counter',
  19. (0, 0, 0),
  20. indexes=[],
  21. )
  22. @property
  23. def id(self):
  24. return id(self)
  25. foo = Foo()
  26. foo.counter = 42
  27. assert shared.get('{}_counter'.format(foo.id)) == 42
  28. foo.counter = 48
  29. assert shared.get('{}_counter'.format(foo.id)) == 48
  30. def test_indexes(self):
  31. pass