Exemplo n.º 1
0
def test_mkdir_negative():
    nt.mkdir("dir_create_test")
    try:
        nt.mkdir("dir_create_test")
        AssertUnreachable("Cannot create the same directory twice")
    except WindowsError, e:
        AreEqual(e.errno, 17)
Exemplo n.º 2
0
 def execv(filename, args):
     #  Create an O_TEMPORARY file and pass its name to the slave process.
     #  When this master process dies, the file will be deleted and the
     #  slave process will know to terminate.
     try:
         tdir = environ["TEMP"]
     except:
         tdir = None
     if tdir:
         try:
             nt.mkdir(pathjoin(tdir, "esky-slave-procs"), 0600)
         except EnvironmentError:
             pass
         if exists(pathjoin(tdir, "esky-slave-procs")):
             flags = nt.O_CREAT | nt.O_EXCL | nt.O_TEMPORARY | nt.O_NOINHERIT
             for i in xrange(10):
                 tfilenm = "slave-%d.%d.txt" % (nt.getpid(), i)
                 tfilenm = pathjoin(tdir, "esky-slave-procs", tfilenm)
                 try:
                     os_open(tfilenm, flags, 0600)
                     args.insert(1, tfilenm)
                     args.insert(1, "--esky-slave-proc")
                     break
                 except EnvironmentError:
                     pass
     # Ensure all arguments are quoted (to allow spaces in paths)
     for i, arg in enumerate(args):
         if arg[0] != '"' and args[-1] != '"':
             args[i] = '"{}"'.format(arg)
     res = spawnv(P_WAIT, filename, args)
     _exit_code[0] = res
     raise SystemExit(res)
def mkdir(path):
    if -1 == path.find("\\" + moddir + "\\"): return 0
    try:
        nt.mkdir(path)
    except:
        pass
    return exists(path)
Exemplo n.º 4
0
def test_mkdir_negative():
    nt.mkdir("dir_create_test")
    try:
        nt.mkdir("dir_create_test")
        AssertUnreachable("Cannot create the same directory twice")
    except WindowsError, e:
        AreEqual(e.errno, 17)
Exemplo n.º 5
0
def test_cp20174():
    cp20174_path = testpath.public_testdir + r"\cp20174"
    
    try:
        nt.mkdir(cp20174_path)
        
        cp20174_init = cp20174_path + r"\__init__.py"
        write_to_file(cp20174_init, "import a")
        
        cp20174_a = cp20174_path + r"\a.py"
        write_to_file(cp20174_a, """
from property import x
class C:
    def _get_x(self): return x
    x = property(_get_x)
""")
        
        cp20174_property = cp20174_path + r"\property.py"
        write_to_file(cp20174_property, "x=1")
        
        import cp20174
        AreEqual(cp20174.property.x, 1)
        
    finally:
        for x in nt.listdir(cp20174_path):
            nt.unlink(cp20174_path + "\\" + x)
        nt.rmdir(cp20174_path)
Exemplo n.º 6
0
def ensure_directory_present(path): 
    path = fullpath(path)
    p = ''
    for x in path.split(separator):
        p += x + separator
        if not directory_exists(p):
            nt.mkdir(p)
Exemplo n.º 7
0
 def execv(filename,args):
     #  Create an O_TEMPORARY file and pass its name to the slave process.
     #  When this master process dies, the file will be deleted and the
     #  slave process will know to terminate.
     tdir = nt.environ.get("TEMP",None)
     if tdir:
         tfile = None
         try:
             nt.mkdir(pathjoin(tdir,"esky-slave-procs"))
         except EnvironmentError:
             pass
         if exists(pathjoin(tdir,"esky-slave-procs")):
             flags = nt.O_CREAT|nt.O_EXCL|nt.O_TEMPORARY|nt.O_NOINHERIT
             for i in xrange(10):
                 tfilenm = "slave-%d.%d.txt" % (nt.getpid(),i,)
                 tfilenm = pathjoin(tdir,"esky-slave-procs",tfilenm)
                 try:
                     tfile = nt.open(tfilenm,flags)
                     break
                 except EnvironmentError:
                     raise
                     pass
     if tdir and tfile:
         args.insert(1,tfilenm)
         args.insert(1,"--esky-slave-proc")
     res = spawnv(P_WAIT,filename,args)
     raise SystemExit(res)
