2016-03-10 09:12:23 +00:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import mock
|
|
|
|
import unittest
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import StringIO
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
|
|
|
|
from pungi import checks
|
|
|
|
|
|
|
|
|
|
|
|
class CheckDependenciesTestCase(unittest.TestCase):
|
2016-03-10 09:44:21 +00:00
|
|
|
|
|
|
|
def dont_find(self, paths):
|
|
|
|
return lambda path: path not in paths
|
|
|
|
|
2016-03-10 09:12:23 +00:00
|
|
|
def test_all_deps_missing(self):
|
|
|
|
def custom_exists(path):
|
|
|
|
return False
|
|
|
|
|
|
|
|
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
|
|
|
with mock.patch('os.path.exists') as exists:
|
|
|
|
exists.side_effect = custom_exists
|
|
|
|
result = checks.check({})
|
|
|
|
|
2016-03-10 09:44:21 +00:00
|
|
|
self.assertGreater(len(out.getvalue().strip().split('\n')), 1)
|
2016-03-10 09:12:23 +00:00
|
|
|
self.assertFalse(result)
|
|
|
|
|
|
|
|
def test_all_deps_ok(self):
|
|
|
|
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
2016-03-10 17:54:14 +00:00
|
|
|
with mock.patch('platform.machine') as machine:
|
|
|
|
machine.return_value = 'x86_64'
|
|
|
|
with mock.patch('os.path.exists') as exists:
|
|
|
|
exists.side_effect = self.dont_find([])
|
|
|
|
result = checks.check({})
|
2016-03-10 09:12:23 +00:00
|
|
|
|
|
|
|
self.assertEqual('', out.getvalue())
|
|
|
|
self.assertTrue(result)
|
|
|
|
|
|
|
|
def test_does_not_require_jigdo_if_not_configured(self):
|
|
|
|
conf = {
|
|
|
|
'create_jigdo': False
|
|
|
|
}
|
|
|
|
|
2016-03-10 11:47:49 +00:00
|
|
|
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
2016-03-10 17:54:14 +00:00
|
|
|
with mock.patch('platform.machine') as machine:
|
|
|
|
machine.return_value = 'x86_64'
|
|
|
|
with mock.patch('os.path.exists') as exists:
|
|
|
|
exists.side_effect = self.dont_find(['/usr/bin/jigdo-lite'])
|
|
|
|
result = checks.check(conf)
|
2016-03-10 09:44:21 +00:00
|
|
|
|
2016-03-10 11:47:49 +00:00
|
|
|
self.assertEqual('', out.getvalue())
|
2016-03-10 09:44:21 +00:00
|
|
|
self.assertTrue(result)
|
|
|
|
|
|
|
|
def test_isohybrid_not_required_without_productimg_phase(self):
|
|
|
|
conf = {
|
|
|
|
'bootable': True,
|
|
|
|
'productimg': False,
|
|
|
|
'runroot': True,
|
|
|
|
}
|
|
|
|
|
2016-03-10 11:47:49 +00:00
|
|
|
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
|
|
|
with mock.patch('os.path.exists') as exists:
|
|
|
|
exists.side_effect = self.dont_find(['/usr/bin/isohybrid'])
|
|
|
|
result = checks.check(conf)
|
2016-03-10 09:44:21 +00:00
|
|
|
|
2016-03-10 11:47:49 +00:00
|
|
|
self.assertEqual('', out.getvalue())
|
2016-03-10 09:44:21 +00:00
|
|
|
self.assertTrue(result)
|
|
|
|
|
|
|
|
def test_isohybrid_not_required_on_not_bootable(self):
|
|
|
|
conf = {
|
|
|
|
'bootable': False,
|
|
|
|
'runroot': True,
|
|
|
|
}
|
2016-03-10 09:12:23 +00:00
|
|
|
|
2016-03-10 11:47:49 +00:00
|
|
|
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
|
|
|
with mock.patch('os.path.exists') as exists:
|
|
|
|
exists.side_effect = self.dont_find(['/usr/bin/isohybrid'])
|
|
|
|
result = checks.check(conf)
|
2016-03-10 09:12:23 +00:00
|
|
|
|
2016-03-10 11:47:49 +00:00
|
|
|
self.assertEqual('', out.getvalue())
|
2016-03-10 09:12:23 +00:00
|
|
|
self.assertTrue(result)
|
|
|
|
|
2016-03-10 09:44:21 +00:00
|
|
|
def test_isohybrid_not_required_on_arm(self):
|
|
|
|
conf = {
|
|
|
|
'bootable': True,
|
|
|
|
'productimg': True,
|
|
|
|
'runroot': True,
|
|
|
|
}
|
|
|
|
|
|
|
|
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
|
|
|
with mock.patch('platform.machine') as machine:
|
|
|
|
machine.return_value = 'armhfp'
|
|
|
|
with mock.patch('os.path.exists') as exists:
|
|
|
|
exists.side_effect = self.dont_find(['/usr/bin/isohybrid'])
|
|
|
|
result = checks.check(conf)
|
|
|
|
|
|
|
|
self.assertRegexpMatches(out.getvalue(), r'^Not checking.*Expect failures.*$')
|
|
|
|
self.assertTrue(result)
|
|
|
|
|
|
|
|
def test_isohybrid_not_needed_in_runroot(self):
|
|
|
|
conf = {
|
|
|
|
'runroot': True,
|
|
|
|
}
|
|
|
|
|
2016-03-10 11:47:49 +00:00
|
|
|
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
|
|
|
with mock.patch('os.path.exists') as exists:
|
|
|
|
exists.side_effect = self.dont_find(['/usr/bin/isohybrid'])
|
|
|
|
result = checks.check(conf)
|
2016-03-10 10:23:45 +00:00
|
|
|
|
2016-03-10 11:47:49 +00:00
|
|
|
self.assertEqual('', out.getvalue())
|
2016-03-10 10:23:45 +00:00
|
|
|
self.assertTrue(result)
|
|
|
|
|
|
|
|
def test_genisoimg_not_needed_in_runroot(self):
|
|
|
|
conf = {
|
|
|
|
'runroot': True,
|
|
|
|
}
|
|
|
|
|
2016-03-10 11:47:49 +00:00
|
|
|
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
|
|
|
with mock.patch('os.path.exists') as exists:
|
|
|
|
exists.side_effect = self.dont_find(['/usr/bin/genisoimage'])
|
|
|
|
result = checks.check(conf)
|
2016-03-10 10:23:45 +00:00
|
|
|
|
2016-03-10 11:47:49 +00:00
|
|
|
self.assertEqual('', out.getvalue())
|
2016-03-10 10:23:45 +00:00
|
|
|
self.assertTrue(result)
|
|
|
|
|
|
|
|
def test_genisoimg_needed_for_productimg(self):
|
|
|
|
conf = {
|
|
|
|
'runroot': True,
|
|
|
|
'productimg': True,
|
|
|
|
'bootable': True,
|
|
|
|
}
|
|
|
|
|
|
|
|
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
2016-03-10 09:44:21 +00:00
|
|
|
with mock.patch('os.path.exists') as exists:
|
2016-03-10 10:23:45 +00:00
|
|
|
exists.side_effect = self.dont_find(['/usr/bin/genisoimage'])
|
2016-03-10 09:44:21 +00:00
|
|
|
result = checks.check(conf)
|
|
|
|
|
2016-03-10 10:23:45 +00:00
|
|
|
self.assertIn('genisoimage', out.getvalue())
|
|
|
|
self.assertFalse(result)
|
|
|
|
|
2016-03-10 09:12:23 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|