示例#1
0
def test_rich_output_metadata():
    """test RichOutput with metadata"""
    data = full_data
    metadata = full_metadata
    rich = capture.RichOutput(data=data, metadata=metadata)
    for method, mime in _mime_map.items():
        yield nt.assert_equal, getattr(rich, method)(), (data[mime], metadata[mime])
示例#2
0
def test_capture_output():
    """capture_output works"""
    rich = capture.RichOutput(data=full_data)
    with capture.capture_output() as cap:
        print(hello_stdout, end="")
        print(hello_stderr, end="", file=sys.stderr)
        rich.display()
    yield nt.assert_equal, hello_stdout, cap.stdout
    yield nt.assert_equal, hello_stderr, cap.stderr
示例#3
0
def test_rich_output():
    """test RichOutput basics"""
    data = basic_data
    metadata = basic_metadata
    rich = capture.RichOutput(data=data, metadata=metadata)
    yield nt.assert_equal, rich._repr_html_(), data['text/html']
    yield nt.assert_equal, rich._repr_png_(), (data['image/png'], metadata['image/png'])
    yield nt.assert_equal, rich._repr_latex_(), None
    yield nt.assert_equal, rich._repr_javascript_(), None
    yield nt.assert_equal, rich._repr_svg_(), None
示例#4
0
def test_capture_output_no_display():
    """test capture_output(display=False)"""
    rich = capture.RichOutput(data=full_data)
    with capture.capture_output(display=False) as cap:
        print(hello_stdout, end="")
        print(hello_stderr, end="", file=sys.stderr)
        rich.display()
    yield nt.assert_equal, hello_stdout, cap.stdout
    yield nt.assert_equal, hello_stderr, cap.stderr
    yield nt.assert_equal, cap.outputs, []
示例#5
0
def test_capture_output_no_stderr():
    """test capture_output(stderr=False)"""
    rich = capture.RichOutput(data=full_data)
    # add nested capture_output so stderr doesn't make it to nose output
    with capture.capture_output(), capture.capture_output(stderr=False) as cap:
        print(hello_stdout, end="")
        print(hello_stderr, end="", file=sys.stderr)
        rich.display()
    yield nt.assert_equal, hello_stdout, cap.stdout
    yield nt.assert_equal, "", cap.stderr
    yield nt.assert_equal, len(cap.outputs), 1
示例#6
0
def test_rich_output_display():
    """test RichOutput.display
    
    This is a bit circular, because we are actually using the capture code we are testing
    to test itself.
    """
    data = full_data
    rich = capture.RichOutput(data=data)
    with capture.capture_output() as cap:
        rich.display()
    yield nt.assert_equal, len(cap.outputs), 1
    rich2 = cap.outputs[0]
    yield nt.assert_equal, rich2.data, rich.data
    yield nt.assert_equal, rich2.metadata, rich.metadata
示例#7
0
def test_rich_output_empty():
    """RichOutput with no args"""
    rich = capture.RichOutput()
    for method, mime in _mime_map.items():
        yield nt.assert_equal, getattr(rich, method)(), None