apparmor/utils/test/test-example.py
Christian Boltz 5fa5125fd4 Add tempdir and tempfile handling to AATest
Add writeTmpfile() to AATest to write a file into the tmpdir. If no
tmpdir exists yet, automatically create one.

createTmpdir() is a separate function so that it's possible to manually
create the tmpdir (for example, if a test needs an empty tmpdir).

Also add a tearDown() function to delete the tmpdir again. This function
calls self.AATeardown() to avoid the need for super() in child classes.

Finally, simplify AaTestWithTempdir in test-aa.py to use createTmpdir()
and add an example for AATeardown() to test-example.py.



Acked-by: Steve Beattie <steve@nxnw.org>
2015-05-29 12:55:38 +02:00

53 lines
1.3 KiB
Python

#! /usr/bin/env python
# ------------------------------------------------------------------
#
# Copyright (C) 2015 Christian Boltz <apparmor@cboltz.de>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License published by the Free Software Foundation.
#
# ------------------------------------------------------------------
import unittest
from common_test import AATest, setup_all_loops
class TestFoo(AATest):
tests = [
(0, 0 ),
(42, 42),
]
def _run_test(self, params, expected):
self.assertEqual(params, expected)
class TestBar(AATest):
tests = [
('a', 'foo'),
('b', 'bar'),
('c', 'baz'),
]
def _run_test(self, params, expected):
self.assertNotEqual(params, expected)
def testAdditionalBarTest(self):
self.assertEqual(1, 1)
class TestBaz(AATest):
def AASetup(self):
# called by setUp() - use AASetup() to avoid the need for using super(...)
pass
def AATeardown(self):
# called by tearDown() - use AATeardown() to avoid the need for using super(...)
pass
def test_Baz_only_one_test(self):
self.assertEqual("baz", "baz")
setup_all_loops(__name__)
if __name__ == '__main__':
unittest.main(verbosity=2)