def test_get_missing_key(d): assume('key' not in d) with pytest.raises(KeyError): d['key'] assert d.get('key') == Nothing()
def test_maybe_decorater(self): maybe_int = maybe(int) assert maybe_int('1') == Just(1) assert maybe_int('whoops') == Nothing()
def test_nothing_bool(self): assert not bool(Nothing())
def test_nothing_or_else(self, value): assert Nothing().or_else(value) is value
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)
def _test_nothing_identity_law(self): assert Nothing().map(identity) == Nothing()
def _test_just_inequality(self, value): assert Just(value) != Nothing()
def _test_nothing_equality(self): assert Nothing() == Nothing()