apparmor/utils/test
Christian Boltz c0b5d90848 Merge Resolve "Python: Ensure opened files are closed."
This MR closes #239. In the temporary file commit, `tempfile.NamedTemporaryFile` is preferred over `tempfile.mkstemp` because it allows for simpler use of context managers and lets you choose what mode to open the file in. Also in this commit, note that in `aa.py` and `easyprof.py` destination files are now written directly, instead of writing to temp files and then renaming them.

Closes #239
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/898
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-07-20 19:34:16 +00:00
..
wtmp-examples Add truncated and ancient wtmp example to tests 2021-10-24 17:24:43 +02:00
cleanprof_test.in Preserve 'hat' keyword in ProfileStorage 2021-05-23 18:19:28 +02:00
cleanprof_test.out Preserve 'hat' keyword in ProfileStorage 2021-05-23 18:19:28 +02:00
common_test.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
easyprof.conf This patchset is broken into 4 parts: 2012-05-07 22:37:48 -07:00
fake_ldd utils: fixup test-aa.py tests that fail due to usr-merge 2019-02-12 23:17:59 -08:00
logprof.conf Fix extra profiles path in utils/test/logprof.conf 2021-07-13 21:09:35 +02:00
Makefile reviewed edits 2022-07-19 21:47:02 +02:00
README.md use new build_platlib path with setuptools >= 61.2 2022-07-16 17:47:18 +02:00
runtests-py3.sh fix utils/test/runtests-py*.sh exitcode 2014-10-03 11:48:21 +02:00
severity_broken.db Update perl abstraction, logprof.conf, severity.db and tests for Debian/Ubuntu 2014-08-20 19:14:24 -05:00
test-aa-cli-bootstrap.py Add tests for shared aa library functions used in command line scripts 2019-04-21 18:37:10 +03:00
test-aa-decode.py Ensure opened temporary files are closed. 2022-07-17 21:52:55 -04:00
test-aa-easyprof.py Remove Python 2 support. 2022-06-29 20:41:38 -04:00
test-aa-notify.py Ensure opened temporary files are closed. 2022-07-17 21:52:55 -04:00
test-aa.py Remove Python 2 support. 2022-06-29 20:41:38 -04:00
test-aare.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-abi.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-alias.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-baserule.py Run severity tests with official severity.db 2021-04-14 21:37:53 +02:00
test-boolean.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-capability.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-change_profile.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-common.py Remove Python 2 support. 2022-06-29 20:41:38 -04:00
test-config.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-dbus.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-example.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-file.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-include.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-libapparmor-test_multi.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-logparser.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-minitools.py Remove Python 2 support. 2022-06-29 20:41:38 -04:00
test-mount_parse.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-network.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-notify.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-parser-simple-tests.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-pivot_root_parse.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-profile-list.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-profile-storage.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-profiles.py Add option to skip reading specific profiles 2021-07-13 21:09:36 +02:00
test-ptrace.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-regex_matches.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-rlimit.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-severity.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-signal.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-translations.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-unix_parse.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
test-variable.py Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00

Test data generated elsewhere

The tests in parser generate additional test profiles in parser/tst/simple_tests/: see gen-dbus.py and gen-xtrans.py.

utils/test/test-parser-simple-tests.py uses this test data when it is available. If this test data has not been generated, this test will not complain: it will simply exercise fewer test profiles.

Running individual tests

Python's unittest allows individual tests to be executed by specifying the class name and the test on the command line. When running tests individually, the unittest framework executes the "setUp" and "tearDown" methods automatically. For more information, refer to the unittest documentation.

Make sure to set the environment variables pointing to the in-tree apparmor modules, and the in-tree libapparmor and its python wrapper:

$ export PYTHONPATH=..:../../libraries/libapparmor/swig/python/build/$(/usr/bin/python3 ../../libraries/libapparmor/swig/python/test/buildpath.py)
$ export __AA_CONFDIR=.

To execute the test individually, run:

$ python3 ./test-tile.py ClassFoo.test_bar