Example #1
0
def test_get_missing_key(d):
    assume('key' not in d)

    with pytest.raises(KeyError):
        d['key']
    assert d.get('key') == Nothing()
Example #2
0
 def test_maybe_decorater(self):
     maybe_int = maybe(int)
     assert maybe_int('1') == Just(1)
     assert maybe_int('whoops') == Nothing()
Example #3
0
 def test_nothing_bool(self):
     assert not bool(Nothing())
Example #4
0
 def test_nothing_or_else(self, value):
     assert Nothing().or_else(value) is value
Example #5
0
 def test_composition_law(self, f: Unary, g: Unary, value):
     h = compose(f, g)
     assert Just(value).map(h) == Just(value).map(g).map(f)
     assert Nothing().map(h) == Nothing().map(g).map(f)
Example #6
0
 def _test_nothing_identity_law(self):
     assert Nothing().map(identity) == Nothing()
Example #7
0
 def _test_just_inequality(self, value):
     assert Just(value) != Nothing()
Example #8
0
 def _test_nothing_equality(self):
     assert Nothing() == Nothing()