Exemplo n.º 8
0
def test_cp20174():
    cp20174_path = testpath.public_testdir + r"\cp20174"

    try:
        nt.mkdir(cp20174_path)

        cp20174_init = cp20174_path + r"\__init__.py"
        write_to_file(cp20174_init, "import a")

        cp20174_a = cp20174_path + r"\a.py"
        write_to_file(
            cp20174_a, """
from property import x
class C:
    def _get_x(self): return x
    x = property(_get_x)
""")

        cp20174_property = cp20174_path + r"\property.py"
        write_to_file(cp20174_property, "x=1")

        import cp20174
        AreEqual(cp20174.property.x, 1)

    finally:
        for x in nt.listdir(cp20174_path):
            nt.unlink(cp20174_path + "\\" + x)
        nt.rmdir(cp20174_path)
Exemplo n.º 9
0
def ensure_directory_present(path): 
    path = fullpath(path)
    p = ''
    for x in path.split(separator):
        p += x + separator
        if not directory_exists(p):
            nt.mkdir(p)
Exemplo n.º 10
0
def test_chmod():
    # chmod tests:
    # BUG 828,830
    nt.mkdir('tmp2')
    nt.chmod('tmp2', 256) # NOTE: change to flag when stat is implemented
    AssertError(OSError, lambda:nt.rmdir('tmp2'))
    nt.chmod('tmp2', 128)
    nt.rmdir('tmp2')
Exemplo n.º 11
0
def test_chmod():
    # chmod tests:
    # BUG 828,830
    nt.mkdir('tmp2')
    nt.chmod('tmp2', 256)  # NOTE: change to flag when stat is implemented
    AssertError(OSError, lambda: nt.rmdir('tmp2'))
    nt.chmod('tmp2', 128)
    nt.rmdir('tmp2')
Exemplo n.º 12
0
    def test_getcwdb(self):
        self.assertEqual(nt.getcwdb(),nt.getcwd().encode())

        nt.mkdir('dir_create_test')
        if is_cli:
            self.assertEqual(nt.listdir(nt.getcwdb()).count('dir_create_test'), 1)
        else:
            self.assertEqual(nt.listdir(nt.getcwdb()).count(b'dir_create_test'), 1)
        nt.rmdir('dir_create_test')
Exemplo n.º 13
0
def test_cp24692():
    import errno, nt, stat
    dir_name = "cp24692_testdir"
    try:
        nt.mkdir(dir_name)
        nt.chmod(dir_name, stat.S_IREAD)
        try:
            nt.rmdir(dir_name)
        except WindowsError, e:
            pass
        AreEqual(e.errno, errno.EACCES)
Exemplo n.º 14
0
def test_cp24692():
    import errno, nt, stat
    dir_name = "cp24692_testdir"
    try:
        nt.mkdir(dir_name)
        nt.chmod(dir_name, stat.S_IREAD)
        try:
            nt.rmdir(dir_name)
        except WindowsError, e:
            pass
        AreEqual(e.errno, errno.EACCES)
Exemplo n.º 15
0
def test_chdir():
    currdir = nt.getcwd()
    nt.mkdir('tsd')
    nt.chdir('tsd')
    AreEqual(currdir+'\\tsd', nt.getcwd())
    nt.chdir(currdir)
    AreEqual(currdir, nt.getcwd())
    nt.rmdir('tsd')
    
    # the directory is empty or does not exist
    AssertErrorWithNumber(WindowsError, 22, lambda:nt.chdir(''))
    AssertErrorWithNumber(WindowsError, 2, lambda:nt.chdir('tsd'))
Exemplo n.º 16
0
    def test_chdir(self):
        currdir = nt.getcwd()
        nt.mkdir('tsd')
        nt.chdir('tsd')
        self.assertEqual(os.path.join(currdir, 'tsd'), nt.getcwd())
        nt.chdir(currdir)
        self.assertEqual(currdir, nt.getcwd())
        nt.rmdir('tsd')

        # the directory is empty or does not exist
        self.assertRaisesNumber(WindowsError, 22, lambda: nt.chdir(''))
        self.assertRaisesNumber(WindowsError, 2, lambda: nt.chdir('tsd'))
Exemplo n.º 17
0
 def test_chdir(self):
     currdir = nt.getcwd()
     nt.mkdir('tsd')
     nt.chdir('tsd')
     self.assertEqual(os.path.join(currdir, 'tsd'), nt.getcwd())
     nt.chdir(currdir)
     self.assertEqual(currdir, nt.getcwd())
     nt.rmdir('tsd')
     
     # the directory is empty or does not exist
     self.assertRaisesNumber(WindowsError, 22, lambda:nt.chdir(''))
     self.assertRaisesNumber(WindowsError, 2, lambda:nt.chdir('tsd'))
