Exemple #1
0
 def test_maybe_map(self):
     l = Maybe("lower")
     lmapped = l.map(lambda s: s.upper())
     assert lmapped == Maybe("LOWER")
     assert lmapped == "LOWER"
     assert lmapped.or_else_get("Nothing") == "LOWER"
     assert lmapped.or_else(lambda: "Nothing") == "LOWER"
     assert lmapped.or_else_raise(lambda: ValueError("Nothing!")) == "LOWER"
Exemple #2
0
 def test_maybe_is_present(self):
     assert Maybe(None).is_present is False
     assert Maybe("Something").is_present
Exemple #3
0
    def test_maybe_or_else_raise(self):
        with pytest.raises(ValueError):
            assert Maybe(None).or_else_raise(lambda: ValueError("No value"))

        assert (Maybe("Something").or_else_raise(
            lambda: ValueError("No value")) == "Something")
Exemple #4
0
 def test_maybe_or_else_get(self):
     assert Maybe(None).or_else_get("Not None") == "Not None"
     assert Maybe("Something").or_else_get("Nothing") == "Something"
Exemple #5
0
 def test_maybe_or_else(self):
     assert Maybe(None).or_else(lambda: "Not None") == "Not None"
     assert Maybe("Something").or_else(lambda: "Nothing") == "Something"
Exemple #6
0
 def test_maybe_equals(self):
     assert Maybe("Something") == "Something"
     assert Maybe("Something") == Maybe("Something")
     assert Maybe(None) == Maybe(None)
     assert Maybe(None) != Maybe("Something")
Exemple #7
0
 def test_maybe_value(self):
     assert Maybe(None).value is None
     assert Maybe("Something").value == "Something"