Пример #1
0
def test_cp1019():
    #--Test that bogus encodings fail properly
    t_in, t_out, t_err = nt.popen3(sys.executable + " " + nt.getcwd() + r"\encoded_files\cp1019.py")
    t_err_lines = t_err.readlines()
    t_out_lines = t_out.readlines()
    t_err.close()
    t_out.close()
    t_in.close()
    
    AreEqual(len(t_out_lines), 0)
    Assert(t_err_lines[0].startswith("  File"))
    Assert(t_err_lines[1].startswith("SyntaxError: encoding problem: with BOM"))
Пример #2
0
def run_one_command(*args):
    """runs a single command, exiting if it doesn't return 0, redirecting std out"""
    cmd_line = '"' + executable + '" '.join(args)
    inp, out, err = nt.popen3(cmd_line)
    print cmd_line
    output, err = multireader(out, err)
    res = out.close()
    if res:
        print '%d running %s failed' % (res, cmd_line)
        print 'output was', output
        print 'err', err
    return output, err, res
Пример #3
0
def test_cp1019():
    #--Test that bogus encodings fail properly
    t_in, t_out, t_err = nt.popen3(sys.executable + " " + nt.getcwd() + r"\encoded_files\cp1019.py")
    t_err_lines = t_err.readlines()
    t_out_lines = t_out.readlines()
    t_err.close()
    t_out.close()
    t_in.close()
    
    AreEqual(len(t_out_lines), 0)
    Assert(t_err_lines[0].startswith("  File"))
    Assert(t_err_lines[1].startswith("SyntaxError: encoding problem: with BOM"))
Пример #4
0
def run_one_command(*args):
    """runs a single command, exiting if it doesn't return 0, redirecting std out"""
    cmd_line = '"' + executable + '" '.join(args)
    inp, out, err = nt.popen3(cmd_line)
    print cmd_line
    output, err = multireader(out, err)
    res = out.close()
    if res:
        print '%d running %s failed' % (res, cmd_line)
        print 'output was', output
        print 'err', err
    return output, err, res
Пример #5
0
def test_cp11923_second():
    import nt
    import sys
    old_path = [x for x in sys.path]
    sys.path.append(nt.getcwd())

    try:
        #Test setup
        _t_test = testpath.public_testdir + "\\cp11116_main.py"
        write_to_file(
            _t_test, """import cp11116_a
try:
    cp11116_a.a()
except:
    pass

cp11116_a.a()
""")

        _t_test_a = testpath.public_testdir + "\\cp11116_a.py"
        write_to_file(_t_test_a, """def a():
    raise None
""")

        #Actual test
        t_out, t_in, t_err = nt.popen3(sys.executable + " " + nt.getcwd() +
                                       r"\cp11116_main.py")
        lines = t_err.readlines()
        t_err.close()
        t_out.close()
        t_in.close()

        #Verification
        Assert("cp11116_main.py\", line 7, in" in lines[1], lines[1])
        line_num = 3
        if is_cli:
            line_num -= 1
        Assert(
            lines[line_num].rstrip().endswith("cp11116_a.py\", line 2, in a"),
            lines[line_num])

    finally:
        sys.path = old_path
        nt.unlink(_t_test)
        nt.unlink(_t_test_a)
Пример #6
0
def test_cp11923_second():
    import nt
    import sys
    old_path = [x for x in sys.path]
    sys.path.append(nt.getcwd())
        
    try:
        #Test setup
        _t_test = testpath.public_testdir + "\\cp11116_main.py"
        write_to_file(_t_test, """import cp11116_a
try:
    cp11116_a.a()
except:
    pass

cp11116_a.a()
""")
       
        _t_test_a = testpath.public_testdir + "\\cp11116_a.py"
        write_to_file(_t_test_a, """def a():
    raise None
""") 
        
        #Actual test
        t_out, t_in, t_err = nt.popen3(sys.executable + " " + nt.getcwd() + r"\cp11116_main.py")
        lines = t_err.readlines()
        t_err.close()
        t_out.close()
        t_in.close()
                
        #Verification
        Assert("cp11116_main.py\", line 7, in" in lines[1], lines[1])
        line_num = 3
        if is_cli:
            line_num -= 1
        Assert(lines[line_num].rstrip().endswith("cp11116_a.py\", line 2, in a"), lines[line_num])
        
    finally:
        sys.path = old_path
        nt.unlink(_t_test)
        nt.unlink(_t_test_a)
