class documentation

class MockOS: (source)

View In Hierarchy

The mock OS: overwrite os, fcntl and {sys} functions with fake ones.

Method __init__ Initialize data structures.
Method chdir Override os.chdir. Save the action.
Method close Fake os.close, saving the closed fd in self.closed.
Method dup2 Fake os.dup2. Do nothing.
Method execvpe Fake os.execvpe. Save the action, and raise an error if self.raiseExec is set.
Method expanduser Mock os.path.expanduser.
Method fdopen Fake os.fdopen. Return a file-like object whose content can be tested later via self.fdio.
Method fork Fake os.fork. Save the action in self.actions, and return 0 if self.child is set, or a dumb number.
Method fstat Fake os.fstat. Return a os.stat_result filled with garbage.
Method getegid Mock os.getegid, returning self.egid instead.
Method geteuid Mock os.geteuid, returning self.euid instead.
Method getfilesystemencoding Return a fixed filesystem encoding.
Method getgid Override os.getgid. Return a dumb number.
Method getpid Return a fixed PID value.
Method getpwnam Mock pwd.getpwnam.
Method getuid Override os.getuid. Return a dumb number.
Method ioctl Override fcntl.ioctl. Do nothing.
Method kill Override os.kill: save the action and raise self.raiseKill if specified.
Method listdir Override os.listdir, returning fake contents of '/dev/fd'
Method open Fake os.open. Return a non fd number to be sure it's not used elsewhere.
Method openpty Override pty.openpty, returning fake file descriptors.
Method pipe Fake os.pipe. Return non fd numbers to be sure it's not used elsewhere, and increment self.pipeCount. This is used to uniquify the result.
Method read Fake os.read: save action, and return readData content.
Method setegid Mock os.setegid, store result.
Method seteuid Mock os.seteuid, store result.
Method setgid Override os.setgid. Do nothing.
Method setNonBlocking Override fdesc.setNonBlocking. Do nothing.
Method setregid Override os.setregid. Do nothing.
Method setreuid Override os.setreuid. Save the action.
Method setsid Fake os.setsid. Save action.
Method settrace Override sys.settrace to keep coverage working.
Method setuid Override os.setuid. Do nothing.
Method switchUID Override util.switchUID. Save the action.
Method ttyname Fake os.ttyname. Return a dumb string.
Method umask Override os.umask. Save the action.
Method unlink Override os.unlink. Save the action.
Method waitpid Override os.waitpid. Return values meaning that the child process has exited, save executed action.
Method write Fake os.write. Save action.
Instance Variable actions hold names of some actions executed by the object, in order of execution.
Instance Variable child whether fork return for the child or the parent.
Instance Variable closed keep track of the file descriptor closed.
Instance Variable egid the gid returned by the fake os.getegid
Instance Variable euid the uid returned by the fake os.geteuid
Instance Variable exited set to True when _exit is called.
Instance Variable fdio fake file object returned by calls to fdopen.
Instance Variable O_NOCTTY dumb value faking os.O_NOCTTY.
Instance Variable O_RDWR dumb value faking os.O_RDWR.
Instance Variable path the path returned by os.path.expanduser.
Instance Variable pipeCount count the number of time that os.pipe has been called.
Instance Variable raiseExec if set, subsequent calls to execvpe will raise an error.
Instance Variable raiseFork if not None, subsequent calls to fork will raise this object.
Instance Variable raiseKill if set, subsequent call to kill will raise the error specified.
Instance Variable raiseWaitPid if set, subsequent calls to waitpid will raise the error specified.
Instance Variable readData data returned by os.read.
Instance Variable setegidCalls stored results of os.setegid calls.
Instance Variable seteuidCalls stored results of os.seteuid calls.
Instance Variable waitChild if set, subsequent calls to waitpid will return it.
Instance Variable WEXITSTATUS Undocumented
Instance Variable WIFEXITED Undocumented
Instance Variable WNOHANG dumb value faking os.WNOHANG.
Method _exit Fake os._exit. Save the action, set the self.exited flag, and raise SystemError.
def __init__(self): (source)

Initialize data structures.

def chdir(self, path): (source)

Override os.chdir. Save the action.

Parameters
pathThe path to change the current directory to.
def close(self, fd): (source)

Fake os.close, saving the closed fd in self.closed.

def dup2(self, fd1, fd2): (source)

Fake os.dup2. Do nothing.

def execvpe(self, command, args, env): (source)

Fake os.execvpe. Save the action, and raise an error if self.raiseExec is set.

def expanduser(self, path): (source)

Mock os.path.expanduser.

def fdopen(self, fd, flag): (source)