Exemplo n.º 18
0
def test_chdir():
    currdir = nt.getcwd()
    nt.mkdir('tsd')
    nt.chdir('tsd')
    AreEqual(currdir + '\\tsd', nt.getcwd())
    nt.chdir(currdir)
    AreEqual(currdir, nt.getcwd())
    nt.rmdir('tsd')

    # the directory is empty or does not exist
    AssertErrorWithNumber(WindowsError, 22, lambda: nt.chdir(''))
    AssertErrorWithNumber(WindowsError, 2, lambda: nt.chdir('tsd'))
Exemplo n.º 19
0
class NtTest(IronPythonTestCase):
    def test_computername(self):
        self.assertEqual(
            nt.environ.has_key('COMPUTERNAME')
            or nt.environ.has_key('computername'), True)

    def test_mkdir(self):
        nt.mkdir('dir_create_test')
        self.assertEqual(nt.listdir(nt.getcwd()).count('dir_create_test'), 1)

        nt.rmdir('dir_create_test')
        self.assertEqual(nt.listdir(nt.getcwd()).count('dir_create_test'), 0)

    def test_mkdir_negative(self):
        nt.mkdir("dir_create_test")
        try:
            nt.mkdir("dir_create_test")
            self.assertUnreachabale("Cannot create the same directory twice")
        except WindowsError, e:
            self.assertEqual(e.errno, 17)

        #if it fails once...it should fail again
        self.assertRaises(WindowsError, nt.mkdir, "dir_create_test")
        nt.rmdir('dir_create_test')
        nt.mkdir("dir_create_test")
        self.assertRaises(WindowsError, nt.mkdir, "dir_create_test")
        nt.rmdir('dir_create_test')
Exemplo n.º 20
0
def verifySaveDirectory(group, x=0, y=0):
    dir = wd("")
    if 'GameDatabase' in dir:
        filename = dir.replace('GameDatabase', 'Decks').replace(
            '383a6ac2-6e52-40a5-980f-fade09e4908b', 'Dragon Ball Z')
    else:
        filename = "Decks\Dragon Ball Z".join(dir.rsplit('OCTGN', 1))
    #notify(filename)
    try:
        nt.mkdir(filename)
    except:
        pass
    try:
        filename = filename + '\\GameStates'
        nt.mkdir(filename)
    except:
        pass
Exemplo n.º 21
0
def test_cp12009():
    import nt
    import shutil
    
    dir1 = "temp_test_stdmodules_dir"
    dir2 = dir1 + "2"
    
    nt.mkdir(dir1)
    f = open(dir1 + r"\stuff.txt", "w")
    f.close()
    
    try:
        shutil.copytree(dir1, dir2)
        Assert("stuff.txt" in nt.listdir(dir2))
    finally:
        for t_dir in [dir1, dir2]:
            nt.unlink(t_dir + r"\stuff.txt")
            nt.rmdir(t_dir)
Exemplo n.º 22
0
def test_cp12009():
    import nt
    import shutil

    dir1 = "temp_test_stdmodules_dir"
    dir2 = dir1 + "2"

    nt.mkdir(dir1)
    f = open(dir1 + r"\stuff.txt", "w")
    f.close()

    try:
        shutil.copytree(dir1, dir2)
        Assert("stuff.txt" in nt.listdir(dir2))
    finally:
        for t_dir in [dir1, dir2]:
            nt.unlink(t_dir + r"\stuff.txt")
            nt.rmdir(t_dir)
Exemplo n.º 23
0
def test_access():
    f = file('new_file_name', 'w')
    f.close()
    
    AreEqual(nt.access('new_file_name', nt.F_OK), True)
    AreEqual(nt.access('does_not_exist.py', nt.F_OK), False)

    nt.chmod('new_file_name', 0x100) # S_IREAD
    AreEqual(nt.access('new_file_name', nt.W_OK), False)
    nt.chmod('new_file_name', 0x80)  # S_IWRITE
        
    nt.unlink('new_file_name')
    
    nt.mkdir('new_dir_name')
    AreEqual(nt.access('new_dir_name', nt.R_OK), True)
    nt.rmdir('new_dir_name')
    
    AssertError(TypeError, nt.access, None, 1)
Exemplo n.º 24
0
def test_access():
    f = file('new_file_name', 'w')
    f.close()
    
    AreEqual(nt.access('new_file_name', nt.F_OK), True)
    AreEqual(nt.access('does_not_exist.py', nt.F_OK), False)

    nt.chmod('new_file_name', 0x100) # S_IREAD
    AreEqual(nt.access('new_file_name', nt.W_OK), False)
    nt.chmod('new_file_name', 0x80)  # S_IWRITE
        
    nt.unlink('new_file_name')
    
    nt.mkdir('new_dir_name')
    AreEqual(nt.access('new_dir_name', nt.R_OK), True)
    nt.rmdir('new_dir_name')
    
    AssertError(TypeError, nt.access, None, 1)
