-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtest_ref.py
More file actions
38 lines (31 loc) · 1.39 KB
/
Copy pathtest_ref.py
File metadata and controls
38 lines (31 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from testtools import TestCase
from ._base import Effect
from ._sync import sync_perform
from .ref import Reference, ModifyReference, ReadReference, reference_dispatcher
class ReferenceTests(TestCase):
"""Tests for :obj:`Reference`."""
def test_read(self):
"""``read`` returns an Effect that represents the current value."""
ref = Reference("initial")
self.assertEqual(ref.read(), Effect(ReadReference(ref=ref)))
def test_modify(self):
"""``modify`` returns an Effect that represents modification."""
ref = Reference(0)
transformer = lambda x: x + 1
eff = ref.modify(transformer)
self.assertEqual(eff, Effect(ModifyReference(ref=ref, transformer=transformer)))
def test_perform_read(self):
"""Performing the reading results in the current value."""
ref = Reference("initial")
result = sync_perform(reference_dispatcher, ref.read())
self.assertEqual(result, "initial")
def test_perform_modify(self):
"""
Performing the modification results in transforming the current value,
and also returns the new value.
"""
ref = Reference(0)
transformer = lambda x: x + 1
result = sync_perform(reference_dispatcher, ref.modify(transformer))
self.assertEqual(result, 1)
self.assertEqual(sync_perform(reference_dispatcher, ref.read()), 1)