2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-30 13:58:22 +00:00

Adjust test-aa.py for python2

This means:
- expect unicode (instead of str) when reading from a file in py2
- convert keys() result to a set to avoid test failures because of
  dict_keys type

After this change, all tests work for both py2 and py3.


Acked-by: Tyler Hicks <tyhicks@canonical.com> for trunk and 2.10.
This commit is contained in:
Christian Boltz
2015-12-17 23:44:18 +01:00
parent 6f63cf3664
commit 726fa53eeb

View File

@@ -75,7 +75,7 @@ class AaTest_check_for_apparmor(AaTestWithTempdir):
class AaTest_create_new_profile(AATest):
tests = [
# file content expected interpreter expected abstraction (besides 'base')
('#!/bin/bash\ntrue', ('/bin/bash', 'abstractions/bash')),
('#!/bin/bash\ntrue', (u'/bin/bash', 'abstractions/bash')),
('foo bar', (None, None)),
]
def _run_test(self, params, expected):
@@ -89,16 +89,16 @@ class AaTest_create_new_profile(AATest):
self.assertEqual(profile[program][program]['allow']['path'][exp_interpreter_path]['audit'], set() )
self.assertEqual(profile[program][program]['allow']['path'][program]['mode'], {'r', '::r'} )
self.assertEqual(profile[program][program]['allow']['path'][program]['audit'], set() )
self.assertEqual(profile[program][program]['allow']['path'].keys(), {exp_interpreter_path, program} )
self.assertEqual(set(profile[program][program]['allow']['path'].keys()), {program, exp_interpreter_path} )
else:
self.assertEqual(profile[program][program]['allow']['path'][program]['mode'], {'r', '::r', 'm', '::m'} )
self.assertEqual(profile[program][program]['allow']['path'][program]['audit'], set() )
self.assertEqual(profile[program][program]['allow']['path'].keys(), {program} )
self.assertEqual(set(profile[program][program]['allow']['path'].keys()), {program} )
if exp_abstraction:
self.assertEqual(profile[program][program]['include'].keys(), {exp_abstraction, 'abstractions/base'})
self.assertEqual(set(profile[program][program]['include'].keys()), {exp_abstraction, 'abstractions/base'})
else:
self.assertEqual(profile[program][program]['include'].keys(), {'abstractions/base'})
self.assertEqual(set(profile[program][program]['include'].keys()), {'abstractions/base'})
class AaTest_get_interpreter_and_abstraction(AATest):
tests = [