Exemplo n.º 25
0
def test_access():
    f = file("new_file_name", "w")
    f.close()

    AreEqual(nt.access("new_file_name", nt.F_OK), True)
    AreEqual(nt.access("does_not_exist.py", nt.F_OK), False)

    nt.chmod("new_file_name", 0x100)  # S_IREAD
    AreEqual(nt.access("new_file_name", nt.W_OK), False)
    nt.chmod("new_file_name", 0x80)  # S_IWRITE

    nt.unlink("new_file_name")

    nt.mkdir("new_dir_name")
    AreEqual(nt.access("new_dir_name", nt.R_OK), True)
    nt.rmdir("new_dir_name")

    AssertError(TypeError, nt.access, None, 1)
Exemplo n.º 26
0
 def __init__(self, prefix, size, header=""):
     from datetime import datetime
     now = datetime.now()
     import nt
     if not nt.environ.has_key("DLR_BIN"):
         self.directory = prefix
     else:
         self.directory = "%s_%02d%02d_%02d%02d_%d" % (prefix, now.month, now.day, now.hour, now.minute, now.microsecond)
     self.size = size
     self.header = header
     self.count = 0
     self.func_count = 0
     self.file_list = []
     self.func_lines = []
     self.current_file = None
     
     try:
         nt.mkdir(self.directory)
     except: pass
Exemplo n.º 27
0
 def __init__(self, prefix, size, header=""):
     from datetime import datetime
     now = datetime.now()
     import nt
     if not nt.environ.has_key("DLR_BIN"):
         self.directory = prefix
     else:
         self.directory = "%s_%02d%02d_%02d%02d_%d" % (prefix, now.month, now.day, now.hour, now.minute, now.microsecond)
     self.size = size
     self.header = header
     self.count = 0
     self.func_count = 0
     self.file_list = []
     self.func_lines = []
     self.current_file = None
     
     try:
         nt.mkdir(self.directory)
     except: pass
Exemplo n.º 28
0
    def __init__(self, name=None, get_moudle_name=None):
        '''name日志收集器名字,get_moudle_name要生成的日志文件的名字'''
        self.name = name
        """读取关于log的配置文件信息,包含日志输出路径,日志收集器收集级别,日志渠道输出级别,日志输出格式formmat"""
        self.log_set = Read_conf()
        self.log_ouyput_level = self.log_set.get("log", "log_output_level")
        self.log_level = self.log_set.get("log", "log_get_level")
        self.log_formatter = self.log_set.get("log", "log_formatter")

        if name != None:
            global new_name
            new_name = name
        if get_moudle_name != None:
            global moudle
            moudle = get_moudle_name
        """设置日志路径"""
        now_date = time.strftime('%Y_%m_%d')
        '''根据日期新建文件夹存放日志文件,可查看test_result下log_result下的日志生成结果'''
        path = constans.log_path + os.sep + now_date
        if not os.path.isdir(path):
            mkdir(path)
        file_path = path + os.sep + moudle + ".txt"
        """初始化"""

        self.logger = logging.getLogger(self.name)
        self.logger.setLevel(self.log_level)
        '''该判断,避免一条日志重复打印,可以去除if后看看打印的结果进行对比'''
        if not self.logger.handlers:
            """制定统一的输出格式:%(levelname)s 文本形式的日志级别
            %(asctime)s 字符串形式的当前时间。默认格式是 “2003-07-08 16:49:45,896”。逗号后面的是毫秒
            %(message)s  %(message)s 用户输出的消息"""
            fmt = logging.Formatter(self.log_formatter)
            """设置控制台日志(信息输出到控制台)"""
            cmd_h = logging.StreamHandler()
            cmd_h.setLevel(self.log_ouyput_level)
            cmd_h.setFormatter(fmt)
            """设置文件日志(输出到指定文件中)"""
            file_h = logging.FileHandler(file_path, encoding="utf8")  #指定日志路径
            file_h.setLevel(self.log_ouyput_level)
            file_h.setFormatter(fmt)
            """添加2种日志"""
            self.logger.addHandler(cmd_h)
            self.logger.addHandler(file_h)
Exemplo n.º 29
0
    def test_access(self):
        open('new_file_name', 'w').close()

        self.assertEqual(nt.access('new_file_name', nt.F_OK), True)
        self.assertEqual(nt.access('new_file_name', nt.R_OK), True)
        self.assertEqual(nt.access('does_not_exist.py', nt.F_OK), False)
        self.assertEqual(nt.access('does_not_exist.py', nt.R_OK), False)

        nt.chmod('new_file_name', 0x100) # S_IREAD
        self.assertEqual(nt.access('new_file_name', nt.W_OK), False)
        nt.chmod('new_file_name', 0x80)  # S_IWRITE

        nt.unlink('new_file_name')

        nt.mkdir('new_dir_name')
        self.assertEqual(nt.access('new_dir_name', nt.R_OK), True)
        nt.rmdir('new_dir_name')

        self.assertRaises(TypeError, nt.access, None, 1)
