def test_compare_maybe(self): # Compare maybes to each other e = Maybe(3) e2 = Maybe(5) assert e < e2 assert e2 > e assert e != e2
def test_get_attribute(self): b = self.Foo(None) a = self.Foo(b) m = Maybe(a) assert m.attr == b assert m['attr'] == b
def test_chained_exists(self): c = self.Foo(None) b = self.Foo(c) a = self.Foo(b) m = Maybe(a) assert isinstance(m.attr.attr, Maybe) assert m.attr.attr.otherwise(None) == c
def test_call_nocall(self): class A: pass v = Maybe(A()) e = v() assert e.is_nothing()
def test_eq(self): e = {'a': 1, 'b': 2} v = Maybe(e) assert e == v
def test_getitem(self): e = [1, 2, 3] v = Maybe(e) assert v[1] == 2
def test_something(self): value = Maybe('1') assert value.just() == '1'
def test_repr(self): e = Maybe(1) assert repr(e) == 'Maybe(1)'
def test_none(self): value = Maybe(None) assert value.just() is None
def test_ge(self): e = Maybe(4) assert not 2 >= e assert 4 >= e assert 6 >= e
def test_lt(self): e = Maybe(4) assert 2 < e assert not 6 < e
def test_nothing(self): value = Maybe(EMPTY) assert not value.is_something()
def test_something(self): value = Maybe('1') assert value.is_something()
def test_none(self): value = Maybe(None) assert value.otherwise(1) is None
def test_something(self): value = Maybe(1) assert value.otherwise() == 1
def test_nothing(self): value = Maybe(EMPTY) assert value.otherwise() is None
def test_ne(self): e = {'a': 1, 'b': 2} v = Maybe(e) x = e.copy() x['a'] = 3 assert e != x
def test_none(self): value = Maybe(None) assert value.is_something()
def test_gt(self): e = Maybe(1) assert 2 > e assert not 1 > e
def test_str(self): e = Maybe(1) assert str(e) == '1'
def test_le(self): e = Maybe(4) assert 2 <= e assert 4 <= e assert not 6 <= e
def test_int(self): e = Maybe('3') assert int(e) == 3
def test_empty(self, d: AsMaybe): m = Maybe(EMPTY) assert m.as_maybe(d).is_nothing()
def test_nothing(self): value = Maybe(EMPTY) assert value.just() is EMPTY
def test_bytes(self): e = Maybe(1) assert bytes(e) == bytes(1)
def test_valid(self, d: AsMaybe): m = Maybe(1) assert m.as_maybe(d).is_something()
def test_float(self): e = Maybe(1) assert float(e) == 1.0
def test_invalid(self, d: AsMaybe): m = Maybe(NotImplemented) assert m.as_maybe(d).is_nothing()
def test_hash(self): e = Maybe(1) e2 = Maybe(2) b = {e} b.add(e2) assert b == {e, e2}
def test_call_error(self): v = Maybe(int) e = v("foo") assert e.is_nothing()