コード例 #1
0
ファイル: test_debug.py プロジェクト: starenka/pipetools
def test_pipe_exception():
    "How an exception in a pipe should look like"

    f = pipe | str | foreach(X.upper()) | foreach(~X.lower() | int) | list

    with pytest.raises(ValueError) as excinfo:
        f('adfasfa')

    assert excinfo.value.message == (
        "invalid literal for int() with base 10: 'a'\n"
        "  in pipe | X.lower | X() | int\n"
        "  in pipe | str | foreach(X.upper | X()) | foreach(X.lower | X() | int) | list"
    )
コード例 #2
0
 def test_with_exception_in_foreach(self):
     f = foreach(unless(AttributeError, X.lower())) | list
     assert f(['A', 'B', 37]) == ['a', 'b', None]
コード例 #3
0
 def test_with_exception(self):
     f = unless(AttributeError, foreach(X.lower()) | list)
     assert f(['A', 'B', 37]) is None
コード例 #4
0
 def test_ok(self):
     f = unless(AttributeError, foreach(X.lower())) | list
     assert f("ABC") == ['a', 'b', 'c']
コード例 #5
0
ファイル: test_utils.py プロジェクト: 0101/pipetools
 def test_with_exception(self):
     f = unless(AttributeError, foreach(X.lower()) | list)
     assert f(['A', 'B', 37]) is None
コード例 #6
0
ファイル: test_utils.py プロジェクト: 0101/pipetools
 def test_ok(self):
     f = unless(AttributeError, foreach(X.lower())) | list
     assert f("ABC") == ['a', 'b', 'c']
コード例 #7
0
ファイル: test_utils.py プロジェクト: 0101/pipetools
 def test_with_exception_in_foreach(self):
     f = foreach(unless(AttributeError, X.lower())) | list
     assert f(['A', 'B', 37]) == ['a', 'b', None]