Exemplo n.º 30
0
    def __init__(self,
                 name=None,
                 get_moudle_name=None,
                 cmd_level=logging.DEBUG,
                 file_level=logging.DEBUG):
        self.name = name
        self.cmd_level = cmd_level
        self.file_level = file_level

        if name != None:
            global new_name
            new_name = name
        if get_moudle_name != None:
            global moudle
            moudle = get_moudle_name
        """设置日志路径"""
        now_date = time.strftime('%Y_%m_%d')
        path = Project_path().project_path(
        ) + "test_result" + os.sep + 'log' + os.sep + now_date
        if not os.path.isdir(path):
            mkdir(path)

        file_path = path + os.sep + moudle + ".txt"
        """初始化"""
        self.logger = logging.getLogger(self.name)
        self.logger.setLevel(logging.DEBUG)
        """制定统一的输出格式:%(levelname)s 文本形式的日志级别
        %(asctime)s 字符串形式的当前时间。默认格式是 “2003-07-08 16:49:45,896”。逗号后面的是毫秒
        %(message)s  %(message)s 用户输出的消息"""
        fmt = logging.Formatter('[%(asctime)s] [%(levelname)s] %(message)s',
                                '%Y_%m_%d %H_%M_%S')
        """设置控制台日志"""
        cmd_h = logging.StreamHandler()
        cmd_h.setLevel(self.cmd_level)
        cmd_h.setFormatter(fmt)
        """设置文件日志"""
        file_h = logging.FileHandler(file_path, encoding="utf8")  #指定日志路径
        file_h.setLevel(self.file_level)
        file_h.setFormatter(fmt)
        """添加2种日志"""
        self.logger.addHandler(cmd_h)
        self.logger.addHandler(file_h)
Exemplo n.º 31
0
 def __init__(self,name=None,get_moudle_name=None):
     self.name=name
     """读取关于log的配置文件信息,包含日志输出路径,日志收集器收集级别,日志渠道输出级别,日志输出格式formmat"""
     self.log_set=Read_conf().read_log("log.conf")
     self.log_level=self.log_set["log_get_level"]
     self.log_ouyput_level=self.log_set["log_output_level"]
     self.log_formatter=self.log_set["log_formatter"]
     if name!=None:
         global new_name
         new_name=name
     if get_moudle_name!=None:
         global moudle
         moudle=get_moudle_name
     """设置日志路径"""
     now_date=time.strftime('%Y_%m_%d')
     path=self.log_set["log_output_path"]+os.sep+now_date
     if not os.path.isdir(path):
         mkdir(path)    
     file_path=path+os.sep+moudle+".txt" 
     """初始化"""
     
     self.logger=logging.getLogger(self.name)   
     self.logger.setLevel(self.log_level)
     
     if not self.logger.handlers:
         """制定统一的输出格式:%(levelname)s 文本形式的日志级别
         %(asctime)s 字符串形式的当前时间。默认格式是 “2003-07-08 16:49:45,896”。逗号后面的是毫秒
         %(message)s  %(message)s 用户输出的消息"""
         fmt = logging.Formatter(self.log_formatter)
         """设置控制台日志"""     
         cmd_h=logging.StreamHandler()
         cmd_h.setLevel(self.log_ouyput_level)
         cmd_h.setFormatter(fmt)
         """设置文件日志"""
         file_h=logging.FileHandler(file_path,encoding="utf8")  #指定日志路径
         file_h.setLevel(self.log_ouyput_level)
         file_h.setFormatter(fmt)
         
         """添加2种日志"""
         self.logger.addHandler(cmd_h)
         self.logger.addHandler(file_h)
Exemplo n.º 32
0
 def main(self):
     try:
         dir = mkdir(self.local)
     except:
         print("is not empty")
     self.getPath()
     for x in range(0, len(self.paths)):
         html = self.getHtml(self.paths[x])
         self.getdata(html)
         for i in range(0, len(self.srcs)):
             self.mkfile(self.srcs[i], str(x), str(self.names[i]))
         self.srcs.clear()
         self.names.clear()
     print('process finished')
