~attente/apparmor/dconf-rules

« back to all changes in this revision

Viewing changes to utils/test/test-baserule.py

  • Committer: Christian Boltz
  • Date: 2015-04-26 19:59:12 UTC
  • Revision ID: apparmor@cboltz.de-20150426195912-k01ff1lpucf488ak
Add match() and _match() class methods to rule classes

Add match() and _match() class methods to rule classes:
- _match() returns a regex match object for the given raw_rule
- match() converts the _match() result to True or False

The primary usage is to get an answer to the question "is this raw_rule
your job?". (For a moment, I thought about naming the function
*Rule.myjob() instead of *Rule.match() ;-)

My next patch will change aa.py to use *Rule.match() instead of directly
using RE_*, which will make the import list much shorter and hide
another implementation detail inside the rule classes.

Also change _parse() to use _match() instead of the regex, and add some
tests for match() and _match().


Acked-by: Seth Arnold <seth.arnold@canonical.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
        with self.assertRaises(AppArmorBug):
23
23
            BaseRule._parse('foo')
24
24
 
 
25
    def test_abstract__parse_2(self):
 
26
        with self.assertRaises(AppArmorBug):
 
27
            BaseRule.parse('foo')
 
28
 
 
29
    def test_abstract__match(self):
 
30
        with self.assertRaises(AppArmorBug):
 
31
            BaseRule._match('foo')
 
32
 
 
33
    def test_abstract__match2(self):
 
34
        with self.assertRaises(AppArmorBug):
 
35
            BaseRule.match('foo')
 
36
 
25
37
    def test_is_equal_localvars(self):
26
38
        obj = BaseRule()
27
39
        with self.assertRaises(AppArmorBug):