Merge lp:~roadmr/checkbox/1187216-check-job-format into lp:checkbox

Proposed by Daniel Manrique
Status: Merged
Approved by: Brendan Donegan
Approved revision: 2164
Merged at revision: 2189
Proposed branch: lp:~roadmr/checkbox/1187216-check-job-format
Merge into: lp:checkbox
Diff against target: 85 lines (+32/-6)
3 files modified
checkbox-old/checkbox/tests/test_message_files.py (+29/-3)
checkbox-old/debian/changelog (+2/-0)
checkbox-old/jobs/fingerprint.txt.in (+1/-3)
To merge this branch: bzr merge lp:~roadmr/checkbox/1187216-check-job-format
Reviewer Review Type Date Requested Status
Jeff Lane  Approve
Daniel Manrique (community) Needs Resubmitting
Review via email: mp+167341@code.launchpad.net

Commit message

Added a test that validates that manual (user-verify and user-interact included) jobs contain the verification field in their description, without which the Qt UI tends to skip tests.

Description of the change

Added a test that validates that manual (user-verify and user-interact included) jobs contain the verification field in their description, without which the Qt UI tends to skip tests.

The test can be trivially modified to check for any other fields in the description.

With this test, builds will fail if any job is malformed, so at least we won't build bad stuff.

To post a comment you must log in.
Revision history for this message
Jeff Lane  (bladernr) wrote :

Just to be pedantic:

This job description:
plugin: user-interact
name: mediacard/mmc-foo
command: do_some_stuff.exe.bat.com
_description:
 PURPOSE:
    to flob the brats
 VERIFICATION:
    blab:

Results in this failure:
FAIL: test_verify_manual_jobs_have_required_fields (tests.test_message_files.MessageFileFormatTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/bladernr/development/daniel-job-desc-test/checkbox-old/checkbox/tests/test_message_files.py", line 122, in test_verify_manual_jobs_have_required_fields
    msg.format(message['name']))
AssertionError: False is not true : Missing verification in mediacard/mmc-foo

I am actually missing the "STEPS" part, not VERIFICATION.

This description returns the same error:
plugin: user-interact
name: mediacard/mmc-foo
command: do_some_stuff.exe.bat.com
_description:
 PURPOSE:
    to flob the brats
 STEPS:
    1: Steal Underpands!
    2: ??
    3: PROFIT!

only it IS missing the VERIFICATION part...

any chance to get it to say WHAT is missing?

review: Needs Fixing
Revision history for this message
Jeff Lane  (bladernr) wrote :

Also, why the change to fingerprint.txt.in removing the PREREQUISITE: field?

Revision history for this message
Daniel Manrique (roadmr) wrote :

It's not being pedantic, it's actually a very valid concern, luckily it's something I can explain.

I run the description through the DescriptionParser, the way checkbox does. If the parser can extract the required fields (purpose, steps, verification, and (optionally) info), it calls a specified method and passes these values (the method then sets the needed variables in a context-dependent way; look at the DescriptionResult mini-class).

However, if the description is malformed (well, not "malformed" but not parsable according to expectations), the DescriptionParser doesn't do anything and the DescriptionResult will be completely empty. Programs are expected to use the raw description in this case.

The message you're getting is in essence correct; the DescriptionResult itself has no "verification" key. However this is because the test description was unparsable (i.e. it had VERIFICATION but lacks STEPS so the parser deems it entirely invalid), so the DescriptionResult object is empty.

I can certainly make the test a bit less crude; it could indicate unparsable descriptions, which *should* work, but in practice I think the Qt UI doesn't like them so we may as well catch and report them.

Removing PREREQUISITE was for the same reason: the parser doesn't know about that section identifier, so it gives up (invalid description as far as it's concerned) and returns an empty DescriptionResult.

I'll modify the test to make it cleverer and more explanatory, should have it ready soon.

2164. By Daniel Manrique

Changed to just run through the parser and reject unparsable descriptions

Revision history for this message
Daniel Manrique (roadmr) wrote :

OK, so I simplified the test and the message, it will simply say "wrong job format" if the parser returns an empty set of fields. Turns out, they're all mandatory (save for INFO) and need to be in the correct order, so this seems simpler. So it's impossible for the parser to return an incomplete set of fields.

To produce a more detailed report of what's wrong, I'd have to implement a new parser (as the existing one is not geared towards diagnostics), not sure if it's needed.

This is the sort of error it produces now:

