예제 #1
0
    def test_fsync(self):
        fsync_file_name = 'text_fsync.txt'
        fd = nt.open(fsync_file_name, nt.O_WRONLY | nt.O_CREAT)

        # negative test, make sure it raises on invalid (closed) fd
        try:
            nt.close(fd+1)
        except:
            pass
        self.assertRaises(OSError, nt.fsync, fd+1)

        # BUG (or implementation detail)
        # On a posix system, once written to a file descriptor
        # it can be read using another fd without any additional intervention.
        # In case of IronPython the data lingers in a stream which
        # is used to simulate file descriptor.
        fd2 = nt.open(fsync_file_name, nt.O_RDONLY)
        self.assertEqual(nt.read(fd2, 1), b'')

        nt.write(fd, b'1')
        if is_cli:
            self.assertEqual(nt.read(fd2, 1), b'') # this should be visible right away, but is not
        nt.fsync(fd)
        self.assertEqual(nt.read(fd2, 1), b'1')

        nt.close(fd)
        nt.close(fd2)

        # fsync on read file descriptor
        fd = nt.open(fsync_file_name, nt.O_RDONLY)
        if not is_cli:
            self.assertRaises(OSError, nt.fsync, fd)
        nt.close(fd)

        # fsync on rdwr file descriptor
        fd = nt.open(fsync_file_name, nt.O_RDWR)
        nt.fsync(fd)
        nt.close(fd)

        # fsync on derived fd
        if not is_cli:
            for mode in ('rb', 'r'):
                with open(fsync_file_name, mode) as f:
                    self.assertRaises(OSError, nt.fsync, f.fileno())

        for mode in ('wb', 'w'):
            with open(fsync_file_name, mode) as f:
                nt.fsync(f.fileno())

        nt.unlink(fsync_file_name)

        # fsync on pipe ends
        r,w = nt.pipe()
        if not is_cli:
            self.assertRaises(OSError, nt.fsync, r)
        nt.write(w, b'1')
        if False:
            nt.fsync(w) # this blocks
        nt.close(w)
        nt.close(r)
예제 #2
0
    def test_fsync(self):
        fsync_file_name = 'text_fsync.txt'
        fd = nt.open(fsync_file_name, nt.O_WRONLY | nt.O_CREAT)

        # negative test, make sure it raises on invalid (closed) fd
        try:
            nt.close(fd+1)
        except:
            pass
        self.assertRaises(OSError, nt.fsync, fd+1)

        # BUG (or implementation detail)
        # On a posix system, once written to a file descriptor
        # it can be read using another fd without any additional intervention.
        # In case of IronPython the data lingers in a stream which
        # is used to simulate file descriptor.
        fd2 = nt.open(fsync_file_name, nt.O_RDONLY)
        self.assertEqual(nt.read(fd2, 1), '')

        nt.write(fd, '1')
        self.assertEqual(nt.read(fd2, 1), '') # this should be visible right away, but is not
        nt.fsync(fd)
        self.assertEqual(nt.read(fd2, 1), '1')

        nt.close(fd)
        nt.close(fd2)

        # fsync on read file descriptor
        fd = nt.open(fsync_file_name, nt.O_RDONLY)
        self.assertRaises(OSError, nt.fsync, fd)
        nt.close(fd)

        # fsync on rdwr file descriptor
        fd = nt.open(fsync_file_name, nt.O_RDWR)
        nt.fsync(fd)
        nt.close(fd)

        # fsync on derived fd
        for mode in ('rb', 'r'):
            f = open(fsync_file_name, mode)
            self.assertRaises(OSError, nt.fsync, f.fileno())
            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)
