refactoring, add tests for passing and failing adt test

bzr-import-20160707
Martin Pitt 11 years ago
parent e1dc047c7e
commit fecf3be811

@ -199,54 +199,88 @@ args.func()
''' % {'py': sys.executable, 'path': self.data.path, 'rq': request}) ''' % {'py': sys.executable, 'path': self.data.path, 'rq': request})
def run_britney(self, args=[]): def run_britney(self, args=[]):
'''Run britney and return (exit, out, err)''' '''Run britney.
Assert that it succeeds and does not produce anything on stderr.
Return generated excuses.html output.
'''
britney = subprocess.Popen([self.britney, '-c', self.britney_conf], britney = subprocess.Popen([self.britney, '-c', self.britney_conf],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
cwd=self.data.path, cwd=self.data.path,
universal_newlines=True) universal_newlines=True)
(out, err) = britney.communicate() (out, err) = britney.communicate()
return (britney.returncode, out, err) self.assertEqual(britney.returncode, 0, out + err)
self.assertEqual(err, '')
def test_no_request_for_uninstallable(self):
'''Does not request a test for an uninstallable package'''
# uninstallable unstable version
self.data.add('green', True,
{'Version': '1.1~beta',
'Depends': 'libc6 (>= 0.9), libgreen1 (>= 2)'})
self.make_adt_britney('green 1.1~beta FAIL green 1.1~beta\n')
(c, o, e) = self.run_britney()
self.assertEqual(e, '', e)
self.assertEqual(c, 0, o + e)
with open(os.path.join(self.data.path, 'output', 'excuses.html')) as f: with open(os.path.join(self.data.path, 'output', 'excuses.html')) as f:
excuses = f.read() excuses = f.read()
self.assertIn('green/amd64 unsatisfiable Depends: libgreen1 (>= 2)', excuses)
# does not request autopkgtest for uninstallable package
self.assertNotIn('autopkgtest', excuses)
def test_request_for_installable(self): return excuses
'''Requests a test for an installable package'''
# installable unstable version def test_no_request_for_uninstallable(self):
self.data.add('green', True, '''Does not request a test for an uninstallable package'''
{'Version': '1.1~beta',
'Depends': 'libc6 (>= 0.9), libgreen1'})
self.make_adt_britney('green 1.1~beta RUNNING green 1.1~beta\n') self.do_test(
# uninstallable unstable version
[('green', {'Version': '1.1~beta', 'Depends': 'libc6 (>= 0.9), libgreen1 (>= 2)'})],
'green 1.1~beta RUNNING green 1.1~beta\n',
False,
[r'\bgreen\b.*>1</a> to .*>1.1~beta<',
'green/amd64 unsatisfiable Depends: libgreen1 \(>= 2\)'],
# autopkgtest should not be triggered for uninstallable pkg
['autopkgtest'])
def test_request_for_installable_running(self):
'''Requests a test for an installable package, test still running'''
self.do_test(
[('green', {'Version': '1.1~beta', 'Depends': 'libc6 (>= 0.9), libgreen1'})],
'green 1.1~beta RUNNING green 1.1~beta\n',
False,
[r'\bgreen\b.*>1</a> to .*>1.1~beta<',
'<li>autopkgtest for green 1.1~beta: RUNNING'])
def test_request_for_installable_fail(self):
'''Requests a test for an installable package, test fail'''
self.do_test(
[('green', {'Version': '1.1~beta', 'Depends': 'libc6 (>= 0.9), libgreen1'})],
'green 1.1~beta FAIL green 1.1~beta\n',
False,
[r'\bgreen\b.*>1</a> to .*>1.1~beta<',
'<li>autopkgtest for green 1.1~beta: FAIL'])
def test_request_for_installable_pass(self):
'''Requests a test for an installable package, test pass'''
self.do_test(
[('green', {'Version': '1.1~beta', 'Depends': 'libc6 (>= 0.9), libgreen1'})],
'green 1.1~beta PASS green 1.1~beta\n',
True,
[r'\bgreen\b.*>1</a> to .*>1.1~beta<',
'<li>autopkgtest for green 1.1~beta: PASS'])
def do_test(self, unstable_add, adt_request, considered, expect=None,
no_expect=None):
for (pkg, fields) in unstable_add:
self.data.add(pkg, True, fields)
self.make_adt_britney(adt_request)
excuses = self.run_britney()
if considered:
self.assertIn('Valid candidate', excuses)
else:
self.assertIn('Not considered', excuses)
(c, o, e) = self.run_britney() if expect:
self.assertEqual(c, 0, o + e) for re in expect:
self.assertEqual(e, '') self.assertRegexpMatches(excuses, re)
if no_expect:
for re in no_expect:
self.assertNotRegexpMatches(excuses, re)
with open(os.path.join(self.data.path, 'output', 'excuses.html')) as f:
excuses = f.read()
self.assertRegexpMatches(excuses, r'\bgreen\b.*>1</a> to .*>1.1~beta<')
self.assertIn('<li>autopkgtest for green 1.1~beta: RUNNING', excuses)
def shell(self): def shell(self):
# uninstallable unstable version # uninstallable unstable version

Loading…
Cancel
Save