Fake os.fdopen. Return a file-like object whose content can be tested later via self.fdio.

def fork(self): (source)

Fake os.fork. Save the action in self.actions, and return 0 if self.child is set, or a dumb number.

def fstat(self, fd): (source)

Fake os.fstat. Return a os.stat_result filled with garbage.

def getegid(self): (source)

Mock os.getegid, returning self.egid instead.

def geteuid(self): (source)

Mock os.geteuid, returning self.euid instead.

def getfilesystemencoding(self): (source)

Return a fixed filesystem encoding.

Returns
A fixed value of "utf8".
def getgid(self): (source)

Override os.getgid. Return a dumb number.

def getpid(self): (source)

Return a fixed PID value.

Returns
A fixed value.
def getpwnam(self, user): (source)

Mock pwd.getpwnam.

def getuid(self): (source)

Override os.getuid. Return a dumb number.

def ioctl(self, fd, flags, arg): (source)

Override fcntl.ioctl. Do nothing.

def kill(self, pid, signalID): (source)

Override os.kill: save the action and raise self.raiseKill if specified.

def listdir(self, path): (source)

Override os.listdir, returning fake contents of '/dev/fd'

def open(self, dev, flags): (source)

Fake os.open. Return a non fd number to be sure it's not used elsewhere.

def openpty(self): (source)

Override pty.openpty, returning fake file descriptors.

def pipe(self): (source)

Fake os.pipe. Return non fd numbers to be sure it's not used elsewhere, and increment self.pipeCount. This is used to uniquify the result.

def read(self, fd, size): (source)

Fake os.read: save action, and return readData content.

Parameters
fdThe file descriptor to read.
sizeThe maximum number of bytes to read.
Returns
A fixed bytes buffer.
def setegid(self, egid): (source)

Mock os.setegid, store result.

def seteuid(self, egid): (source)

Mock os.seteuid, store result.

def setgid(self, val): (source)

Override os.setgid. Do nothing.

def setNonBlocking(self, fd): (source)

Override fdesc.setNonBlocking. Do nothing.

def setregid(self, val1, val2): (source)

Override os.setregid. Do nothing.

def setreuid(self, val1, val2): (source)

Override os.setreuid. Save the action.

def setsid(self): (source)

Fake os.setsid. Save action.

def settrace(self, arg): (source)

Override sys.settrace to keep coverage working.

def setuid(self, val): (source)

Override os.setuid. Do nothing.

def switchUID(self, uid, gid): (source)

Override util.switchUID. Save the action.

def ttyname(self, fd): (source)

Fake os.ttyname. Return a dumb string.

def umask(self, mask): (source)

Override os.umask. Save the action.

Parameters
maskThe new file mode creation mask.
def unlink(self, filename): (source)

Override os.unlink. Save the action.

Parameters
filenameThe file name to remove.
def waitpid(self, pid, options): (source)

Override os.waitpid. Return values meaning that the child process has exited, save executed action.

def write(self, fd, data): (source)

Fake os.write. Save action.

actions: list of str = (source)

hold names of some actions executed by the object, in order of execution.

child: bool = (source)

whether fork return for the child or the parent.

closed: list of int = (source)

keep track of the file descriptor closed.

egid: int = (source)

the gid returned by the fake os.getegid

euid: int = (source)

the uid returned by the fake os.geteuid

exited: bool = (source)

set to True when _exit is called.

fdio: BytesIO or BytesIO = (source)

fake file object returned by calls to fdopen.

O_NOCTTY: int = (source)

dumb value faking os.O_NOCTTY.

O_RDWR: int = (source)

dumb value faking os.O_RDWR.

path: str = (source)

the path returned by os.path.expanduser.

pipeCount: int = (source)

count the number of time that os.pipe has been called.

raiseExec: bool = (source)

if set, subsequent calls to execvpe will raise an error.

raiseFork: None or Exception = (source)

if not None, subsequent calls to fork will raise this object.

raiseKill: None or an exception instance. = (source)

if set, subsequent call to kill will raise the error specified.

raiseWaitPid: None or a class = (source)

if set, subsequent calls to waitpid will raise the error specified.

readData: str = (source)

data returned by os.read.

setegidCalls: list = (source)

stored results of os.setegid calls.

seteuidCalls: list = (source)

stored results of os.seteuid calls.

waitChild: None or a tuple = (source)

if set, subsequent calls to waitpid will return it.

WEXITSTATUS = (source)

Undocumented

WIFEXITED = (source)

Undocumented

WNOHANG: int = (source)

dumb value faking os.WNOHANG.

def _exit(self, code): (source)

Fake os._exit. Save the action, set the self.exited flag, and raise SystemError.