======================================================================
FAIL: test_verify_manual_jobs_have_parsable_description (checkbox.tests.test_message_files.MessageFileFormatTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/media/bulk/checkboxes/checkbox/1187216-check-job-format/checkbox-old/checkbox/tests/test_message_files.py", line 122, in test_verify_manual_jobs_have_parsable_description
    msg.format(message['name']))
AssertionError: {} is not true : Description for manual job mediacard/mmc-foo2 has wrong format

review: Needs Resubmitting
Revision history for this message
Jeff Lane  (bladernr) wrote :

Thanks, that's less confusing. And Yeah, no need to write a completely new parser just to make a unit test easier :)

Thanks a lot for making those changes!

review: Approve
Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

Don't forget to set the overall status to 'Approved' to let Tarmac do its thing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'checkbox-old/checkbox/tests/test_message_files.py'
2--- checkbox-old/checkbox/tests/test_message_files.py 2013-05-29 07:50:30 +0000
3+++ checkbox-old/checkbox/tests/test_message_files.py 2013-06-05 15:27:29 +0000
4@@ -18,8 +18,20 @@
5 #
6 import os
7 import unittest
8+from io import StringIO
9+
10 from checkbox.lib.path import path_expand_recursive
11 from checkbox.lib.template_i18n import TemplateI18n
12+from checkbox.parsers.description import DescriptionParser
13+
14+
15+class DescriptionResult(object):
16+ def __init__(self):
17+ self.fields = {}
18+
19+ def setDescription(self, purpose, steps, verification, info):
20+ for name in ['purpose', 'steps', 'verification', 'info']:
21+ self.fields[name] = locals()[name]
22
23
24 class MessageFileFormatTest(unittest.TestCase):
25@@ -72,11 +84,11 @@
26 shell_variables += re.findall(shell_variables_regex,
27 message[key])
28 if 'environ' in message:
29- environ_variables = re.findall(environ_variables_regex,
30+ environ_variables = re.findall(environ_variables_regex,
31 message['environ'])
32 self.assertEqual(set(environ_variables),
33- set(shell_variables),
34- message['name'])
35+ set(shell_variables),
36+ message['name'])
37
38 def test_jobs_comply_with_schema(self):
39 globals = {}
40@@ -95,3 +107,17 @@
41 for message in self.messages:
42 if message['plugin'] in ('user-verify', 'user-interact'):
43 self.assertTrue("command" in message)
44+
45+ def test_verify_manual_jobs_have_parsable_description(self):
46+ for message in self.messages:
47+ if message['plugin'] in ('user-verify', 'user-interact', 'manual'):
48+ for key in ['description', 'description_extended']:
49+ if key in message and message[key]:
50+ descstream = StringIO(message[key])
51+ parser = DescriptionParser(descstream)
52+ result = DescriptionResult()
53+ parser.run(result)
54+ msg = "Description for manual job {} has wrong format"
55+ self.assertTrue(result.fields,
56+ msg.format(message['name']))
57+
58
59=== modified file 'checkbox-old/debian/changelog'
60--- checkbox-old/debian/changelog 2013-06-05 11:56:25 +0000
61+++ checkbox-old/debian/changelog 2013-06-05 15:27:29 +0000
62@@ -17,6 +17,8 @@
63
64 [ Daniel Manrique ]
65 * jobs/stress.txt.in: fixed a few inconsistent invocations of sleep_test.
66+ * checkbox/tests/test_message_files.py: Added a test to verify jobs contain
67+ required fields (LP: #1187216).
68
69 [ Sylvain Pineau ]
70 * jobs/resource.txt.in: updated version of the package resource job command
71
72=== modified file 'checkbox-old/jobs/fingerprint.txt.in'
73--- checkbox-old/jobs/fingerprint.txt.in 2013-05-29 07:50:30 +0000
74+++ checkbox-old/jobs/fingerprint.txt.in 2013-06-05 15:27:29 +0000
75@@ -2,9 +2,7 @@
76 name: fingerprint/login
77 _description:
78 PURPOSE:
79- This test will verify that a fingerprint reader will work properly for logging into your system.
80- PREREQUISITES:
81- This test case assumes that there's a testing account from which test cases are run and a personal account that the tester uses to verify the fingerprint reader
82+ This test will verify that a fingerprint reader will work properly for logging into your system. This test case assumes that there's a testing account from which test cases are run and a personal account that the tester uses to verify the fingerprint reader
83 STEPS:
84 1. Click on the User indicator on the left side of the panel (your user name).
85 2. Select "Switch User Account"

Subscribers

People subscribed via source and target branches