예제 #1
0
파일: nt_test.py 프로젝트: 89sos98/main
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)
예제 #2
0
def directory_exists(path):
    if sys.platform=="win32":
        return nt.access(path, nt.F_OK)
    else:
        try:    
            nt.stat(path)
            return True
        except: 
            return False
예제 #3
0
def file_exists(file):
    if sys.platform=="win32":
        return nt.access(file, nt.F_OK)
    else:
        try:    
            nt.stat(file)
            return True
        except: 
            return False
예제 #4
0
def directory_exists(path):
    if sys.platform=="win32":
        return nt.access(path, nt.F_OK)
    else:
        try:    
            nt.stat(path)
            return True
        except: 
            return False
예제 #5
0
def file_exists(file):
    if sys.platform=="win32":
        return nt.access(file, nt.F_OK)
    else:
        try:    
            nt.stat(file)
            return True
        except: 
            return False
예제 #6
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)
예제 #7
0
def run_module(modToRun, init_globals=None, run_name = '__main__', alter_sys = True):
    if alter_sys:
        for o in sys.path:
            libpath = o + '\\' + modToRun + '.py'
            if nt.access(libpath, nt.F_OK):
                sys.argv[0] = libpath
                break
    
    __import__(modToRun)
예제 #8
0
파일: nt_test.py 프로젝트: slide/main
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)
예제 #9
0
def run_module(modToRun,
               init_globals=None,
               run_name='__main__',
               alter_sys=True):
    if alter_sys:
        for o in sys.path:
            libpath = o + '\\' + modToRun + '.py'
            if nt.access(libpath, nt.F_OK):
                sys.argv[0] = libpath
                break

    __import__(modToRun)
예제 #10
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)