예제 #3
0
def GetShipList(dir = None):
	import nt
	import strop
	
	if (not dir is None):
		loaddir = dir
	else:
		loaddir = "scripts\Custom"
		
	ships = []
	
	f = nt.open(loaddir + "\ships.txt", nt.O_RDONLY)
	l = nt.lseek((f, 0, 2))
	nt.lseek((f, 0, 0))
	s = nt.read((f, l))
	list = strop.split(s)
	nt.close(f)
	
	for ship in list:
		s = strop.split(ship, '.')
		if (len(s)>1) and ((s[-1] == 'pyc') or (s[-1] == 'py')):
			shipname = s[0]
			pModule = __import__('ships.'+shipname)
			
			if (hasattr(pModule, 'GetShipStats')):
				stats = pModule.GetShipStats()
			
				if (shipname != '__init__') and (ships.count([shipname, stats["Name"]]) == 0):
					ships.append([shipname, stats["Name"]])
	
	ships.sort()

	return ships
예제 #4
0
파일: test_file.py 프로젝트: mdavid/dlr
def test_coverage():
    f = file(temp_file, 'w')
    Assert(str(f).startswith("<open file '%s', mode 'w'" % temp_file))
    Assert(f.fileno() <> -1)
    Assert(f.fileno() <> 0)

    # write
    AssertError(TypeError, f.writelines, [3])
    f.writelines(["firstline\n"])

    f.close()
    Assert(str(f).startswith("<closed file '%s', mode 'w'" % temp_file))

    # append
    f = file(temp_file, 'a+')
    f.writelines(['\n', 'secondline\n'])

    pos = len('secondline\n') + 1
    f.seek(-1 * pos, 1)

    f.writelines(['thirdline\n'])
    f.close()

    # read
    f = file(temp_file, 'r+', 512)
    f.seek(-1 * pos - 2, 2)

    AreEqual(f.readline(), 'e\n')
    AreEqual(f.readline(5), 'third')
    AreEqual(f.read(-1), 'line\n')
    AreEqual(f.read(-1), '')
    f.close()

    # read
    f = file(temp_file, 'rb', 512)
    f.seek(-1 * pos - 2, 2)

    AreEqual(f.readline(), 'e\r\n')
    AreEqual(f.readline(5), 'third')
    AreEqual(f.read(-1), 'line\r\n')
    AreEqual(f.read(-1), '')
    f.close()

    ## file op in nt    
    nt.unlink(temp_file)

    fd = nt.open(temp_file, nt.O_CREAT | nt.O_WRONLY)
    nt.write(fd, "hello ")
    nt.close(fd)

    fd = nt.open(temp_file, nt.O_APPEND | nt.O_WRONLY)
    nt.write(fd, "world")
    nt.close(fd)

    fd = nt.open(temp_file, 0)
    AreEqual(nt.read(fd, 1024), "hello world")
    nt.close(fd)

    nt.unlink(temp_file)
예제 #5
0
def test_coverage():
    f = file(temp_file, 'w')
    Assert(str(f).startswith("<open file '%s', mode 'w'" % temp_file))
    Assert(f.fileno() <> -1)
    Assert(f.fileno() <> 0)

    # write
    AssertError(TypeError, f.writelines, [3])
    f.writelines(["firstline\n"])

    f.close()
    Assert(str(f).startswith("<closed file '%s', mode 'w'" % temp_file))

    # append
    f = file(temp_file, 'a+')
    f.writelines(['\n', 'secondline\n'])

    pos = len('secondline\n') + 1
    f.seek(-1 * pos, 1)

    f.writelines(['thirdline\n'])
    f.close()

    # read
    f = file(temp_file, 'r+', 512)
    f.seek(-1 * pos - 2, 2)

    AreEqual(f.readline(), 'e\n')
    AreEqual(f.readline(5), 'third')
    AreEqual(f.read(-1), 'line\n')
    AreEqual(f.read(-1), '')
    f.close()

    # read
    f = file(temp_file, 'rb', 512)
    f.seek(-1 * pos - 2, 2)

    AreEqual(f.readline(), 'e\r\n')
    AreEqual(f.readline(5), 'third')
    AreEqual(f.read(-1), 'line\r\n')
    AreEqual(f.read(-1), '')
    f.close()

    ## file op in nt
    nt.unlink(temp_file)

    fd = nt.open(temp_file, nt.O_CREAT | nt.O_WRONLY)
    nt.write(fd, "hello ")
    nt.close(fd)

    fd = nt.open(temp_file, nt.O_APPEND | nt.O_WRONLY)
    nt.write(fd, "world")
    nt.close(fd)

    fd = nt.open(temp_file, 0)
    AreEqual(nt.read(fd, 1024), "hello world")
    nt.close(fd)

    nt.unlink(temp_file)
