[apparmor] [patch] Adjust test-aa.py for python2

Christian Boltz apparmor at cboltz.de
Sun Nov 29 21:34:43 UTC 2015


Hello,

$subject.

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.


I propose this patch for trunk and 2.10.
(Nothing to fix in 2.9 - it doesn't have this test.)



[ 22-adjust-test-aa-for-py2.diff ]

=== modified file ./utils/test/test-aa.py
--- utils/test/test-aa.py       2015-11-19 17:42:26.329879090 +0100
+++ utils/test/test-aa.py       2015-11-29 21:44:36.968433594 +0100
@@ -75,7 +75,7 @@
 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 @@
             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 = [



Regards,

Christian Boltz
-- 
> Kann ich auf einen Bootloader (lilo oder grub) verzichten,
> falls auf der Festplatte nur 2 Partitionen sind
Klar kannst du. Vorausgesetzt du kannst auch darauf verzichten
das Betriebssystem zu booten.
[> Wolfgang Erlenkötter und Hartmut Meyer in suse-linux]




More information about the AppArmor mailing list