Exemplo n.º 33
0
def test_rename():
    # normal test
    handler = open("oldnamefile.txt", "w")
    handler.close()
    str_old = "oldnamefile.txt"
    dst = "newnamefile.txt"
    nt.rename(str_old, dst)
    AreEqual(nt.listdir(nt.getcwd()).count(dst), 1)
    AreEqual(nt.listdir(nt.getcwd()).count(str_old), 0)
    nt.remove(dst)

    # the destination name is a directory
    handler = open("oldnamefile.txt", "w")
    handler.close()
    str_old = "oldnamefile.txt"
    dst = "newnamefile.txt"
    nt.mkdir(dst)
    AssertError(OSError, nt.rename, str_old, dst)
    nt.rmdir(dst)
    nt.remove(str_old)

    # the dst already exists
    handler1 = open("oldnamefile.txt", "w")
    handler1.close()
    handler2 = open("newnamefile.txt", "w")
    handler2.close()
    str_old = "oldnamefile.txt"
    dst = "newnamefile.txt"
    AssertError(OSError, nt.rename, str_old, dst)
    nt.remove(str_old)
    nt.remove(dst)

    # the source file specified does not exist
    str_old = "oldnamefile.txt"
    dst = "newnamefile.txt"
    AssertError(OSError, nt.rename, str_old, dst)
Exemplo n.º 34
0
def test_rename():
    # normal test
    handler = open("oldnamefile.txt","w")
    handler.close()
    str_old = "oldnamefile.txt"
    dst = "newnamefile.txt"
    nt.rename(str_old,dst)
    AreEqual(nt.listdir(nt.getcwd()).count(dst), 1)
    AreEqual(nt.listdir(nt.getcwd()).count(str_old), 0)
    nt.remove(dst)
    
    # the destination name is a directory
    handler = open("oldnamefile.txt","w")
    handler.close()
    str_old = "oldnamefile.txt"
    dst = "newnamefile.txt"
    nt.mkdir(dst)
    AssertError(OSError, nt.rename,str_old,dst)
    nt.rmdir(dst)
    nt.remove(str_old)
    
    # the dst already exists
    handler1 = open("oldnamefile.txt","w")
    handler1.close()
    handler2 = open("newnamefile.txt","w")
    handler2.close()
    str_old = "oldnamefile.txt"
    dst = "newnamefile.txt"
    AssertError(OSError, nt.rename,str_old,dst)
    nt.remove(str_old)
    nt.remove(dst)
    
    # the source file specified does not exist
    str_old = "oldnamefile.txt"
    dst = "newnamefile.txt"
    AssertError(OSError, nt.rename,str_old,dst)
Exemplo n.º 35
0
def test_file_encodings_negative():
    '''
    TODO:
    - we should use *.py files in the correct encoding instead
    of dynamically generating ASCII files
    - need variations on the encoding names
    '''
    import sys
    import nt
    sys.path.append(nt.getcwd() + "\\tmp_encodings")
    try:
        nt.mkdir(nt.getcwd() + "\\tmp_encodings")
    except:
        pass
             
    try:
        #negative case
        f = open(nt.getcwd() + "\\tmp_encodings\\" + "bad_encoding.py", "w")
        f.write("# coding: bad")
        f.close()
        AssertError(SyntaxError, __import__, "bad_encoding")
    finally:
        #cleanup
        sys.path.remove(nt.getcwd() + "\\tmp_encodings")
Exemplo n.º 36
0
def test_file_encodings_negative():
    '''
    TODO:
    - we should use *.py files in the correct encoding instead
    of dynamically generating ASCII files
    - need variations on the encoding names
    '''
    import sys
    import nt
    sys.path.append(nt.getcwd() + "\\tmp_encodings")
    try:
        nt.mkdir(nt.getcwd() + "\\tmp_encodings")
    except:
        pass
             
    try:
        #negative case
        f = open(nt.getcwd() + "\\tmp_encodings\\" + "bad_encoding.py", "w")
        f.write("# coding: bad")
        f.close()
        AssertError(SyntaxError, __import__, "bad_encoding")
    finally:
        #cleanup
        sys.path.remove(nt.getcwd() + "\\tmp_encodings")
Exemplo n.º 37
0
def test_mkdir_negative():
    nt.mkdir("dir_create_test")
    try:
        nt.mkdir("dir_create_test")
        AssertUnreachable("Cannot create the same directory twice")
    except WindowsError as e:
        AreEqual(e.errno, 17)

    #if it fails once...it should fail again
    AssertError(WindowsError, nt.mkdir, "dir_create_test")
    nt.rmdir('dir_create_test')
    nt.mkdir("dir_create_test")
    AssertError(WindowsError, nt.mkdir, "dir_create_test")
    nt.rmdir('dir_create_test')
