123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- # coding: utf-8
- import pytest
-
- from synergine2.exceptions import UnknownSharedData
- from synergine2.share import SharedDataManager
- from tests import BaseTest
-
-
- class TestShare(BaseTest):
- def test_simple_share_with_class(self):
- shared = SharedDataManager()
-
- class Foo(object):
- counter = shared.create('counter', 0)
-
- foo = Foo()
- foo.counter = 42
-
- assert shared.get('counter') == 42
-
- foo.counter = 48
-
- assert shared.get('counter') == 48
-
- def test_dynamic_key(self):
- shared = SharedDataManager()
-
- class Foo(object):
- counter = shared.create(
- '{id}_counter',
- (0, 0, 0),
- indexes=[],
- )
-
- @property
- def id(self):
- return id(self)
-
- foo = Foo()
- foo.counter = 42
-
- assert shared.get('{}_counter'.format(foo.id)) == 42
-
- foo.counter = 48
-
- assert shared.get('{}_counter'.format(foo.id)) == 48
-
- def test_update_dict_with_pointer(self):
- shared = SharedDataManager()
-
- class Foo(object):
- data = shared.create('data', {})
-
- foo = Foo()
- foo.data = {'foo': 'bar'}
-
- assert shared.get('data') == {'foo': 'bar'}
-
- foo.data['foo'] = 'buz'
- assert shared.get('data') == {'foo': 'buz'}
-
- def test_refresh_without_commit(self):
- shared = SharedDataManager()
-
- class Foo(object):
- counter = shared.create('counter', 0)
-
- foo = Foo()
- foo.counter = 42
-
- assert shared.get('counter') == 42
-
- shared.refresh()
- with pytest.raises(UnknownSharedData):
- shared.get('counter')
-
- def test_commit(self):
- shared = SharedDataManager()
-
- class Foo(object):
- counter = shared.create('counter', 0)
-
- foo = Foo()
- foo.counter = 42
-
- assert shared.get('counter') == 42
-
- shared.commit()
- assert shared.get('counter') == 42
-
- def test_commit_then_refresh(self):
- shared = SharedDataManager()
-
- class Foo(object):
- counter = shared.create('counter', 0)
-
- foo = Foo()
- foo.counter = 42
-
- assert shared.get('counter') == 42
-
- shared.commit()
- shared.refresh()
- assert shared.get('counter') == 42
-
- def test_indexes(self):
- pass
|