selinux/policycoreutils/audit2allow/test_audit2allow.py
Jason Zaman 789d0ebbf9 policycoreutils: Fix PEP8 issues
When trying to get policycoreutils working in python3, I kept running
into TabErrors:

    Traceback (most recent call last):
      File "/usr/lib/python-exec/python3.3/semanage", line 27, in <module>
        import seobject
      File "/usr/lib64/python3.3/site-packages/seobject.py", line 154
        context = "%s%s" % (filler, raw)
                                       ^
    TabError: inconsistent use of tabs and spaces in indentation

Python3 is a lot stricter than python2 regarding whitespace and looks like
previous commits mixed the two.  When fixing this, I took the chance to fix
other PEP8 style issues at the same time.

This commit was made using:
$ file $(find . -type f) | grep -i python | sed 's/:.*$//' > pyfiles
$ autopep8 --in-place --ignore=E501,E265 $(cat pyfiles)

The ignore E501 is long lines since there are many that would be wrapped
otherwise, and E265 is block comments that start with ## instead of just #.

Signed-off-by: Jason Zaman <jason@perfinion.com>
2015-07-24 16:07:13 +08:00

52 lines
1.6 KiB
Python

import unittest
import os
import shutil
from tempfile import mkdtemp
from subprocess import Popen, PIPE
class Audit2allowTests(unittest.TestCase):
def assertDenied(self, err):
self.assertTrue('Permission denied' in err,
'"Permission denied" not found in %r' % err)
def assertNotFound(self, err):
self.assertTrue('not found' in err,
'"not found" not found in %r' % err)
def assertFailure(self, status):
self.assertTrue(status != 0,
'"Succeeded when it should have failed')
def assertSuccess(self, cmd, status, err):
self.assertTrue(status == 0,
'"%s should have succeeded for this test %r' % (cmd, err))
def test_sepolgen_ifgen(self):
"Verify sepolgen-ifgen works"
p = Popen(['sudo', 'sepolgen-ifgen'], stdout=PIPE)
out, err = p.communicate()
if err:
print(out, err)
self.assertSuccess("sepolgen-ifgen", p.returncode, err)
def test_audit2allow(self):
"Verify audit2allow works"
p = Popen(['audit2allow', "-i", "test.log"], stdout=PIPE)
out, err = p.communicate()
if err:
print(out, err)
self.assertSuccess("audit2allow", p.returncode, err)
def test_audit2why(self):
"Verify audit2why works"
p = Popen(['audit2why', "-i", "test.log"], stdout=PIPE)
out, err = p.communicate()
if err:
print(out, err)
self.assertSuccess("audit2why", p.returncode, err)
if __name__ == "__main__":
unittest.main()