Exemplo n.º 38
0
    def test_mkdir_negative(self):
        nt.mkdir("dir_create_test")
        try:
            nt.mkdir("dir_create_test")
            self.assertUnreachabale("Cannot create the same directory twice")
        except WindowsError as e:
            self.assertEqual(e.errno, 17)

        #if it fails once...it should fail again
        self.assertRaises(WindowsError, nt.mkdir, "dir_create_test")
        nt.rmdir('dir_create_test')
        nt.mkdir("dir_create_test")
        self.assertRaises(WindowsError, nt.mkdir, "dir_create_test")
        nt.rmdir('dir_create_test')
Exemplo n.º 39
0
 def test_getcwdu(self):
     self.assertEqual(nt.getcwd(),nt.getcwdu())
     
     nt.mkdir('dir_create_test')
     self.assertEqual(nt.listdir(nt.getcwdu()).count('dir_create_test'), 1)
     nt.rmdir('dir_create_test')
Exemplo n.º 40
0
skiptest("silverlight")
skiptest("win32")
from iptest.console_util import IronPythonInstance
import sys
import nt
import re
from System import *
import os

# Test that IronPython console behaves as expected (command line argument processing etc.).

# Get a temporary directory in which the tests can scribble.
tmpdir = Environment.GetEnvironmentVariable("TEMP")
tmpdir = IO.Path.Combine(tmpdir, "IronPython")
if not os.path.exists(tmpdir):
    nt.mkdir(tmpdir)

# Name of a temporary file used to capture console output.
tmpfile = IO.Path.Combine(tmpdir, "tmp_output.txt")

# Name of a batch file used to execute the console to workaround the fact we have no way to redirect stdout
# from nt.spawnl.
batfile = IO.Path.Combine(tmpdir, "__runconsole.bat")

f = file(batfile, "w")
f.write("@" + sys.executable + " >" + tmpfile + " 2>&1 %*\n")
f.close()

############################################################
# Runs the console with the given tuple of arguments and verifies that the output and exit code are as
# specified. The expected_output argument can be specified in various ways:
Exemplo n.º 41
0
            "-------------------------------------------------------\n")
        bug_report.write(
            """Complete list of module attributes that should be removed 
from IronPython:
""")
        for x in needs_to_be_removed:
            bug_report.write("    " + x)

    bug_report.close()
    return bug_report_name


#--MAIN------------------------------------------------------------------------

try:
    nt.mkdir(nt.getcwd() + "\\bug_reports")
except:
    pass

for mod_name in MODULES:
    #--First figure out what's missing and what's extra in a module
    #  and write this to disk.
    ipy_should_impl_filename = "bug_reports\\mod_to_impl_%s.log" % mod_name
    ipy_should_not_impl_filename = "bug_reports\\mod_rm_impl_%s.log" % mod_name
    IPY_SHOULD_IMPL = open(ipy_should_impl_filename, "w")
    IPY_SHOULD_NOT_IMPL = open(ipy_should_not_impl_filename, "w")

    get_cpython_results(mod_name)

    IPY_SHOULD_IMPL.close()
    IPY_SHOULD_NOT_IMPL.close()
Exemplo n.º 42
0
import requests
import os
from nt import mkdir
if __name__=='__main__':
    dir = 'C:\\Users\\mlq\\Desktop\\'
    url = "http://image.nationalgeographic.com.cn/2017/0322/20170322120238770.jpg"
    path = dir+url.split('/')[-1]
    if not os.path.exists(dir):
        mkdir(dir)
    if not os.path.exists(path):
        #kv = {'User-Agent','Mozella/5.0'}
        #headers=kv
        r = requests.get(url)
        with open(path,'wb') as f:
            f.write(r.content)
    else:
        print('文件已经存在了')   
Exemplo n.º 43
0
        bug_report.write("-------------------------------------------------------\n")
        bug_report.write("""Complete list of module attributes that should be removed 
from IronPython:
""")
        for x in needs_to_be_removed:
            bug_report.write("    " + x)
    
    bug_report.close()
    return bug_report_name
    


#--MAIN------------------------------------------------------------------------

try:
    nt.mkdir(nt.getcwd() + "\\bug_reports")
except:
    pass

for mod_name in MODULES:
    #--First figure out what's missing and what's extra in a module
    #  and write this to disk.
    ipy_should_impl_filename = "bug_reports\\mod_to_impl_%s.log" % mod_name
    ipy_should_not_impl_filename = "bug_reports\\mod_rm_impl_%s.log" % mod_name
    IPY_SHOULD_IMPL = open(ipy_should_impl_filename, "w")
    IPY_SHOULD_NOT_IMPL = open(ipy_should_not_impl_filename, "w")

    get_cpython_results(mod_name)
    
    IPY_SHOULD_IMPL.close()
    IPY_SHOULD_NOT_IMPL.close()