예제 #6
0
def GetMd5(filename):
        file = nt.open(filename, nt.O_CREAT)
        mdsum = MD5new()
        readBytes = 1024
        while(readBytes):
                readString = nt.read(file, 1024)
                mdsum.update(readString)
                readBytes = len(readString)
        nt.close(file)
        return mdsum.hexdigest()
예제 #7
0
def GetSystemList(dir = None):	
	import nt
	import strop
	
	if (not dir is None):
		loaddir = dir
	else:
		loaddir = "scripts\Custom"
		
	systems = []
	
	f = nt.open(loaddir + "\systems.txt", nt.O_RDONLY)
	l = nt.lseek((f, 0, 2))
	nt.lseek((f, 0, 0))
	s = nt.read((f, l))
	list = strop.split(s)
	nt.close(f)

	for system in list:
		s = strop.split(system, '.')
		if (len(s)==1):
			systemname = s[0]
			
			if (systemname == "Starbase12"):
				continue # Starbase12 will only crash us
				pModule = __import__('Systems.Starbase12.Starbase')
			elif (systemname == "DryDock"):
				pModule = __import__('Systems.DryDock.DryDockSystem')
			elif (systemname == "QuickBattle"):
				pModule = __import__('Systems.QuickBattle.QuickBattleSystem')
			else:
				pModule = __import__('Systems.'+systemname+'.'+systemname)
			
			if (hasattr(pModule, 'CreateMenus')):
				systems.append(systemname)
	
	systems.sort()
	return systems
예제 #8
0
def test_write():
    # write the file
    tempfilename = "temp.txt"
    file = open(tempfilename, "w")
    nt.write(file.fileno(), "Hello,here is the value of test string")
    file.close()

    # read from the file
    file = open(tempfilename, "r")
    str = nt.read(file.fileno(), 100)
    AreEqual(str, "Hello,here is the value of test string")
    file.close()
    nt.unlink(tempfilename)

    # BUG 8783 the argument buffersize in nt.read(fd, buffersize) is less than zero
    # the string written to the file is empty string
    tempfilename = "temp.txt"
    file = open(tempfilename, "w")
    nt.write(file.fileno(), "bug test")
    file.close()
    file = open(tempfilename, "r")
    AssertError(OSError, nt.read, file.fileno(), -10)
    file.close()
    nt.unlink(tempfilename)
예제 #9
0
파일: nt_test.py 프로젝트: 89sos98/main
def test_write():
    # write the file
    tempfilename = "temp.txt"
    file = open(tempfilename,"w")
    nt.write(file.fileno(),"Hello,here is the value of test string")
    file.close()
    
    # read from the file
    file =   open(tempfilename,"r")
    str = nt.read(file.fileno(),100)
    AreEqual(str,"Hello,here is the value of test string")
    file.close()
    nt.unlink(tempfilename)
    
    # BUG 8783 the argument buffersize in nt.read(fd, buffersize) is less than zero
    # the string written to the file is empty string
    tempfilename = "temp.txt"
    file = open(tempfilename,"w")
    nt.write(file.fileno(),"bug test")
    file.close()
    file = open(tempfilename,"r")
    AssertError(OSError,nt.read,file.fileno(),-10)
    file.close()
    nt.unlink(tempfilename)