예제 #1
0
def test_newline():
    ipi = IronPythonInstance(executable, exec_prefix, "")
    ipi.proc.Start()
    ipi.reader = ipi.proc.StandardOutput
    output = ipi.EatToPrompt()
    Assert('\r\r\n' not in output)
    Assert('\r\n' in output)
예제 #2
0
 def test_logo(self):
     from iptest.console_util import IronPythonInstance
     i = IronPythonInstance(sys.executable, sys.exec_prefix, "")
     self.assertEqual(i.proc.Start(), True)
     i.reader = i.proc.StandardOutput
     x = i.EatToPrompt()
     self.assertTrue(x.find('\r\r\n') == -1)
     i.End()
예제 #3
0
def test_startup_dir():
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)
    response = ipi.ExecuteLine("print dir()")
    AreEqual(sorted(eval(response)),
             sorted(['__builtins__', '__doc__', '__name__']))
예제 #4
0
def test_aform_feeds():
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)
    response = ipi.ExecuteLine("\fprint 'hello'")
    AreEqual(response, "hello")
    response = ipi.ExecuteLine("      \fprint 'hello'")
    AreEqual(response, "hello")

    ipi.ExecutePartialLine("def f():")
    ipi.ExecutePartialLine("\f    print 'hello'")
    ipi.ExecuteLine('')
    response = ipi.ExecuteLine('f()')
    AreEqual(response, "hello")

    # \f resets indent to 0
    ipi.ExecutePartialLine("def f():")
    ipi.ExecutePartialLine("    \f    x = 'hello'")
    ipi.ExecutePartialLine("\f    print x")

    ipi.ExecuteLine('')
    response = ipi.ExecuteLine('f()')
    AreEqual(response, "hello")

    # \f resets indent to 0
    ipi.ExecutePartialLine("def f():")
    ipi.ExecutePartialLine("    \f    x = 'hello'")
    ipi.ExecutePartialLine("    print x")

    ipi.ExecuteLine('')
    response = ipi.ExecuteLine('f()')
    AreEqual(response, "hello")
예제 #5
0
def test_comments():
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)

    response = ipi.ExecuteLine("# this is some comment line")
    AreEqual(response, "")
    response = ipi.ExecuteLine("    # this is some comment line")
    AreEqual(response, "")
    response = ipi.ExecuteLine("# this is some more comment line")
    AreEqual(response, "")
    ipi.ExecutePartialLine("if 100:")
    ipi.ExecutePartialLine("    print 100")
    ipi.ExecutePartialLine("# this is some more comment line inside if")
    ipi.ExecutePartialLine(
        "#     this is some indented comment line inside if")
    ipi.ExecutePartialLine("    print 200")
    response = ipi.ExecuteLine("")
    AreEqual(response, "100" + newline + "200")
    ipi.End()
예제 #6
0
def test_whitespace():
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)
    ipi.ExecuteLine("  ")
    response = ipi.ExecuteLine("")
    ipi.End()

    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)
    ipi.ExecuteLine("  ")
    response = ipi.ExecuteLine("2")
    Assert("2" in response)
    ipi.End()

    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)
    ipi.ExecuteLine("  ")
    response = ipi.ExecuteLine("  2", True)
    Assert("SyntaxError:" in response)
    ipi.End()
예제 #7
0
def test_partial_dicts():
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)
    ipi.ExecutePartialLine("{2:2")
    ipi.ExecutePartialLine("  ,")
    ipi.ExecutePartialLine("    2:2")
    response = ipi.ExecuteLine("}")
    Assert("{2: 2}" in response)

    ipi.ExecutePartialLine("{")
    response = ipi.ExecuteLine("}")
    Assert("{}" in response)

    ipi.ExecutePartialLine("a = {")
    ipi.ExecutePartialLine("    None:2")
    ipi.ExecutePartialLine(" , ")
    ipi.ExecuteLine("}")
    response = ipi.ExecuteLine("a")
    Assert("{None: 2}" in response)

    ipi.ExecutePartialLine("{")
    ipi.ExecutePartialLine("'joe'")
    ipi.ExecutePartialLine(": ")
    ipi.ExecutePartialLine("       42")
    ipi.ExecutePartialLine(",")
    ipi.ExecutePartialLine("3:45")
    response = ipi.ExecuteLine("}")
    Assert(repr({'joe': 42, 3: 45}) in response)

    ipi.ExecutePartialLine("{")
    ipi.ExecutePartialLine("")
    ipi.ExecutePartialLine("")
    response = ipi.ExecuteLine("}")
    Assert("{}" in response)

    ipi.End()
