~talkless/apparmor/fix_user_download_nonlatin

« back to all changes in this revision

Viewing changes to utils/test/test-aa-easyprof.py

  • Committer: Tyler Hicks
  • Date: 2017-03-02 21:25:01 UTC
  • Revision ID: tyhicks@canonical.com-20170302212501-qa7332ix8i39psp4
utils: Fix apparmor.easyprof import in test-aa-easyprof.py

The test-aa-easyprof.py script was attempting to do its own special
setup to import the in-tree easyprof module. However, this proved to be
very flaky and resulted in the test periodically failing due to an
AttributeError the first time easyprof.parse_args() was called.

This patch removes the flakiness by trusting that PYTHONPATH is set up
appropriately before the test script is ran. PYTHONPATH is already
initialized appropriately by utils/test/Makefile according to the
USE_SYSTEM make variable.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import tempfile
19
19
import unittest
20
20
 
 
21
import apparmor.easyprof as easyprof
 
22
 
21
23
topdir = None
22
24
debugging = False
23
25
 
2673
2675
# Main
2674
2676
#
2675
2677
if __name__ == '__main__':
2676
 
    def cleanup(files):
2677
 
        for f in files:
2678
 
            if os.path.exists(f):
2679
 
                os.unlink(f)
2680
 
 
2681
2678
    absfn = os.path.abspath(sys.argv[0])
2682
2679
    topdir = os.path.dirname(os.path.dirname(absfn))
2683
2680
 
2684
2681
    if len(sys.argv) > 1 and (sys.argv[1] == '-d' or sys.argv[1] == '--debug'):
2685
2682
        debugging = True
2686
2683
 
2687
 
    created = []
2688
 
 
2689
 
    # Create the necessary files to import aa-easyprof
2690
 
    init = os.path.join(os.path.dirname(absfn), '__init__.py')
2691
 
    if not os.path.exists(init):
2692
 
        open(init, 'a').close()
2693
 
        created.append(init)
2694
 
 
2695
 
    symlink = os.path.join(os.path.dirname(absfn), 'easyprof.py')
2696
 
    if not os.path.exists(symlink):
2697
 
        os.symlink(os.path.join(topdir, 'apparmor', 'easyprof.py'), symlink)
2698
 
        created.append(symlink)
2699
 
        created.append(symlink + 'c')
2700
 
 
2701
 
    # Now that we have everything we need, import aa-easyprof
2702
 
    import easyprof
2703
 
 
2704
2684
    # run the tests
2705
2685
    suite = unittest.TestSuite()
2706
2686
    suite.addTest(unittest.TestLoader().loadTestsFromTestCase(T))
2707
2687
    rc = unittest.TextTestRunner(verbosity=2).run(suite)
2708
2688
 
2709
 
    cleanup(created)
2710
 
 
2711
2689
    if not rc.wasSuccessful():
2712
2690
        sys.exit(1)