summaryrefslogtreecommitdiff
path: root/templates
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-11-18 06:44:46 +0200
committerLars Wirzenius <liw@liw.fi>2020-11-18 06:44:46 +0200
commit4d587379b59a39128dfc358ade899bec9662d36f (patch)
tree42784710b11f890b6bbcc8c5e2db88f3ded64c5b /templates
parent08517b92af270e6cc466fb644070da8574029874 (diff)
downloadsubplot-4d587379b59a39128dfc358ade899bec9662d36f.tar.gz
refactor(templates/python): drop magic cookie for environment vars
We previously changed the Python template to set TMPDIR to the per-scenario directory. Part of that was using a "magic cookie" value to indicate which environment variables to set to the scenario directory. The cookie is unnecessary: we can just set the environment variables at the start of the scenario. This commit does that.
Diffstat (limited to 'templates')
-rw-r--r--templates/python/main.py24
-rw-r--r--templates/python/scenarios.py15
2 files changed, 12 insertions, 27 deletions
diff --git a/templates/python/main.py b/templates/python/main.py
index 7f55765..05e1715 100644
--- a/templates/python/main.py
+++ b/templates/python/main.py
@@ -28,29 +28,6 @@ def parse_command_line():
return p.parse_args()
-# Any environment variables set to this value will be set to the data directory
-# for each scenario, when the scenario starts.
-_DATADIR_COOKIE = "set-this-to-datadir-for-each-scenario"
-
-
-def setup_minimal_environment():
- minimal = {
- "PATH": "/bin:/usr/bin",
- "SHELL": "/bin/sh",
- "HOME": _DATADIR_COOKIE,
- "TMPDIR": _DATADIR_COOKIE,
- }
-
- os.environ.clear()
- os.environ.update(minimal)
-
-
-def set_environment_variables_to(scendir):
- for key in os.environ:
- if os.environ[key] == _DATADIR_COOKIE:
- os.environ[key] = scendir
-
-
def setup_logging(args):
if args.log:
fmt = "%(asctime)s %(levelname)s %(message)s"
@@ -78,7 +55,6 @@ def save_directory(dirname, tarname):
def main(scenarios):
args = parse_command_line()
- setup_minimal_environment()
setup_logging(args)
logging.info("Test program starts")
diff --git a/templates/python/scenarios.py b/templates/python/scenarios.py
index 6dbc1a8..eb5302e 100644
--- a/templates/python/scenarios.py
+++ b/templates/python/scenarios.py
@@ -60,14 +60,12 @@ class Scenario:
self._steps.append(step)
def run(self, datadir):
- set_environment_variables_to = globals()["set_environment_variables_to"]
-
print("scenario: {}".format(self._title))
logging.info("Scenario: {}".format(self._title))
scendir = tempfile.mkdtemp(dir=datadir)
os.chdir(scendir)
- set_environment_variables_to(scendir)
+ self._set_environment_variables_to(scendir)
done = []
ctx = self._ctx
@@ -82,3 +80,14 @@ class Scenario:
raise
for step in reversed(done):
step.cleanup(ctx)
+
+ def _set_environment_variables_to(self, scendir):
+ minimal = {
+ "PATH": "/bin:/usr/bin",
+ "SHELL": "/bin/sh",
+ "HOME": scendir,
+ "TMPDIR": scendir,
+ }
+
+ os.environ.clear()
+ os.environ.update(minimal)