Ejemplo n.º 1
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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 8
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)
Ejemplo n.º 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)
Ejemplo n.º 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)