Пример #7
0
def test_popen():
    # open a pipe just for reading...
    pipe_modes = [["ping 127.0.0.1 -n 1", "r"], ["ping 127.0.0.1 -n 1"]]
    if is_cli:
        pipe_modes.append(["ping 127.0.0.1 -n 1", ""])

    for args in pipe_modes:
        x = nt.popen(*args)
        text = x.read()
        Assert(text.lower().index('pinging') != -1)
        AreEqual(x.close(), None)

    # write to a pipe
    x = nt.popen('sort', 'w')
    x.write('hello\nabc\n')
    x.close()

    # bug 1146
    #x = nt.popen('sort', 'w')
    #x.write('hello\nabc\n')
    #AreEqual(x.close(), None)

    # once w/ default mode
    AssertError(ValueError, nt.popen, "ping 127.0.0.1 -n 1", "a")

    # popen uses cmd.exe to run stuff -- at least sometimes
    dir_pipe = nt.popen('dir')
    dir_pipe.read()
    dir_pipe.close()

    # once w/ no mode
    stdin, stdout = nt.popen2('sort')
    stdin.write('hello\nabc\n')
    AreEqual(stdin.close(), None)
    AreEqual(stdout.read(), 'abc\nhello\n')
    AreEqual(stdout.close(), None)

    # bug 1146
    # and once w/ each mode
    #for mode in ['b', 't']:
    #    stdin, stdout = nt.popen2('sort', mode)
    #    stdin.write('hello\nabc\n')
    #    AreEqual(stdin.close(), None)
    #    AreEqual(stdout.read(), 'abc\nhello\n')
    #    AreEqual(stdout.close(), None)

    # popen3: once w/ no mode
    stdin, stdout, stderr = nt.popen3('sort')
    stdin.write('hello\nabc\n')
    AreEqual(stdin.close(), None)
    AreEqual(stdout.read(), 'abc\nhello\n')
    AreEqual(stdout.close(), None)
    AreEqual(stderr.read(), '')
    AreEqual(stderr.close(), None)

    # bug 1146
    # popen3: and once w/ each mode
    #for mode in ['b', 't']:
    #    stdin, stdout, stderr = nt.popen3('sort', mode)
    #    stdin.write('hello\nabc\n')
    #    AreEqual(stdin.close(), None)
    #    AreEqual(stdout.read(), 'abc\nhello\n')
    #    AreEqual(stdout.close(), None)
    #    AreEqual(stderr.read(), '')
    #    AreEqual(stderr.close(), None)

    tmpfile = 'tmpfile.tmp'
    f = open(tmpfile, 'w')
    f.close()
    nt.unlink(tmpfile)
    try:
        nt.chmod('tmpfile.tmp', 256)
    except Exception:
        pass  #should throw when trying to access file deleted by unlink
    else:
        Assert(
            False,
            "Error! Trying to access file deleted by unlink should have thrown."
        )

    try:
        tmpfile = "tmpfile2.tmp"
        f = open(tmpfile, "w")
        f.write("testing chmod")
        f.close()
        nt.chmod(tmpfile, 256)
        AssertError(OSError, nt.unlink, tmpfile)
        nt.chmod(tmpfile, 128)
        nt.unlink(tmpfile)
        AssertError(IOError, file, tmpfile)
    finally:
        try:
            nt.chmod(tmpfile, 128)
            nt.unlink(tmpfile)
        except Exception as e:
            print("exc", e)

    # verify that nt.stat reports times in seconds, not ticks...

    import time
    tmpfile = 'tmpfile.tmp'
    f = open(tmpfile, 'w')
    f.close()
    t = time.time()
    mt = nt.stat(tmpfile).st_mtime
    nt.unlink(tmpfile)  # this deletes the file
    Assert(abs(t - mt) < 60, "time differs by too much " + str(abs(t - mt)))

    tmpfile = 'tmpfile.tmp'  # need to open it again since we deleted it with 'unlink'
    f = open(tmpfile, 'w')
    f.close()
    nt.chmod('tmpfile.tmp', 256)
    nt.chmod('tmpfile.tmp', 128)
    nt.unlink('tmpfile.tmp')
