[apparmor] [PATCH 2/2] utils: Simplify newly added test-regex_matches tests
Tyler Hicks
tyhicks at canonical.com
Wed Apr 23 21:42:26 UTC 2014
On 2014-04-23 23:31:23, Christian Boltz wrote:
> Hello,
>
> Am Mittwoch, 23. April 2014 schrieb Tyler Hicks:
> > Remove duplicated test code by adding a simple way for regex test
> > classes to declare a regex to use and a list of tuples consisting of
> > (line, expected_result). The setup_regex_tests() method generates test
> > methods for each tuple in a classes list. The test methods are based
> > on the regex_test() method, which performs the regex search and
> > compares the results to the expected_result.
> >
> > Signed-off-by: Tyler Hicks <tyhicks at canonical.com>
> > Cc: Christian Boltz <apparmor at cboltz.de>
> > ---
> >
> > This patch is meant to address feedback from cboltz regarding
> > duplicated test code in test-regex_matches.py:
> >
> > https://lists.ubuntu.com/archives/apparmor/2014-April/005613.html
> >
> > utils/test/test-regex_matches.py | 449
> > ++++++++++----------------------------- 1 file changed,
> > 114 insertions(+), 335 deletions(-)
>
> That insert/delete relation explains why I asked for this patch ;-)
>
>
> Let me quote the resulting file instead of the patch to get a more readable version:
>
> > def regex_test(self, line, expected):
> ...
> > for (i, group) in enumerate(groups):
> > if group:
> > group = group.strip()
> >
> > self.assertEqual(group, expected[i], 'Group %d mismatch' % i)
>
> The error message could be a bit more helpful, like
> Group %d mismatch - expected %s, found %s
unittest gives you that for free. For example, I changed one of the
expected values from None to 'deny' and here's the test failure message:
======================================================================
FAIL: test_5 (__main__.AARegexPivotRoot)
test ' audit pivot_root /old /new -> child,'
----------------------------------------------------------------------
Traceback (most recent call last):
File "test/test-regex_matches.py", line 172, in stub_test
regex_test(self, line, expected)
File "test/test-regex_matches.py", line 159, in regex_test
self.assertEqual(group, expected[i], 'Group %d mismatch' % i)
AssertionError: None != 'deny' : Group 1 mismatch
----------------------------------------------------------------------
>
>
> The test cases itsself (class AARegex*) look very good and are much
> easier to read and to maintain :-)
>
> > class AARegexBareFile(unittest.TestCase):
> > '''Tests for RE_PROFILE_BARE_FILE_ENTRY'''
> >
> > regex = aa.RE_PROFILE_BARE_FILE_ENTRY
> >
> > tests = [
> > (' file,', (None, None, None, None)),
>
> Please also add
> (' owner file , ', (None, None, 'owner', None)),
> (' audit owner file , ', ('audit', None, 'owner', None)),
> (' deny file , ', (None, 'deny', None, None)),
>
> (untested, but should work ;-)
Added and tested
>
> > class AARegexPivotRoot(unittest.TestCase):
> ...
> > (' pivot_root /old,', (None, None, 'pivot_root /old,', None)),
> > (' pivot_root /old /new,',
> > (None, None, 'pivot_root /old /new,', None)),
> > (' pivot_root /old /new -> child,',
> > (None, None, 'pivot_root /old /new -> child,', None)),
> > (' audit pivot_root /old /new -> child,',
> > ('audit', None, 'pivot_root /old /new -> child,', None)),
>
> Those rules contain an invalid syntax ;-)
> Please replace /old with oldroot=/old in all lines quoted above.
I changed these to 'oldroot=/new/old' since pivot_root(2) requires put_old to
be under new_root.
>
> With the things listed above fixed,
> Acked-by: Christian Boltz <apparmor at cboltz.de>
Thanks again!
Tyler
>
>
> Regards,
>
> Christian Boltz
> --
> > Was ist ein "umbrella bug"?
> Eine Regenschirm-Wanze ;-)
> [> Al Bogner und Andreas Winkelmann in suse-linux]
>
>
> --
> AppArmor mailing list
> AppArmor at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/apparmor
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20140423/77351d91/attachment.pgp>
More information about the AppArmor
mailing list