Beispiel #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])
Beispiel #2
0
    def binder(self, line, cell=''):
        '''Simple example.'''
        
        args = parse_argstring(self.binder, line)
        if args.repo:
            self.repo = args.repo
            binderURL = binder_url(self.repo)
            self.b = MyBinderCell(binderURL, message='step')
            
        if self.b is None:
            print('No connection...')
            return
        
        if cell is None:
            print('Use block magic')
        else:
            #We can force cell numbers...
            #get_ipython().execution_count = 77

            #Use a different colour cell background to show we're using a Binder kernel...
            _set_background()

            items = self.b.execute_request(cell)
            for item in items['iopub']:
                if item['msg_type']=='execute_result':
                    return capture.RichOutput(data=item['content']['data'], metadata={})
                elif item['msg_type']=='stream':
                    IPython.display.display({'text/plain':item['content']['text']}, raw=True)
Beispiel #3
0
def test_rich_output_metadata(method_mime):
    """test RichOutput with metadata"""
    data = full_data
    metadata = full_metadata
    rich = capture.RichOutput(data=data, metadata=metadata)
    method, mime = method_mime
    nt.assert_equal(getattr(rich, method)(), (data[mime], metadata[mime]))
Beispiel #4
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
Beispiel #5
0
def test_capture_output_no_stdout():
    """test capture_output(stdout=False)"""
    rich = capture.RichOutput(data=full_data)
    with capture.capture_output(stdout=False) as cap:
        print(hello_stdout, end="")
        print(hello_stderr, end="", file=sys.stderr)
        rich.display()
    nt.assert_equal("", cap.stdout)
    nt.assert_equal(hello_stderr, cap.stderr)
    nt.assert_equal(len(cap.outputs), 1)
Beispiel #6
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
Beispiel #7
0
def test_rich_output():
    """test RichOutput basics"""
    data = basic_data
    metadata = basic_metadata
    rich = capture.RichOutput(data=data, metadata=metadata)
    assert rich._repr_html_() == data["text/html"]
    assert rich._repr_png_() == (data["image/png"], metadata["image/png"])
    assert rich._repr_latex_() is None
    assert rich._repr_javascript_() is None
    assert rich._repr_svg_() is None
Beispiel #8
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()
    assert hello_stdout == cap.stdout
    assert hello_stderr == cap.stderr
    assert cap.outputs == []
Beispiel #9
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, []
Beispiel #10
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
Beispiel #11
0
def test_rich_output():
    """test RichOutput basics"""
    data = basic_data
    metadata = basic_metadata
    rich = capture.RichOutput(data=data, metadata=metadata)
    nt.assert_equal(rich._repr_html_(), data["text/html"])
    nt.assert_equal(rich._repr_png_(),
                    (data["image/png"], metadata["image/png"]))
    nt.assert_equal(rich._repr_latex_(), None)
    nt.assert_equal(rich._repr_javascript_(), None)
    nt.assert_equal(rich._repr_svg_(), None)
Beispiel #12
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()
    assert hello_stdout == cap.stdout
    assert "" == cap.stderr
    assert len(cap.outputs) == 1
Beispiel #13
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
Beispiel #14
0
def test_rich_output_empty(method_mime):
    """RichOutput with no args"""
    rich = capture.RichOutput()
    method, mime = method_mime
    nt.assert_equal(getattr(rich, method)(), None)
Beispiel #15
0
def test_rich_output_no_metadata():
    """test RichOutput with no metadata"""
    data = full_data
    rich = capture.RichOutput(source="test", data=data)
    for method, mime in _mime_map.items():
        yield nt.assert_equal, getattr(rich, method)(), data[mime]
Beispiel #16
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
Beispiel #17
0
def test_rich_output_no_metadata(method_mime):
    """test RichOutput with no metadata"""
    data = full_data
    rich = capture.RichOutput(data=data)
    method, mime = method_mime
    assert getattr(rich, method)() == data[mime]