예제 #8
0
    return hasattr(*args)


AreEqual(foo('', 'index'), True)

# dispatch to a ReflectOptimized method

if is_cli and not is_silverlight:
    from iptest.console_util import IronPythonInstance
    from System import Environment
    from sys import executable

    wkdir = testpath.public_testdir

    if "-X:LightweightScopes" in Environment.GetCommandLineArgs():
        ipi = IronPythonInstance(executable, wkdir, "-X:LightweightScopes",
                                 "-X:BasicConsole")
    else:
        ipi = IronPythonInstance(executable, wkdir, "-X:BasicConsole")

    if (ipi.Start()):
        result = ipi.ExecuteLine("from iptest.assert_util import *")
        result = ipi.ExecuteLine("load_iron_python_test()")
        result = ipi.ExecuteLine("from IronPythonTest import DefaultParams")
        response = ipi.ExecuteLine(
            "DefaultParams.FuncWithDefaults(1100, z=82)")
        AreEqual(response, '1184')
        ipi.End()

p = ((1, 2), )

AreEqual(list(zip(*(p * 10))), [(1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
예제 #9
0
def test_partial_lists():
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)
    ipi.ExecutePartialLine("[1")
    ipi.ExecutePartialLine("  ,")
    ipi.ExecutePartialLine("    2")
    response = ipi.ExecuteLine("]")
    Assert("[1, 2]" in response)

    ipi.ExecutePartialLine("[")
    ipi.ExecutePartialLine("")
    ipi.ExecutePartialLine("")
    response = ipi.ExecuteLine("]")
    Assert("[]" in response)
    ipi.End()
예제 #10
0
def test_strings():
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)

    # String exception
    response = ipi.ExecuteLine("raise 'foo'", True)
    AreEqual(
        response.replace("\r\r\n", "\n").replace("\r", ""),
        """Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: exceptions must be classes, or instances, not str""")

    # Multi-line string literal
    ipi.ExecutePartialLine("\"\"\"Hello")
    ipi.ExecutePartialLine("")
    ipi.ExecutePartialLine("")
    AreEqual("'Hello\\n\\n\\nWorld'", ipi.ExecuteLine("World\"\"\""))

    ipi.ExecutePartialLine("if False: print 3")
    ipi.ExecutePartialLine("else: print 'hello'")
    AreEqual(r'hello', ipi.ExecuteLine(""))

    # Empty line
    AreEqual("", ipi.ExecuteLine(""))

    ipi.End()
예제 #11
0
def test_sys_exitfunc():
    import clr

    inputScript = testpath.test_inputs_dir + "\\exitFuncRuns.py"
    ipi = IronPythonInstance(executable, exec_prefix,
                             extraArgs + " \"" + inputScript + "\"")
    (result, output, output2, exitCode) = ipi.StartAndRunToCompletion()
    AreEqual(exitCode, 0)
    AreEqual(output.find('hello world') > -1, True)
    ipi.End()

    args = extraArgs

    if clr.GetCurrentRuntime().Configuration.DebugMode:
        args = "-D " + args

    inputScript = testpath.test_inputs_dir + "\\exitFuncRaises.py"
    ipi = IronPythonInstance(executable, exec_prefix,
                             args + " \"" + inputScript + "\"")
    (result, output, output2, exitCode) = ipi.StartAndRunToCompletion()
    AreEqual(exitCode, 0)
    AreEqual(output2.find('Error in sys.exitfunc:') > -1, True)

    AreEqual(output2.find('exitFuncRaises.py", line 19, in foo') > -1, True)

    ipi.End()

    # verify sys.exit(True) and sys.exit(False) return 1 and 0

    ipi = IronPythonInstance(executable, exec_prefix,
                             '-c "import sys; sys.exit(False)"')
    res = ipi.StartAndRunToCompletion()
    AreEqual(res[0], True)  # should have started
    AreEqual(res[1], '')  # no std out
    AreEqual(res[2], '')  # no std err
    AreEqual(res[3], 0)  # should return 0

    ipi = IronPythonInstance(executable, exec_prefix,
                             '-c "import sys; sys.exit(True)"')
    res = ipi.StartAndRunToCompletion()
    AreEqual(res[0], True)  # should have started
    AreEqual(res[1], '')  # no std out
    AreEqual(res[2], '')  # no std err
    AreEqual(res[3], 1)  # should return 0

    # and verify it works at the interactive console as well
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)

    # parameterless exception
    ipi.ExecuteLine("import sys")
    AreEqual(ipi.ExecuteAndExit("sys.exit(False)"), 0)

    # and verify it works at the interactive console as well
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)

    # parameterless exception
    ipi.ExecuteLine("import sys")
    AreEqual(ipi.ExecuteAndExit("sys.exit(True)"), 1)
