-
Notifications
You must be signed in to change notification settings - Fork 994
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/enabling environment variables unset action (#4224)
* Enabling the possibility of unsetting variables by means of appending such variable with value equal to None. Tests covering tools.env.environment_append have been included * Fixing PEP8 line width requirement * Fixing PEP8 line width requirement * Fixing path separator used in the unit test considering its os-dependant value * Fixing how the env_vars dictionary is being modified. Instead of removing values on-the-fly, It is previourly checked which should be removed by iterating on the keys. * Fixing how the env_vars dictionary is being modified again. Iterating on keys didn't work enough and now it is decoupled the iteration by using the keys that should be removed and were previously stored * Fix. Setting all the variables to None (unsetting all of them) effectively removes them from environment. - Applying changes needed. - Adding regression test. - Adding additional test covering the case where no variables are asked to be removed (empty dict). - Improve tests naming.
- Loading branch information
Showing
2 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# coding=utf-8 | ||
|
||
import os | ||
import unittest | ||
import mock | ||
|
||
from conans.client.tools import env | ||
|
||
|
||
class ToolsEnvTest(unittest.TestCase): | ||
def test_environment_append_variables(self): | ||
with mock.patch.dict('os.environ', {}),\ | ||
env.environment_append({'env_var1': 'value', | ||
'env_var2': 'value2'}): | ||
self.assertEqual(os.environ['env_var1'], 'value') | ||
self.assertEqual(os.environ['env_var2'], 'value2') | ||
|
||
def test_environment_append_variables_without_values(self): | ||
with mock.patch.dict('os.environ', | ||
{'env_var1': 'value', | ||
'env_var2': 'value2'}),\ | ||
env.environment_append({}): | ||
self.assertEqual(os.environ['env_var1'], 'value') | ||
self.assertEqual(os.environ['env_var2'], 'value2') | ||
|
||
def test_environment_append_overwriting(self): | ||
with mock.patch.dict('os.environ', {'env_var1': 'value'}),\ | ||
env.environment_append({'env_var1': 'new_value'}): | ||
self.assertEqual(os.environ['env_var1'], 'new_value') | ||
|
||
def test_environment_append_list(self): | ||
with mock.patch.dict('os.environ', {}),\ | ||
env.environment_append({'env_var1': ['value1', 'value2']}): | ||
self.assertEqual(os.environ['env_var1'], 'value1' + | ||
os.pathsep + 'value2') | ||
|
||
def test_environment_append_unsetting_some_variables(self): | ||
with mock.patch.dict('os.environ', {'env_var1': 'value'}),\ | ||
env.environment_append({'env_var1': None, 'env_var2': 'value2'}): | ||
self.assertNotIn('env_var1', os.environ) | ||
self.assertEqual(os.environ['env_var2'], 'value2') | ||
|
||
def test_environment_append_unsetting_all_variables(self): | ||
with mock.patch.dict('os.environ', | ||
{'env_var1': 'value', | ||
'env_var2': 'value2'}),\ | ||
env.environment_append({'env_var1': None}): | ||
self.assertNotIn('env_var1', os.environ) |