Sort comments in file_comments testing

We need to sort the comments by file then by line as we have overlapping
lines in the test set. This results in nondeterministic order for our
asserts. We fix this by using a multi attribute sort.

Change-Id: I977c98b1c9d5f8cc6de103ee2540ce5f99f07061
This commit is contained in:
Clark Boylan
2020-08-27 11:34:21 -07:00
parent 570fb83069
commit c9332abeca

View File

@@ -247,9 +247,24 @@ class TestFileComments(AnsibleZuulTestCase):
self.assertEqual(self.getJobFromHistory('file-comments-error').result,
'SUCCESS')
self.assertEqual(len(A.comments), 6)
comments = sorted(A.comments, key=lambda x: x['line'])
comments = sorted(A.comments, key=lambda x: (x['file'], x['line']))
self.assertEqual(
comments[0],
{
'file': 'otherfile.txt',
'line': 21,
'message': 'This is a much longer message.\n\n'
'With multiple paragraphs.\n',
'reviewer': {
'email': 'zuul@example.com',
'name': 'Zuul',
'username': 'jenkins'
},
},
)
self.assertEqual(
comments[1],
{
"file": "path/to/file.py",
"line": 2,
@@ -263,7 +278,7 @@ class TestFileComments(AnsibleZuulTestCase):
)
self.assertEqual(
comments[1],
comments[2],
{
"file": "path/to/file.py",
"line": 21,
@@ -279,23 +294,18 @@ class TestFileComments(AnsibleZuulTestCase):
},
)
self.assertEqual(comments[2],
{'file': 'otherfile.txt',
'line': 21,
'message': 'This is a much longer message.\n\n'
'With multiple paragraphs.\n',
'reviewer': {'email': 'zuul@example.com',
'name': 'Zuul',
'username': 'jenkins'}}
)
self.assertEqual(comments[3],
{'file': 'path/to/file.py',
'line': 42,
'message': 'line too long',
'reviewer': {'email': 'zuul@example.com',
'name': 'Zuul',
'username': 'jenkins'}}
self.assertEqual(
comments[3],
{
'file': 'path/to/file.py',
'line': 42,
'message': 'line too long',
'reviewer': {
'email': 'zuul@example.com',
'name': 'Zuul',
'username': 'jenkins'
},
},
)
self.assertEqual(