Пример #8
0
def test_popen():
    # open a pipe just for reading...
    pipe_modes = [["ping 127.0.0.1 -n 1", "r"], ["ping 127.0.0.1 -n 1"]]
    if is_cli:
        pipe_modes.append(["ping 127.0.0.1 -n 1", ""])

    for args in pipe_modes:
        x = nt.popen(*args)
        text = x.read()
        Assert(text.lower().index('pinging') != -1)
        AreEqual(x.close(), None)

    # write to a pipe
    x = nt.popen('sort', 'w')
    x.write('hello\nabc\n')
    x.close()

    # bug 1146
    #x = nt.popen('sort', 'w')
    #x.write('hello\nabc\n')
    #AreEqual(x.close(), None)

    # once w/ default mode
    AssertError(ValueError, nt.popen, "ping 127.0.0.1 -n 1", "a")

    # popen uses cmd.exe to run stuff -- at least sometimes
    dir_pipe = nt.popen('dir')
    dir_pipe.read()
    dir_pipe.close()

    # once w/ no mode
    stdin, stdout = nt.popen2('sort')
    stdin.write('hello\nabc\n')
    AreEqual(stdin.close(), None)
    AreEqual(stdout.read(), 'abc\nhello\n')
    AreEqual(stdout.close(), None)

    # bug 1146
    # and once w/ each mode
    #for mode in ['b', 't']:
    #    stdin, stdout = nt.popen2('sort', mode)
    #    stdin.write('hello\nabc\n')
    #    AreEqual(stdin.close(), None)
    #    AreEqual(stdout.read(), 'abc\nhello\n')
    #    AreEqual(stdout.close(), None)

    # popen3: once w/ no mode
    stdin, stdout, stderr = nt.popen3('sort')
    stdin.write('hello\nabc\n')
    AreEqual(stdin.close(), None)
    AreEqual(stdout.read(), 'abc\nhello\n')
    AreEqual(stdout.close(), None)
    AreEqual(stderr.read(), '')
    AreEqual(stderr.close(), None)

    # bug 1146
    # popen3: and once w/ each mode
    #for mode in ['b', 't']:
    #    stdin, stdout, stderr = nt.popen3('sort', mode)
    #    stdin.write('hello\nabc\n')
    #    AreEqual(stdin.close(), None)
    #    AreEqual(stdout.read(), 'abc\nhello\n')
    #    AreEqual(stdout.close(), None)
    #    AreEqual(stderr.read(), '')
    #    AreEqual(stderr.close(), None)

    tmpfile = 'tmpfile.tmp'
    f = open(tmpfile, 'w')
    f.close()
    nt.unlink(tmpfile)
    try:
        nt.chmod('tmpfile.tmp', 256)
    except Exception:
        pass  #should throw when trying to access file deleted by unlink
    else:
        Assert(
            False,
            "Error! Trying to access file deleted by unlink should have thrown."
        )

    try:
        tmpfile = "tmpfile2.tmp"
        f = open(tmpfile, "w")
        f.write("testing chmod")
        f.close()
        nt.chmod(tmpfile, 256)
        AssertError(OSError, nt.unlink, tmpfile)
        nt.chmod(tmpfile, 128)
        nt.unlink(tmpfile)
        AssertError(IOError, file, tmpfile)
    finally:
        try:
            nt.chmod(tmpfile, 128)
            nt.unlink(tmpfile)
        except Exception, e:
            print "exc", e
Пример #9
0
def test_popen():
    # open a pipe just for reading...
    pipe_modes = [["ping 127.0.0.1", "r"],
                  ["ping 127.0.0.1"]]
    if is_cli:
        pipe_modes.append(["ping 127.0.0.1", ""])
        
    for args in pipe_modes:
        x = nt.popen(*args)
        text = x.read()
        Assert(text.lower().index('pinging') != -1)
        AreEqual(x.close(), None)

    # write to a pipe
    x = nt.popen('sort', 'w')
    x.write('hello\nabc\n')
    x.close()

    # bug 1146
    #x = nt.popen('sort', 'w')
    #x.write('hello\nabc\n')
    #AreEqual(x.close(), None)

    # once w/ default mode
    AssertError(ValueError, nt.popen, "ping 127.0.0.1", "a")

    # popen uses cmd.exe to run stuff -- at least sometimes
    dir_pipe = nt.popen('dir')
    dir_pipe.read()
    dir_pipe.close()

    # once w/ no mode
    stdin, stdout = nt.popen2('sort')
    stdin.write('hello\nabc\n')
    AreEqual(stdin.close(), None)
    AreEqual(stdout.read(), 'abc\nhello\n')
    AreEqual(stdout.close(), None)

    # bug 1146
    # and once w/ each mode
    #for mode in ['b', 't']:
    #    stdin, stdout = nt.popen2('sort', mode)
    #    stdin.write('hello\nabc\n')
    #    AreEqual(stdin.close(), None)
    #    AreEqual(stdout.read(), 'abc\nhello\n')
    #    AreEqual(stdout.close(), None)
        

    # popen3: once w/ no mode
    stdin, stdout, stderr = nt.popen3('sort')
    stdin.write('hello\nabc\n')
    AreEqual(stdin.close(), None)
    AreEqual(stdout.read(), 'abc\nhello\n')
    AreEqual(stdout.close(), None)
    AreEqual(stderr.read(), '')
    AreEqual(stderr.close(), None)

    # bug 1146
    # popen3: and once w/ each mode
    #for mode in ['b', 't']:
    #    stdin, stdout, stderr = nt.popen3('sort', mode)
    #    stdin.write('hello\nabc\n')
    #    AreEqual(stdin.close(), None)
    #    AreEqual(stdout.read(), 'abc\nhello\n')
    #    AreEqual(stdout.close(), None)
    #    AreEqual(stderr.read(), '')
    #    AreEqual(stderr.close(), None)
    
    tmpfile = 'tmpfile.tmp'
    f = open(tmpfile, 'w')
    f.close()
    nt.unlink(tmpfile)
    try:
        nt.chmod('tmpfile.tmp', 256)
    except Exception:
        pass #should throw when trying to access file deleted by unlink
    else:
        Assert(False,"Error! Trying to access file deleted by unlink should have thrown.")

    try:
        tmpfile = "tmpfile2.tmp"
        f = open(tmpfile, "w")
        f.write("testing chmod")
        f.close()
        nt.chmod(tmpfile, 256)
        AssertError(OSError, nt.unlink, tmpfile)
        nt.chmod(tmpfile, 128)
        nt.unlink(tmpfile)
        AssertError(IOError, file, tmpfile)
    finally:
        try:
            nt.chmod(tmpfile, 128)
            nt.unlink(tmpfile)
        except Exception, e:
            print "exc", e