本文整理汇总了Python中shinysdr.values.LooseCell.set方法的典型用法代码示例。如果您正苦于以下问题:Python LooseCell.set方法的具体用法?Python LooseCell.set怎么用?Python LooseCell.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shinysdr.values.LooseCell
的用法示例。
在下文中一共展示了LooseCell.set方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestViewCell
# 需要导入模块: from shinysdr.values import LooseCell [as 别名]
# 或者: from shinysdr.values.LooseCell import set [as 别名]
class TestViewCell(unittest.TestCase):
def setUp(self):
self.lc = LooseCell(value=0, key='a', type=int)
self.vc = ViewCell(
base=self.lc,
get_transform=lambda x: x + 1,
set_transform=lambda x: x - 1,
key='b',
type=int)
def test_get_set(self):
self.assertEqual(0, self.lc.get())
self.assertEqual(1, self.vc.get())
self.vc.set(2)
self.assertEqual(1, self.lc.get())
self.assertEqual(2, self.vc.get())
self.lc.set(3)
self.assertEqual(3, self.lc.get())
self.assertEqual(4, self.vc.get())
def test_subscription(self):
fired = []
def f():
fired.append(self.vc.get())
self.vc.subscribe(f)
self.lc.set(1)
self.assertEqual([2], fired)
示例2: TestLooseCell
# 需要导入模块: from shinysdr.values import LooseCell [as 别名]
# 或者: from shinysdr.values.LooseCell import set [as 别名]
class TestLooseCell(unittest.TestCase):
def setUp(self):
self.lc = LooseCell(value=0, key='a', type=int)
def test_get_set(self):
self.assertEqual(0, self.lc.get())
self.lc.set(1)
self.assertEqual(1, self.lc.get())
self.lc.set(2.1)
self.assertEqual(2, self.lc.get())
def test_subscription(self):
st = CellSubscriptionTester(self.lc)
self.lc.set(1)
st.expect_now(1)
st.unsubscribe()
self.lc.set(2)
st.advance() # check for unwanted callbacks
示例3: TestLooseCell
# 需要导入模块: from shinysdr.values import LooseCell [as 别名]
# 或者: from shinysdr.values.LooseCell import set [as 别名]
class TestLooseCell(unittest.TestCase):
def setUp(self):
self.lc = LooseCell(
value=0,
type=int,
writable=True,
interest_tracker=LoopbackInterestTracker())
def test_get_set(self):
self.assertEqual(0, self.lc.get())
self.lc.set(1)
self.assertEqual(1, self.lc.get())
self.lc.set(2.1)
self.assertEqual(2, self.lc.get())
def test_subscription(self):
st = CellSubscriptionTester(self.lc)
self.lc.set(1)
st.expect_now(1)
st.unsubscribe()
self.lc.set(2)
st.advance() # check for unwanted callbacks
def test_repr(self):
if six.PY2:
self.assertEqual(repr(self.lc), '<LooseCell PythonT(<type \'int\'>) 0>')
else:
self.assertEqual(repr(self.lc), '<LooseCell PythonT(<class \'int\'>) 0>')
def test_default_writability(self):
self.assertFalse(LooseCell(value=0, type=int).isWritable())
def test_not_writable(self):
self.lc = LooseCell(value=0, type=int, writable=False)
self.assertRaises(Exception, lambda:
self.lc.set(1))
self.assertEqual(self.lc.get(), 0)
示例4: TestViewCell
# 需要导入模块: from shinysdr.values import LooseCell [as 别名]
# 或者: from shinysdr.values.LooseCell import set [as 别名]
class TestViewCell(unittest.TestCase):
def setUp(self):
self.lc = LooseCell(value=0, type=RangeT([(-100, 100)]), writable=True)
self.delta = 1
self.vc = ViewCell(
base=self.lc,
get_transform=lambda x: x + self.delta,
set_transform=lambda x: x - self.delta,
type=int,
writable=True,
interest_tracker=LoopbackInterestTracker())
# TODO: Add tests for behavior when the transform is not perfectly one-to-one (such as due to floating-point error).
# TODO: Test propagation of interest
def test_get_set(self):
self.assertEqual(0, self.lc.get())
self.assertEqual(1, self.vc.get())
self.vc.set(2)
self.assertEqual(1, self.lc.get())
self.assertEqual(2, self.vc.get())
self.lc.set(3)
self.assertEqual(3, self.lc.get())
self.assertEqual(4, self.vc.get())
self.delta = 10
self.vc.changed_transform()
self.assertEqual(3, self.lc.get())
self.assertEqual(13, self.vc.get())
def test_subscription(self):
st = CellSubscriptionTester(self.vc)
self.lc.set(1)
st.expect_now(2)
self.delta = 10
self.vc.changed_transform()
self.assertEqual(1, self.lc.get())
st.expect_now(11)
st.unsubscribe()
self.lc.set(2)
st.advance()
def test_coerced_base_value(self):
self.vc.set(999) # out of base cell's range, gets clamped
self.assertEqual(100 + self.delta, self.vc.get())