Exemplo n.º 44
0
    def test_getcwdu(self):
        self.assertEqual(nt.getcwd(), nt.getcwdu())

        nt.mkdir('dir_create_test')
        self.assertEqual(nt.listdir(nt.getcwdu()).count('dir_create_test'), 1)
        nt.rmdir('dir_create_test')
Exemplo n.º 45
0
    
    nt.rmdir('dir_create_test')
    AreEqual(nt.listdir(nt.getcwd()).count('dir_create_test'), 0)

def test_mkdir_negative():
    nt.mkdir("dir_create_test")
    try:
        nt.mkdir("dir_create_test")
        AssertUnreachable("Cannot create the same directory twice")
    except WindowsError, e:
        AreEqual(e.errno, 17)
        
    #if it fails once...it should fail again
    AssertError(WindowsError, nt.mkdir, "dir_create_test")
    nt.rmdir('dir_create_test')
    nt.mkdir("dir_create_test")
    AssertError(WindowsError, nt.mkdir, "dir_create_test")
    nt.rmdir('dir_create_test')

def test_listdir():
    AssertError(TypeError, nt.listdir, None)
    if is_cpython: #http://ironpython.codeplex.com/workitem/28207
        AreEqual(nt.listdir(nt.getcwd()), nt.listdir('.'))
    else:
        AreEqual(nt.listdir(''), nt.listdir('.'))

# stat,lstat
def test_stat():
    # stat
    AssertError(nt.error, nt.stat, 'doesnotexist.txt')
        
Exemplo n.º 46
0
def test_getcwdu():
    AreEqual(nt.getcwd(), nt.getcwdu())

    nt.mkdir('dir_create_test')
    AreEqual(nt.listdir(nt.getcwdu()).count('dir_create_test'), 1)
    nt.rmdir('dir_create_test')
Exemplo n.º 47
0
def test_mkdir():
    nt.mkdir("dir_create_test")
    AreEqual(nt.listdir(nt.getcwd()).count("dir_create_test"), 1)

    nt.rmdir("dir_create_test")
    AreEqual(nt.listdir(nt.getcwd()).count("dir_create_test"), 0)
Exemplo n.º 48
0
def test_getcwdu():
    AreEqual(nt.getcwd(),nt.getcwdu())
    
    nt.mkdir('dir_create_test')
    AreEqual(nt.listdir(nt.getcwdu()).count('dir_create_test'), 1)
    nt.rmdir('dir_create_test')
Exemplo n.º 49
0
    nt.rmdir('dir_create_test')
    AreEqual(nt.listdir(nt.getcwd()).count('dir_create_test'), 0)


def test_mkdir_negative():
    nt.mkdir("dir_create_test")
    try:
        nt.mkdir("dir_create_test")
        AssertUnreachable("Cannot create the same directory twice")
    except WindowsError, e:
        AreEqual(e.errno, 17)

    #if it fails once...it should fail again
    AssertError(WindowsError, nt.mkdir, "dir_create_test")
    nt.rmdir('dir_create_test')
    nt.mkdir("dir_create_test")
    AssertError(WindowsError, nt.mkdir, "dir_create_test")
    nt.rmdir('dir_create_test')


def test_listdir():
    AssertError(TypeError, nt.listdir, None)
    AreEqual(nt.listdir(nt.getcwd()), nt.listdir('.'))


# stat,lstat
def test_stat():
    # stat
    AssertError(nt.error, nt.stat, 'doesnotexist.txt')

    #lstat
Exemplo n.º 50
0
skiptest("silverlight")
skiptest("win32")
from iptest.console_util import IronPythonInstance
import sys
import nt
import re
from System import *
import os

# Test that IronPython console behaves as expected (command line argument processing etc.).

# Get a temporary directory in which the tests can scribble.
tmpdir = Environment.GetEnvironmentVariable("TEMP")
tmpdir = IO.Path.Combine(tmpdir, "IronPython")
if not os.path.exists(tmpdir):
    nt.mkdir(tmpdir)

# Name of a temporary file used to capture console output.
tmpfile = IO.Path.Combine(tmpdir, "tmp_output.txt")

# Name of a batch file used to execute the console to workaround the fact we have no way to redirect stdout
# from nt.spawnl.
batfile = IO.Path.Combine(tmpdir, "__runconsole.bat")

f = file(batfile, "w")
f.write("@" + sys.executable + " >" + tmpfile + " 2>&1 %*\n")
f.close()


############################################################
# Runs the console with the given tuple of arguments and verifies that the output and exit code are as