File: test_str.py

package info (click to toggle)
ubelt 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,180 kB
  • sloc: python: 15,487; sh: 807; makefile: 24
file content (24 lines) | stat: -rw-r--r-- 583 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import ubelt as ub


def test_capture_stdout_enabled():
    with ub.CaptureStdout(enabled=False) as cap:
        print('foobar')
    assert cap.text is None

    with ub.CaptureStdout(enabled=True) as cap:
        print('foobar')
    assert cap.text.strip() == 'foobar'


def test_capture_stdout_exception():
    """
    CommandLine:
        pytest ubelt/tests/test_str.py::test_capture_stdout_exception -s
    """
    try:
        with ub.CaptureStdout(enabled=True) as cap:
            raise Exception('foobar')
    except Exception:
        pass
    assert cap.text.strip() == ''