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)
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)
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')
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')
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')
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')
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)
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'))
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'))
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'))
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'))
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')
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')
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)
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)
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)
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)
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)
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)
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')
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) finally: nt.chmod(dir_name, stat.S_IWRITE) nt.rmdir(dir_name) # TODO: this test needs to run against Dev10 builds as well @skip("win32") def test_cp22735(): import System if System.Environment.Version.Major < 4: clr.AddReference("System.Core") from System import Func #------------------------------------------------------------------------------ #--General coverage. These need to be extended. def test_xxsubtype_bench(): import xxsubtype
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)
f.close() for mode in ('wb', 'w'): f = open(fsync_file_name, mode) nt.fsync(f.fileno()) f.close() nt.unlink(fsync_file_name) # fsync on pipe ends r, w = nt.pipe() AssertError(OSError, nt.fsync, r) nt.write(w, '1') nt.fsync(w) nt.close(w) nt.close(r) #------------------------------------------------------------------------------ try: run_test(__name__) finally: #test cleanup - the test functions create the following directories and if any of them #fail, the directories may not necessarily be removed. for this reason we try to remove #them again for temp_dir in ['dir_create_test', 'tsd', 'tmp2', 'newnamefile.txt']: try: nt.rmdir(temp_dir) except: pass
f.close() for mode in ('wb', 'w'): f = open(fsync_file_name, mode) nt.fsync(f.fileno()) f.close() nt.unlink(fsync_file_name) # fsync on pipe ends r,w = nt.pipe() self.assertRaises(OSError, nt.fsync, r) nt.write(w, '1') nt.fsync(w) nt.close(w) nt.close(r) #------------------------------------------------------------------------------ try: run_test(__name__) finally: #test cleanup - the test functions create the following directories and if any of them #fail, the directories may not necessarily be removed. for this reason we try to remove #them again for temp_dir in ['dir_create_test', 'tsd', 'tmp2', 'newnamefile.txt']: try: nt.rmdir(temp_dir) except: pass
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')
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')
def test_cp15803(): ''' ''' _testdir = 'cp15803' pickle_file = path_combine(testpath.public_testdir, "cp15803.pickle") module_txt = """ class K%s(object): static_member = 1 def __init__(self): self.member = 2 %s = K%s() """ _testdir_init = path_combine(testpath.public_testdir, _testdir, '__init__.py') write_to_file(_testdir_init, module_txt % ("", "FROM_INIT", "")) _testdir_mod = path_combine(testpath.public_testdir, _testdir, 'mod.py') write_to_file(_testdir_mod, module_txt % ("Mod", "FROM_MOD", "Mod") + """ from cp15803 import K FROM_INIT_IN_MOD = K() """ ) _testdir_sub = path_combine(testpath.public_testdir, _testdir, 'sub') _testdir_sub_init = path_combine(_testdir_sub, '__init__.py') write_to_file(_testdir_sub_init) _testdir_sub_submod = path_combine(_testdir_sub, 'submod.py') write_to_file(_testdir_sub_submod, module_txt % ("SubMod", "FROM_SUB_MOD", "SubMod") + """ from cp15803 import mod FROM_MOD_IN_SUBMOD = mod.KMod() """ ) import cp15803 import cp15803.mod import cp15803.sub.submod import cp15803.sub.submod as newname try: for x in [ cp15803.K(), cp15803.FROM_INIT, cp15803.mod.KMod(), cp15803.mod.FROM_MOD, cp15803.mod.K(), cp15803.mod.FROM_INIT_IN_MOD, cp15803.sub.submod.KSubMod(), cp15803.sub.submod.FROM_SUB_MOD, cp15803.sub.submod.FROM_MOD_IN_SUBMOD, cp15803.sub.submod.mod.KMod(), cp15803.sub.submod.mod.FROM_MOD, cp15803.sub.submod.mod.K(), cp15803.sub.submod.mod.FROM_INIT_IN_MOD, newname.KSubMod(), newname.FROM_SUB_MOD, newname.FROM_MOD_IN_SUBMOD, newname.mod.KMod(), newname.mod.FROM_MOD, newname.mod.K(), newname.mod.FROM_INIT_IN_MOD, ]: with open(pickle_file, "w") as f: cPickle.dump(x, f) with open(pickle_file, "r") as f: x_unpickled = cPickle.load(f) AreEqual(x.__class__.__name__, x_unpickled.__class__.__name__) AreEqual(x.static_member, x_unpickled.static_member) AreEqual(x.member, x_unpickled.member) finally: import nt try: nt.unlink(pickle_file) for f_name in [ _testdir_init, _testdir_mod, _testdir_sub_init, _testdir_sub_submod, ]: nt.unlink(f_name) if sys.platform=="win32": nt.unlink(f_name + "c") for dir_name in [ _testdir_sub, _testdir]: nt.rmdir(dir_name) except: pass
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')
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')
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) 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')
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():
"ENOENT") 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) finally: nt.chmod(dir_name, stat.S_IWRITE) nt.rmdir(dir_name) # TODO: this test needs to run against Dev10 builds as well @skip("win32") def test_cp22735(): import System if System.Environment.Version.Major < 4: clr.AddReference("System.Core") from System import Func #------------------------------------------------------------------------------ #--General coverage. These need to be extended. def test_xxsubtype_bench(): import xxsubtype AreEqual(type(xxsubtype.bench(xxsubtype, "bench")), float)