>From c1a0b11980c050db4a95616895db25addb241d8c Mon Sep 17 00:00:00 2001 From: Tomas Hozza Date: Thu, 7 Nov 2019 13:01:44 +0100 Subject: [PATCH 2/3] testenv: Allow definition of environment variables for wget execuion * testenv/README: Added description for new EnvironmentVariable hook * testenv/conf/environment_variable.py: Added implementation of EnvironmentVariable hook * testenv/test/base_test.py: Modified exec_wget() to enable use of EnvironmentVariable hook Added new test hook called EnvironmentVariables, for defining environment variables when wget is executed in tests. This is handy for testing environment variables, which are accepted by wget. Signed-off-by: Tomas Hozza --- testenv/README | 3 +++ testenv/conf/environment_variables.py | 14 ++++++++++++++ testenv/test/base_test.py | 6 +++++- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 testenv/conf/environment_variables.py diff --git a/testenv/README b/testenv/README index aca8cdda..d4fabddd 100644 --- a/testenv/README +++ b/testenv/README @@ -224,6 +224,9 @@ executed. The currently supported options are: file. While all Download URL's are passed to Urls, a notable exception is when in-url authentication is used. In such a case, the URL is specified in the WgetCommands string. + * EnvironmentVariables: A dictionary with key-value items, which will be + defined as environment variables during the execution of wget command in + test. Post-Test Hooks: ================================================================================ diff --git a/testenv/conf/environment_variables.py b/testenv/conf/environment_variables.py new file mode 100644 index 00000000..323c051c --- /dev/null +++ b/testenv/conf/environment_variables.py @@ -0,0 +1,14 @@ +from conf import hook + +""" Test Option: EnvironmentVariables +This hook is used to define environment variables used for execution of wget +command in test.""" + + +@hook(alias='EnvironmentVariables') +class URLs: + def __init__(self, envs): + self.envs = envs + + def __call__(self, test_obj): + test_obj.envs.update(**self.envs) diff --git a/testenv/test/base_test.py b/testenv/test/base_test.py index 0d2624ad..228f728b 100644 --- a/testenv/test/base_test.py +++ b/testenv/test/base_test.py @@ -51,6 +51,7 @@ class BaseTest: self.wget_options = '' self.urls = [] + self.envs = dict() self.tests_passed = True self.ready = False @@ -97,12 +98,15 @@ class BaseTest: cmd_line = self.gen_cmd_line() params = shlex.split(cmd_line) print(params) + envs = {"HOME": os.getcwd()} + envs.update(**self.envs) + print(envs) if os.getenv("SERVER_WAIT"): time.sleep(float(os.getenv("SERVER_WAIT"))) try: - ret_code = call(params, env={"HOME": os.getcwd()}) + ret_code = call(params, env=envs) except FileNotFoundError: raise TestFailed("The Wget Executable does not exist at the " "expected path.") -- 2.25.4