Merge lp:~psivaa/auto-upgrade-testing/bug1159671 into lp:~auto-upgrade-testing-dev/auto-upgrade-testing/trunk

Proposed by Para Siva
Status: Needs review
Proposed branch: lp:~psivaa/auto-upgrade-testing/bug1159671
Merge into: lp:~auto-upgrade-testing-dev/auto-upgrade-testing/trunk
Diff against target: 125 lines (+32/-18)
1 file modified
share/post_upgrade_tests/test_python_import.py (+32/-18)
To merge this branch: bzr merge lp:~psivaa/auto-upgrade-testing/bug1159671
Reviewer Review Type Date Requested Status
Para Siva (community) Needs Resubmitting
Paul Larson (community) Needs Fixing
Auto Upgrade Testing Developers Pending
Review via email: mp+155819@code.launchpad.net

Description of the change

The change is to try and import all the possible modules from sys.path as specified in bug 1159671.
The main change is on rev 75. The next one is re: pep8 changes.

To post a comment you must log in.
Revision history for this message
Paul Larson (pwlars) wrote :

82 - self.distpackages = '/usr/lib/%s/dist-packages/' % self.default_version
83 - self.stderr = open('/tmp/%s.stderr' % os.path.basename(__file__)[:-3],'w')
84 + self.distpackages = []
85 + for dist_path in sys.path:
86 + if 'dist-packages' in dist_path:
One of the goals here was to specifically pick up the python standard libraries. Restricting to dist-packages won't accomplish that unfortunately.

87 + if dist_path[0:dist_path.find('dist-packages') + 13] \
I prefer to avoid magic numbers

review: Needs Fixing
77. By Para Siva

Allowing to test the imports from all the possible paths in sys.path

Revision history for this message
Para Siva (psivaa) wrote :

OK, thanks. The restriction of testing the imports from dist-packages has now been removed. That removed the magic number changes too. It would be helpful to get the feedback on this. Thanks

review: Needs Resubmitting

Unmerged revisions

77. By Para Siva

Allowing to test the imports from all the possible paths in sys.path

76. By Para Siva

Formatting pep8 changes

75. By Para Siva

testing python imports from sys.path

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'share/post_upgrade_tests/test_python_import.py'
2--- share/post_upgrade_tests/test_python_import.py 2012-08-08 09:53:18 +0000
3+++ share/post_upgrade_tests/test_python_import.py 2013-04-05 15:05:26 +0000
4@@ -13,6 +13,7 @@
5 import os
6 import logging
7 import subprocess
8+import sys
9
10 logging.basicConfig(
11 filename='/tmp/%s.log' % os.path.basename(__file__)[:-3],
12@@ -24,9 +25,9 @@
13 "PAMmodule.so",
14 "aomodule.so",
15 "plannerui.so",
16- "desktopcouch", # needs a KeyringDaemon
17- "ropemacs", # just hangs
18- "keyring", # needs X
19+ "desktopcouch", # needs a KeyringDaemon
20+ "ropemacs", # just hangs
21+ "keyring", # needs X
22 "invest",
23 "Onboard",
24 "goocanvasmodule.so",
25@@ -34,8 +35,9 @@
26
27 # If you want to test modules that require a display you'll have to install
28 # xvfb in the base image
29-XVFB_BIN='/usr/bin/xvfb-run'
30-XVFB_OPT=[]
31+XVFB_BIN = '/usr/bin/xvfb-run'
32+XVFB_OPT = []
33+
34
35 def py_module_filter(pymodule):
36 return not (
37@@ -47,6 +49,7 @@
38 pymodule in BLACKLIST
39 )
40
41+
42 def get_module_from_path(path):
43 f = os.path.basename(path)
44 if path and os.path.exists(os.path.join(path, "__init__.py")):
45@@ -60,6 +63,7 @@
46 elif f.endswith(".so"):
47 return f.split(".")[0]
48
49+
50 class TestPython(unittest.TestCase):
51 # total imports
52 total = 0
53@@ -81,16 +85,19 @@
54 return rc
55
56 try:
57- cmd = ["python", "-c","import %s" % module]
58+ cmd = ["python", "-c", "import %s" % module]
59 self.total += 1
60- subprocess.check_call(cmd, stderr = self.stderr)
61+ subprocess.check_call(cmd, stderr=self.stderr)
62 except subprocess.CalledProcessError:
63 try:
64- pkg = subprocess.check_output(["dpkg", "-S", os.path.realpath(path)])
65+ pkg = subprocess.check_output(["dpkg", "-S",
66+ os.path.realpath(path)])
67 self.failed.append((module, pkg.strip()))
68- logging.error('Import failed. Package providing this module: %s', pkg)
69+ logging.error('Import failed. Package providing this \
70+ module: %s', pkg)
71 except subprocess.CalledProcessError:
72- logging.error("Import of %s failed, and no package ships this module.", path)
73+ logging.error("Import of %s failed, and no \
74+ package ships this module.", path)
75 rc = False
76 return rc
77
78@@ -99,8 +106,8 @@
79 config = ConfigParser.SafeConfigParser()
80 config.read('/usr/share/python/debian_defaults')
81 self.default_version = config.get('DEFAULT', 'default-version')
82- self.distpackages = '/usr/lib/%s/dist-packages/' % self.default_version
83- self.stderr = open('/tmp/%s.stderr' % os.path.basename(__file__)[:-3],'w')
84+ self.stderr = open('/tmp/%s.stderr' % os.path.basename
85+ (__file__)[:-3], 'w')
86
87 def tearDown(self):
88 self.stderr.close()
89@@ -109,23 +116,30 @@
90 '''Import python modules from /usr/lib/PYTHONVER/dist-packages/'''
91 res = True
92
93- for module in filter(py_module_filter, os.listdir(self.distpackages)):
94- res &= self._try_import(os.path.join(self.distpackages, module))
95+ for package_path in sys.path:
96+ if os.path.exists(package_path):
97+ for module in filter(py_module_filter,
98+ os.listdir(package_path)):
99+ res &= self._try_import(os.path.join(package_path,
100+ module))
101
102 logging.info('Modules imported: %d', self.total)
103 if res:
104 logging.info('No failure')
105
106- self.assertTrue(res, '%d module(s) failed to import' % len(self.failed))
107+ self.assertTrue(res, '%d module(s) failed to import' %
108+ len(self.failed))
109
110 if __name__ == '__main__':
111 if 'DISPLAY' in os.environ:
112 unittest.main()
113 elif os.path.exists(XVFB_BIN):
114- logging.info("'%s' found and DISPLAY not set. Re-executing myself with xvfb")
115- cmd = [ XVFB_BIN ] + XVFB_OPT + [os.path.abspath(__file__)]
116+ logging.info("'%s' found and DISPLAY not set. \
117+ Re-executing myself with xvfb")
118+ cmd = [XVFB_BIN] + XVFB_OPT + [os.path.abspath(__file__)]
119 logging.info(cmd)
120 subprocess.call(cmd)
121 else:
122- logging.warning("'%s' not found and DISPLAY not set. Executing test without a display", XVFB_BIN)
123+ logging.warning("'%s' not found and DISPLAY not set. Executing \
124+ test without a display", XVFB_BIN)
125 unittest.main()

Subscribers

People subscribed via source and target branches