コード例 #1
0
ファイル: test_effect.py プロジェクト: thomhickey/pfun
 def test_get(self):
     mock_resource = asynctest.MagicMock()
     resource = Resource(lambda: either.Right(mock_resource))
     effect = resource.get()
     assert effect.run(None) == mock_resource
     mock_resource.__aenter__.assert_called_once()
     assert resource.resource is None
コード例 #2
0
 def test_resources_are_unique(self):
     mock_resource = asynctest.MagicMock()
     resource = Resource(lambda: either.Right(mock_resource))
     r1, r2 = effect.sequence_async(
         (resource.get(), resource.get())
     ).run(None)
     assert r1 is r2
     mock_resource.__aenter__.assert_called_once()
コード例 #3
0
 def test_absolve(self):
     right = either.Right(1)
     left = either.Left('error')
     right_effect = effect.success(right)
     left_effect = effect.success(left)
     assert effect.absolve(right_effect).run(None) == 1
     with pytest.raises(Exception):
         # todo
         effect.absolve(left_effect).run(None)
コード例 #4
0
 def test_try_modify(self):
     int_ref = ref.Ref(0)
     int_ref.try_modify(lambda _: either.Left('')).either().run(None)
     assert int_ref.value == 0
     int_ref.try_modify(lambda _: either.Right(1)).run(None)
     assert int_ref.value == 1
コード例 #5
0
 def f(s: str) -> either.Either[str, str]:
     return either.Right(s)
コード例 #6
0
 def test_either(self):
     success = effect.success(1)
     error = effect.error('error')
     assert success.either().run(None) == either.Right(1)
     error.either().run(None) == either.Left('error')