Beispiel #1
0
def test_output_quiet():
    """Checking to make sure that output is quiet"""

    with AssertNotPrints('2'):
        ip.run_cell('1+1;', store_history=True)

    with AssertNotPrints('2'):
        ip.run_cell('1+1; # comment with a semicolon', store_history=True)
Beispiel #2
0
def test_output_quiet():
    """Checking to make sure that output is quiet"""

    with AssertNotPrints("2"):
        ip.run_cell("1+1;", store_history=True)

    with AssertNotPrints("2"):
        ip.run_cell("1+1; # comment with a semicolon", store_history=True)

    with AssertNotPrints("2"):
        ip.run_cell("1+1;\n#commented_out_function()", store_history=True)
Beispiel #3
0
def test_interactivehooks_ast_modes():
    """
    Test that ast nodes can be triggered with different modes
    """
    saved_mode = ip.ast_node_interactivity
    ip.ast_node_interactivity = 'last_expr_or_assign'

    try:
        with AssertPrints('2'):
            ip.run_cell('a = 1+1', store_history=True)

        with AssertPrints('9'):
            ip.run_cell('b = 1+8 # comment with a semicolon;', store_history=False)

        with AssertPrints('7'):
            ip.run_cell('c = 1+6\n#commented_out_function();', store_history=True)

        ip.run_cell('d = 11', store_history=True)
        with AssertPrints('12'):
            ip.run_cell('d += 1', store_history=True)

        with AssertNotPrints('42'):
            ip.run_cell('(u,v) = (41+1, 43-1)')

    finally:
        ip.ast_node_interactivity = saved_mode
Beispiel #4
0
def test_interactivehooks_ast_modes():
    """
    Test that ast nodes can be triggered with different modes
    """
    saved_mode = ip.ast_node_interactivity
    ip.ast_node_interactivity = "last_expr_or_assign"

    try:
        with AssertPrints("2"):
            ip.run_cell("a = 1+1", store_history=True)

        with AssertPrints("9"):
            ip.run_cell("b = 1+8 # comment with a semicolon;",
                        store_history=False)

        with AssertPrints("7"):
            ip.run_cell("c = 1+6\n#commented_out_function();",
                        store_history=True)

        ip.run_cell("d = 11", store_history=True)
        with AssertPrints("12"):
            ip.run_cell("d += 1", store_history=True)

        with AssertNotPrints("42"):
            ip.run_cell("(u,v) = (41+1, 43-1)")

    finally:
        ip.ast_node_interactivity = saved_mode
Beispiel #5
0
def test_display_available():
    """
    Test that display is available without import

    We don't really care if it's in builtin or anything else, but it should
    always be available.
    """
    ip = get_ipython()
    with AssertNotPrints('NameError'):
        ip.run_cell('display')
    try:
        ip.run_cell('del display')
    except NameError:
        pass  # it's ok, it might be in builtins
    # even if deleted it should be back
    with AssertNotPrints('NameError'):
        ip.run_cell('display')
Beispiel #6
0
def test_interactivehooks_ast_modes_semi_supress():
    """
    Test that ast nodes can be triggered with different modes and suppressed
    by semicolon
    """
    saved_mode = ip.ast_node_interactivity
    ip.ast_node_interactivity = 'last_expr_or_assign'

    try:
        with AssertNotPrints('2'):
            ip.run_cell('x = 1+1;', store_history=True)

        with AssertNotPrints('7'):
            ip.run_cell('y = 1+6; # comment with a semicolon', store_history=True)

        with AssertNotPrints('9'):
            ip.run_cell('z = 1+8;\n#commented_out_function()', store_history=True)

    finally:
        ip.ast_node_interactivity = saved_mode
Beispiel #7
0
def test_pinfo_no_docstring_if_source():
    """Docstring should not be included with detail_level=1 if source is found"""
    def foo():
        """foo has a docstring"""

    ip.user_ns['foo'] = foo

    with AssertPrints('Docstring:'):
        ip._inspect('pinfo', 'foo', detail_level=0)
    with AssertPrints('Source:'):
        ip._inspect('pinfo', 'foo', detail_level=1)
    with AssertNotPrints('Docstring:'):
        ip._inspect('pinfo', 'foo', detail_level=1)
Beispiel #8
0
def test_pinfo_no_docstring_if_source():
    """Docstring should not be included with detail_level=1 if source is found"""
    def foo():
        """foo has a docstring"""

    ip.user_ns["foo"] = foo

    with AssertPrints("Docstring:"):
        ip._inspect("pinfo", "foo", detail_level=0)
    with AssertPrints("Source:"):
        ip._inspect("pinfo", "foo", detail_level=1)
    with AssertNotPrints("Docstring:"):
        ip._inspect("pinfo", "foo", detail_level=1)
Beispiel #9
0
def test_interactivehooks_ast_modes_semi_suppress():
    """
    Test that ast nodes can be triggered with different modes and suppressed
    by semicolon
    """
    saved_mode = ip.ast_node_interactivity
    ip.ast_node_interactivity = "last_expr_or_assign"

    try:
        with AssertNotPrints("2"):
            ip.run_cell("x = 1+1;", store_history=True)

        with AssertNotPrints("7"):
            ip.run_cell("y = 1+6; # comment with a semicolon",
                        store_history=True)

        with AssertNotPrints("9"):
            ip.run_cell("z = 1+8;\n#commented_out_function()",
                        store_history=True)

    finally:
        ip.ast_node_interactivity = saved_mode
Beispiel #10
0
def test_pinfo_docstring_if_detail_and_no_source():
    """ Docstring should be displayed if source info not available """
    obj_def = '''class Foo(object):
                  """ This is a docstring for Foo """
                  def bar(self):
                      """ This is a docstring for Foo.bar """
                      pass
              '''

    ip.run_cell(obj_def)
    ip.run_cell('foo = Foo()')

    with AssertNotPrints("Source:"):
        with AssertPrints('Docstring:'):
            ip._inspect('pinfo', 'foo', detail_level=0)
        with AssertPrints('Docstring:'):
            ip._inspect('pinfo', 'foo', detail_level=1)
        with AssertPrints('Docstring:'):
            ip._inspect('pinfo', 'foo.bar', detail_level=0)

    with AssertNotPrints('Docstring:'):
        with AssertPrints('Source:'):
            ip._inspect('pinfo', 'foo.bar', detail_level=1)