本文整理汇总了Python中plainbox.impl.job.JobDefinition.modify_execution_environment方法的典型用法代码示例。如果您正苦于以下问题:Python JobDefinition.modify_execution_environment方法的具体用法?Python JobDefinition.modify_execution_environment怎么用?Python JobDefinition.modify_execution_environment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plainbox.impl.job.JobDefinition
的用法示例。
在下文中一共展示了JobDefinition.modify_execution_environment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: JobEnvTests
# 需要导入模块: from plainbox.impl.job import JobDefinition [as 别名]
# 或者: from plainbox.impl.job.JobDefinition import modify_execution_environment [as 别名]
class JobEnvTests(TestCase):
def setUp(self):
self.job = JobDefinition({
'name': 'name',
'environ': 'foo bar froz'
})
self.job._checkbox = Mock()
self.job._checkbox.extra_PYTHONPATH = None
self.job._checkbox.extra_PATH = "value-of-extra-path"
self.job._checkbox.CHECKBOX_SHARE = "checkbox-share-value"
self.session_dir = "session-dir-value"
def test_checkbox_env(self):
env = {
"PATH": ""
}
self.job.modify_execution_environment(env, self.session_dir)
self.assertEqual(env['CHECKBOX_SHARE'], 'checkbox-share-value')
self.assertEqual(env['CHECKBOX_DATA'], self.session_dir)
def test_without_config(self):
env = {
"PATH": "",
# foo is not defined in the environment
'bar': 'old-bar-value'
# froz is not defined in the environment
}
# Ask the job to modify the environment
self.job.modify_execution_environment(env, self.session_dir)
# Check how foo bar and froz look like now
self.assertNotIn('foo', env)
self.assertEqual(env['bar'], 'old-bar-value')
self.assertNotIn('froz', env)
def test_with_config_and_environ_variables(self):
env = {
"PATH": "",
# foo is not defined in the environment
'bar': 'old-bar-value'
# froz is not defined in the environment
}
# Setup a configuration object with values for foo and bar
from plainbox.impl.applogic import PlainBoxConfig
config = PlainBoxConfig()
config.environment = {
'foo': 'foo-value',
'bar': 'bar-value'
}
# Ask the job to modify the environment
self.job.modify_execution_environment(env, self.session_dir, config)
# foo got copied from the config
self.assertEqual(env['foo'], 'foo-value')
# bar from the old environment
self.assertEqual(env['bar'], 'old-bar-value')
# froz is still empty
self.assertNotIn('froz', env)
def test_with_config_and_variables_not_in_environ(self):
env = {
'bar': 'old-bar-value'
}
# Setup a configuration object with values for baz.
# Note that baz is *not* declared in the job's environ line.
from plainbox.impl.applogic import PlainBoxConfig
config = PlainBoxConfig()
config.environment = {
'baz': 'baz-value'
}
# Ask the job to modify the environment
self.job.modify_execution_environment(env, self.session_dir, config)
# bar from the old environment
self.assertEqual(env['bar'], 'old-bar-value')
# baz from the config environment
self.assertEqual(env['baz'], 'baz-value')
示例2: JobEnvTests
# 需要导入模块: from plainbox.impl.job import JobDefinition [as 别名]
# 或者: from plainbox.impl.job.JobDefinition import modify_execution_environment [as 别名]
class JobEnvTests(TestCase):
def setUp(self):
self.job = JobDefinition({"name": "name", "environ": "foo bar froz"})
self.job._provider = Mock()
self.job._provider.extra_PYTHONPATH = None
self.job._provider.extra_PATH = "value-of-extra-path"
self.job._provider.CHECKBOX_SHARE = "checkbox-share-value"
self.session_dir = "session-dir-value"
self.checkbox_data_dir = os.path.join(self.session_dir, "CHECKBOX_DATA")
def test_provider_env(self):
env = {"PATH": ""}
self.job.modify_execution_environment(env, self.session_dir, self.checkbox_data_dir)
self.assertEqual(env["CHECKBOX_SHARE"], "checkbox-share-value")
self.assertEqual(env["CHECKBOX_DATA"], os.path.join(self.session_dir, "CHECKBOX_DATA"))
def test_without_config(self):
env = {
"PATH": "",
# foo is not defined in the environment
"bar": "old-bar-value"
# froz is not defined in the environment
}
# Ask the job to modify the environment
self.job.modify_execution_environment(env, self.session_dir, self.checkbox_data_dir)
# Check how foo bar and froz look like now
self.assertNotIn("foo", env)
self.assertEqual(env["bar"], "old-bar-value")
self.assertNotIn("froz", env)
def test_with_config_and_environ_variables(self):
env = {
"PATH": "",
# foo is not defined in the environment
"bar": "old-bar-value"
# froz is not defined in the environment
}
# Setup a configuration object with values for foo and bar
from plainbox.impl.applogic import PlainBoxConfig
config = PlainBoxConfig()
config.environment = {"foo": "foo-value", "bar": "bar-value"}
# Ask the job to modify the environment
self.job.modify_execution_environment(env, self.session_dir, self.checkbox_data_dir, config)
# foo got copied from the config
self.assertEqual(env["foo"], "foo-value")
# bar from the old environment
self.assertEqual(env["bar"], "old-bar-value")
# froz is still empty
self.assertNotIn("froz", env)
def test_with_config_and_variables_not_in_environ(self):
env = {"bar": "old-bar-value"}
# Setup a configuration object with values for baz.
# Note that baz is *not* declared in the job's environ line.
from plainbox.impl.applogic import PlainBoxConfig
config = PlainBoxConfig()
config.environment = {"baz": "baz-value"}
# Ask the job to modify the environment
self.job.modify_execution_environment(env, self.session_dir, self.checkbox_data_dir, config)
# bar from the old environment
self.assertEqual(env["bar"], "old-bar-value")
# baz from the config environment
self.assertEqual(env["baz"], "baz-value")