From 37f3a15f22e75fb961cb8c5ea53ca121f7f8c5e0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20de=20Saint=20Martin?= <cedric.dsm@tiolive.com>
Date: Fri, 7 Sep 2012 09:49:32 +0200
Subject: [PATCH] Update egg_test and erp5_test to support specific environment

---
 slapos/recipe/erp5_test/__init__.py | 39 ++++++++++++++++++++++-------
 slapos/recipe/erp5_test/test.py     |  4 +++
 2 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/slapos/recipe/erp5_test/__init__.py b/slapos/recipe/erp5_test/__init__.py
index 495804403..a9ed300a0 100644
--- a/slapos/recipe/erp5_test/__init__.py
+++ b/slapos/recipe/erp5_test/__init__.py
@@ -100,16 +100,37 @@ class CloudoooRecipe(GenericBaseRecipe):
     return path_list
 
 class EggTestRecipe(GenericBaseRecipe):
+  """
+  Recipe used to create wrapper used to run test suite (python setup.py test)
+  off a list of Python eggs.
+  """
   def install(self):
     path_list = []
-    common_dict = dict()
-     #   prepend_path=self.options['prepend-path'],
-    #)
-    common_list = [ "--source-core-path-list", self.options['test-list']]
-    path_list.append(self.createPythonScript(self.options['run-test-suite'],
-        __name__ + '.test.runTestSuite', [dict(
-        call_list=[self.options['run-test-suite-binary'],
-          ] + common_list, **common_dict)]))
+    test_list = self.options['test-list'].strip().replace('\n', ',')
+    common_dict = {}
 
-    return path_list
+    environment_dict = {}
+    if self.options.get('environment'):
+      environment_part = self.buildout.get(self.options['environment'])
+      if environment_part:
+        for key, value in environment_part.iteritems():
+          environment_dict[key] = value
+
+    common_list = [ "--source_code_path_list", test_list]
 
+    argument_dict = dict(
+        call_list=[self.options['run-test-suite-binary'],] + common_list,
+        environment=environment_dict,
+        **common_dict
+    )
+    if 'prepend-path' in self.options:
+      argument_dict['prepend_path'] = self.options['prepend-path']
+
+    run_test_suite_script = self.createPythonScript(
+        self.options['run-test-suite'], __name__ + '.test.runTestSuite',
+        [argument_dict]
+    )
+
+    path_list.append(run_test_suite_script)
+
+    return path_list
diff --git a/slapos/recipe/erp5_test/test.py b/slapos/recipe/erp5_test/test.py
index d2c93b876..362b0d1db 100644
--- a/slapos/recipe/erp5_test/test.py
+++ b/slapos/recipe/erp5_test/test.py
@@ -39,6 +39,10 @@ def runTestSuite(args):
     env['INSTANCE_HOME'] = d['instance_home']
     env['REAL_INSTANCE_HOME'] = d['instance_home']
 
+  # If defined, will add (and replace if existing) envvars to environment.
+  if 'environment' in d:
+    env.update(d['environment'])
+
   # Deal with Shebang size limitation
   executable_filepath = d['call_list'][0]
   file_object = open(executable_filepath, 'r')
-- 
2.30.9