Example #1
0
 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
Example #2
0
            def test_get_attribute(self):
                b = self.Foo(None)
                a = self.Foo(b)

                m = Maybe(a)
                assert m.attr == b
                assert m['attr'] == b
Example #3
0
 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
Example #4
0
        def test_call_nocall(self):
            class A:
                pass

            v = Maybe(A())
            e = v()
            assert e.is_nothing()
Example #5
0
 def test_eq(self):
     e = {'a': 1, 'b': 2}
     v = Maybe(e)
     assert e == v
Example #6
0
 def test_getitem(self):
     e = [1, 2, 3]
     v = Maybe(e)
     assert v[1] == 2
Example #7
0
 def test_something(self):
     value = Maybe('1')
     assert value.just() == '1'
Example #8
0
 def test_repr(self):
     e = Maybe(1)
     assert repr(e) == 'Maybe(1)'
Example #9
0
 def test_none(self):
     value = Maybe(None)
     assert value.just() is None
Example #10
0
 def test_ge(self):
     e = Maybe(4)
     assert not 2 >= e
     assert 4 >= e
     assert 6 >= e
Example #11
0
 def test_lt(self):
     e = Maybe(4)
     assert 2 < e
     assert not 6 < e
Example #12
0
 def test_nothing(self):
     value = Maybe(EMPTY)
     assert not value.is_something()
Example #13
0
 def test_something(self):
     value = Maybe('1')
     assert value.is_something()
Example #14
0
 def test_none(self):
     value = Maybe(None)
     assert value.otherwise(1) is None
Example #15
0
 def test_something(self):
     value = Maybe(1)
     assert value.otherwise() == 1
Example #16
0
 def test_nothing(self):
     value = Maybe(EMPTY)
     assert value.otherwise() is None
Example #17
0
 def test_ne(self):
     e = {'a': 1, 'b': 2}
     v = Maybe(e)
     x = e.copy()
     x['a'] = 3
     assert e != x
Example #18
0
 def test_none(self):
     value = Maybe(None)
     assert value.is_something()
Example #19
0
 def test_gt(self):
     e = Maybe(1)
     assert 2 > e
     assert not 1 > e
Example #20
0
 def test_str(self):
     e = Maybe(1)
     assert str(e) == '1'
Example #21
0
 def test_le(self):
     e = Maybe(4)
     assert 2 <= e
     assert 4 <= e
     assert not 6 <= e
Example #22
0
 def test_int(self):
     e = Maybe('3')
     assert int(e) == 3
Example #23
0
 def test_empty(self, d: AsMaybe):
     m = Maybe(EMPTY)
     assert m.as_maybe(d).is_nothing()
Example #24
0
 def test_nothing(self):
     value = Maybe(EMPTY)
     assert value.just() is EMPTY
Example #25
0
 def test_bytes(self):
     e = Maybe(1)
     assert bytes(e) == bytes(1)
Example #26
0
 def test_valid(self, d: AsMaybe):
     m = Maybe(1)
     assert m.as_maybe(d).is_something()
Example #27
0
 def test_float(self):
     e = Maybe(1)
     assert float(e) == 1.0
Example #28
0
 def test_invalid(self, d: AsMaybe):
     m = Maybe(NotImplemented)
     assert m.as_maybe(d).is_nothing()
Example #29
0
 def test_hash(self):
     e = Maybe(1)
     e2 = Maybe(2)
     b = {e}
     b.add(e2)
     assert b == {e, e2}
Example #30
0
 def test_call_error(self):
     v = Maybe(int)
     e = v("foo")
     assert e.is_nothing()