예제 #12
0
def test_logo():
    i = IronPythonInstance(sys.executable, sys.exec_prefix, "")
    AreEqual(i.proc.Start(), True)
    i.reader = i.proc.StandardOutput
    x = i.EatToPrompt()
    Assert(x.find('\r\r\n') == -1)
예제 #13
0
def start_remote_console(args = ""):
    inputScript = testpath.test_inputs_dir + "\\RemoteConsole.py"
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs + " \"" + inputScript + "\" -X:ExceptionDetail " + args)
    AreEqual(ipi.Start(), True)
    return ipi
예제 #14
0
def test_sta_sleep_Warning():
    ipi = IronPythonInstance(executable, exec_prefix, '-c "from System.Threading import Thread;Thread.Sleep(100)"')    
    retval, stdouttext, stderrtext, exitcode = ipi.StartAndRunToCompletion()
    Assert(stderrtext.endswith("RuntimeWarning: Calling Thread.Sleep on an STA thread doesn't pump messages.  Use Thread.CurrentThread.Join instead.\r\n"))
예제 #15
0
def test_dump_exception():
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs + " -X:ExceptionDetail")
    AreEqual(ipi.Start(), True)
    response = ipi.ExecuteLine("raise 'goodbye'", True)
    AreEqual(response.count("IronPython.Hosting") >= 1, True)
    ipi.End()
예제 #16
0
def test_future_with():
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)
    ipi.ExecutePartialLine("class K(object):")
    ipi.ExecutePartialLine("    def __enter__(self): return 3.14")
    ipi.ExecutePartialLine(
        "    def __exit__(self, type, value, tb): return False")
    ipi.ExecuteLine("")
    ipi.ExecutePartialLine("with K() as d:")
    ipi.ExecutePartialLine("    print d")
    response = ipi.ExecuteLine("")
    AreEqual(response, "3.14")
    ipi.End()
