mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Unittest - Make is easier to reset env vars of task and taskd
This commit is contained in:
parent
2a198d59fe
commit
02683aecd7
2 changed files with 22 additions and 11 deletions
|
@ -37,13 +37,7 @@ class Task(object):
|
|||
# Ensure any instance is properly destroyed at session end
|
||||
atexit.register(lambda: self.destroy())
|
||||
|
||||
# Copy all env variables to avoid clashing subprocess environments
|
||||
self.env = os.environ.copy()
|
||||
|
||||
# Make sure no TASKDDATA is isolated
|
||||
self.env["TASKDATA"] = self.datadir
|
||||
# As well as TASKRC
|
||||
self.env["TASKRC"] = self.taskrc
|
||||
self.reset_env()
|
||||
|
||||
# Cannot call self.config until confirmation is disabled
|
||||
with open(self.taskrc, 'w') as rc:
|
||||
|
@ -58,6 +52,17 @@ class Task(object):
|
|||
txt = super(Task, self).__repr__()
|
||||
return "{0} running from {1}>".format(txt[:-1], self.datadir)
|
||||
|
||||
def reset_env(self):
|
||||
"""Set a new environment derived from the one used to launch the test
|
||||
"""
|
||||
# Copy all env variables to avoid clashing subprocess environments
|
||||
self.env = os.environ.copy()
|
||||
|
||||
# Make sure no TASKDDATA is isolated
|
||||
self.env["TASKDATA"] = self.datadir
|
||||
# As well as TASKRC
|
||||
self.env["TASKRC"] = self.taskrc
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
"aka t = Task() ; t() which is now an alias to t.runSuccess()"
|
||||
return self.runSuccess(*args, **kwargs)
|
||||
|
|
|
@ -57,10 +57,7 @@ class Taskd(object):
|
|||
# Ensure any instance is properly destroyed at session end
|
||||
atexit.register(lambda: self.destroy())
|
||||
|
||||
# Copy all env variables to avoid clashing subprocess environments
|
||||
self.env = os.environ.copy()
|
||||
# Make sure TASKDDATA points to the temporary folder
|
||||
self.env["TASKDATA"] = self.datadir
|
||||
self.reset_env()
|
||||
|
||||
if certpath is None:
|
||||
certpath = DEFAULT_CERT_PATH
|
||||
|
@ -101,6 +98,15 @@ class Taskd(object):
|
|||
txt = super(Taskd, self).__repr__()
|
||||
return "{0} running from {1}>".format(txt[:-1], self.datadir)
|
||||
|
||||
def reset_env(self):
|
||||
"""Set a new environment derived from the one used to launch the test
|
||||
"""
|
||||
# Copy all env variables to avoid clashing subprocess environments
|
||||
self.env = os.environ.copy()
|
||||
|
||||
# Make sure TASKDDATA points to the temporary folder
|
||||
self.env["TASKDATA"] = self.datadir
|
||||
|
||||
def create_user(self, user=None, group=None, org=None):
|
||||
"""Create a user/group in the server and return the user
|
||||
credentials to use in a taskw client.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue