Skip to content

Commit

Permalink
remove key sort in favor of printing the environ each time
Browse files Browse the repository at this point in the history
I had previously sorted the key set to avoid order mismatches
between python 2/3. Fort whatever reason the tests showed

AttributeError: 'KeysView' object has no attribute 'sort'

in python 3 - likely a different point version.
  • Loading branch information
prwolfe committed Aug 6, 2019
1 parent 9bd0f21 commit 486016f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 33 deletions.
5 changes: 2 additions & 3 deletions cmake/std/PullRequestLinuxDriverMerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ def echoJenkinsVars(workspace):
pwd = {cwd}
'''.format(workspace=workspace,
cwd=os.getcwd()), file=sys.stdout)
keys = os.environ.keys()
keys.sort()
for key in keys:

for key in os.environ:
print(key +' = ' + os.environ[key])
print('''
================================================================================''',
Expand Down
51 changes: 21 additions & 30 deletions cmake/std/unittests/TestPullRequestLinuxDriverMerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,27 @@ def test_writeHeader(self):

class Test_EchoJenkinsVars(unittest.TestCase):
'''Test that the Jenkins environment is echoed properly'''
def test_echoJenkinsVars(self):
expected_string = '''
================================================================================
Jenkins Environment Variables:
- WORKSPACE : /dev/null/TEST_WORKSPACE

================================================================================
Environment:

pwd = {cwd}
def setUp(self):
self.m_environ = mock.patch.dict(os.environ, {'JOB_BASE_NAME':'TEST_JOB_BASE_NAME',
'JOB_NAME':'TEST_JOB_NAME',
'WORKSPACE':os.path.join(os.sep,
'dev',
'null',
'TEST_WORKSPACE'),
'NODE_NAME':'TEST_NODE_NAME'},
clear=True)

JOB_BASE_NAME = TEST_JOB_BASE_NAME
JOB_NAME = TEST_JOB_NAME
WORKSPACE = /dev/null/TEST_WORKSPACE
NODE_NAME = TEST_NODE_NAME

================================================================================
'''.format(cwd=os.getcwd())
if sys.version_info.major is not 3:
expected_string = '''
def test_echoJenkinsVars(self):
with self.m_environ:
env_string_io = StringIO()
for key in os.environ:
print(key + ' = ' + os.environ[key],
file=env_string_io)

expected_string = '''
================================================================================
Jenkins Environment Variables:
- WORKSPACE : /dev/null/TEST_WORKSPACE
Expand All @@ -74,23 +75,13 @@ def test_echoJenkinsVars(self):
pwd = {cwd}
JOB_BASE_NAME = TEST_JOB_BASE_NAME
JOB_NAME = TEST_JOB_NAME
NODE_NAME = TEST_NODE_NAME
WORKSPACE = /dev/null/TEST_WORKSPACE
{environ}
================================================================================
'''.format(cwd=os.getcwd())
'''.format(cwd=os.getcwd(),
environ=env_string_io.getvalue())

with mock.patch('sys.stdout', new_callable=StringIO) as m_stdout, \
mock.patch.dict(os.environ, {'JOB_BASE_NAME':'TEST_JOB_BASE_NAME',
'JOB_NAME':'TEST_JOB_NAME',
'WORKSPACE':os.path.join(os.sep,
'dev',
'null',
'TEST_WORKSPACE'),
'NODE_NAME':'TEST_NODE_NAME'},
clear=True):
self.m_environ:
PullRequestLinuxDriverMerge.echoJenkinsVars(os.path.join(os.sep,
'dev',
'null',
Expand Down

0 comments on commit 486016f

Please sign in to comment.