예제 #17
0
def test_interactive_mode():
    inputScript = testpath.test_inputs_dir + "\\simpleCommand.py"
    ipi = IronPythonInstance(executable, exec_prefix,
                             extraArgs + " -i \"" + inputScript + "\"")
    AreEqual(ipi.Start(), True)
    ipi.EnsureInteractive()
    AreEqual("1", ipi.ExecuteLine("x"))
    ipi.End()

    inputScript = testpath.test_inputs_dir + "\\raise.py"
    ipi = IronPythonInstance(executable, exec_prefix,
                             extraArgs + " -i \"" + inputScript + "\"")
    AreEqual(ipi.Start(), True)
    ipi.ReadError()
    ipi.EnsureInteractive()
    AreEqual("1", ipi.ExecuteLine("x"))
    ipi.End()

    inputScript = testpath.test_inputs_dir + "\\syntaxError.py"
    ipi = IronPythonInstance(executable, exec_prefix,
                             extraArgs + " -i \"" + inputScript + "\"")
    AreEqual(ipi.Start(), True)
    # ipi.EnsureInteractive()
    AssertContains(ipi.ExecuteLine("x", True), "NameError")
    ipi.End()

    inputScript = testpath.test_inputs_dir + "\\exit.py"
    ipi = IronPythonInstance(executable, exec_prefix,
                             extraArgs + " -i \"" + inputScript + "\"")
    (result, output, output2, exitCode) = ipi.StartAndRunToCompletion()
    AreEqual(exitCode, 0)
    ipi.End()

    # interactive + -c
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs + " -i -c x=2")
    AreEqual(ipi.Start(), True)
    ipi.EnsureInteractive()
    Assert(ipi.ExecuteLine("x", True).find("2") != -1)
    ipi.End()
예제 #18
0
def test_partial_lists_cp3530():

    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)

    try:
        ipi.ExecutePartialLine("[{'a':None},")
        response = ipi.ExecuteLine("]")
        Assert("[{'a': None}]" in response, response)

        ipi.ExecutePartialLine("[{'a'")
        response = ipi.ExecutePartialLine(":None},")
        response = ipi.ExecuteLine("]")
        Assert("[{'a': None}]" in response, response)

        ipi.ExecutePartialLine("[{'a':None},")
        ipi.ExecutePartialLine("1,")
        response = ipi.ExecuteLine("2]")
        Assert("[{'a': None}, 1, 2]" in response, response)

    finally:
        ipi.End()
예제 #19
0
def test_logo():
    i = IronPythonInstance(sys.executable, sys.exec_prefix, "")
    AreEqual(i.proc.Start(), True)
    i.reader = i.proc.StandardOutput
    x = i.EatToPrompt()
    Assert(x.find('\r\r\n') == -1)
예제 #20
0
def test_partial_tuples():
    ipi = IronPythonInstance(executable, exec_prefix, extraArgs)
    AreEqual(ipi.Start(), True)
    ipi.ExecutePartialLine("(2")
    ipi.ExecutePartialLine("  ,")
    ipi.ExecutePartialLine("    3")
    response = ipi.ExecuteLine(")")
    Assert("(2, 3)" in response)

    ipi.ExecutePartialLine("(")
    response = ipi.ExecuteLine(")")
    Assert("()" in response)

    ipi.ExecutePartialLine("'abc %s %s %s %s %s' % (")
    ipi.ExecutePartialLine("    'def'")
    ipi.ExecutePartialLine("    ,'qrt',")
    ipi.ExecutePartialLine("    'jkl'")
    ipi.ExecutePartialLine(",'jkl'")
    ipi.ExecutePartialLine("")
    ipi.ExecutePartialLine(",")
    ipi.ExecutePartialLine("")
    ipi.ExecutePartialLine("")
    ipi.ExecutePartialLine("'123'")
    response = ipi.ExecuteLine(")")
    Assert("'abc def qrt jkl jkl 123'" in response)

    ipi.ExecutePartialLine("a = (")
    ipi.ExecutePartialLine("    1")
    ipi.ExecutePartialLine(" , ")
    ipi.ExecuteLine(")")
    response = ipi.ExecuteLine("a")
    Assert("(1,)" in response)

    ipi.ExecutePartialLine("(")
    ipi.ExecutePartialLine("'joe'")
    ipi.ExecutePartialLine(" ")
    ipi.ExecutePartialLine("       #")
    ipi.ExecutePartialLine(",")
    ipi.ExecutePartialLine("2")
    response = ipi.ExecuteLine(")")
    Assert("('joe', 2)" in response)

    ipi.ExecutePartialLine("(")
    ipi.ExecutePartialLine("")
    ipi.ExecutePartialLine("")
    response = ipi.ExecuteLine(")")
    Assert("()" in response)

    ipi.End()