def test_mode_any(self): '''calling with --mode any''' sys.argv = ['ui-test', '--list', '--mode', 'any'] ui = sandbox.TestUI() self.assertEqual(sandbox.TestUI().run(), 0) displayed = set(ui.get_displayed_handlers()) self.stop_capture() self.assertEqual(len(self.stdout.strip().splitlines()), 5) self.assert_('free module with available hardware, graphics card' in self.stdout) self.assert_('kmod:mint ' in self.stdout) self.assert_('kmod:vanilla ' in self.stdout) self.assert_('kmod:vanilla3d ' in self.stdout) self.assert_('kmod:firmwifi ' in self.stdout) self.assertEqual(displayed, set(['kmod:mint', 'kmod:vanilla', 'kmod:vanilla3d', 'kmod:firmwifi', 'kmod:foodmi'])) # mint is not enabled by default self.failIf('Restricted' in ui.main_window_title()) (h, s) = ui.main_window_text() self.assert_('No proprietary drivers are in use' in h) self.assert_('cannot fix or improve' in s) # enable mint ui.backend().set_enabled('kmod:mint', True) (h, s) = ui.main_window_text() self.assert_('Proprietary drivers are being used' in h) self.assert_('cannot fix or improve' in s)
def test_check_composite_avail(self): '''calling with --check-composite and available driver''' sys.argv = ['ui-test', '--check-composite'] ui = sandbox.TestUI() class XorgComp(XorgDriverHandler): def __init__(self, ui): XorgDriverHandler.__init__(self, ui, 'vanilla3d', 'mesa-vanilla', 'v3d', 'vanilla') def enables_composite(self): return True h = XorgComp(ui.backend()) h_id = h.id() self.failIf(h.enabled()) ui.backend().handlers[h_id] = h ui.confirm_response = True self.assertEqual(ui.run(), 0) self.stop_capture() self.assert_(jockey.ui.bool( ui.backend().handler_info(h_id)['enabled']))
def test_enable(self): '''calling with --enable''' open(os.path.join(OSLib.inst.handler_dir, 'h.py'), 'w').write(sandbox.h_availability_py) # disable mint driver and verify that in --list sys.argv = ['ui-test', '--list'] ui = sandbox.TestUI() ui.backend().set_enabled('kmod:mint', False) self.assertEqual(ui.run(), 0) # enable it using the CLI sys.argv = ['ui-test', '--enable', 'kmod:mint'] ui = sandbox.TestUI() self.assertEqual(ui.run(), 0) self.stop_capture() mint_disabled = False for l in self.stdout.strip().splitlines(): if l.startswith('kmod:mint'): if ui.string_disabled in l: mint_disabled = True break self.assert_(mint_disabled) for h in ui.backend().available(): self.assert_( jockey.ui.bool(ui.backend().handler_info(h)['enabled']))
def test_enable(self): '''calling with --enable''' open (os.path.join(OSLib.inst.handler_dir, 'h.py'), 'w').write( sandbox.h_availability_py) # disable mint driver and verify that in --list sys.argv = ['ui-test', '--list'] ui = sandbox.TestUI() ui.backend().set_enabled('kmod:mint', False) self.assertEqual(ui.run(), 0) # enable it using the CLI sys.argv = ['ui-test', '--enable', 'kmod:mint'] ui = sandbox.TestUI() self.assertEqual(ui.run(), 0) self.stop_capture() mint_disabled = False for l in self.stdout.strip().splitlines(): if l.startswith('kmod:mint'): if ui.string_disabled in l: mint_disabled = True break self.assert_(mint_disabled) for h in ui.backend().available(): self.assert_(jockey.ui.bool(ui.backend().handler_info(h)['enabled']))
def test_search_driver_disabled(self): '''D-BUS API: Search for a noninstalled driver''' # search_driver() should not display available==True handlers open(os.path.join(OSLib.inst.handler_dir, 'kmod_avail.py'), 'w').write(sandbox.h_availability_py) ui = sandbox.TestUI() self.assert_('kmod:spam' not in ui.backend().available()) sandbox.start_driverdb_server() try: ui.backend().add_driverdb('XMLRPCDriverDB', ['http://localhost:8080']) # first match is kmod:mint:UbuOne in our fake db result = ui.search_driver('pci:9876/FEDC') finally: sandbox.stop_driverdb_server() self.stop_capture() self.assertEqual(result, (False, [])) self.assertEqual(ui.get_displayed_handlers(), ['kmod:spam']) info = ui.backend().handler_info('kmod:spam') self.assertEqual(info['enabled'], 'True')
def test_search_driver_enable(self): '''D-BUS API: Search for a driver which gets enabled''' ui = sandbox.TestUI() self.stop_capture() ui.backend().handlers['kmod:vanilla3d'].package = 'mesa-vanilla' # don't enable the driver result = ui.search_driver( 'modalias:pci:v00001001d00003D0sv0sd0bc03sc0i0') self.assertEqual(set(ui.get_displayed_handlers()), set(['kmod:vanilla3d', 'kmod:vanilla'])) self.assertEqual(result, (False, [])) self.assertEqual( ui.backend().handler_info('kmod:vanilla3d')['enabled'], 'False') # enable it now ui.ui_main_loop = lambda: ui.set_handler_enable( 'kmod:vanilla3d', 'enable', False, False ) # fake main loop to enable kmod:vanilla3d result = ui.search_driver( 'modalias:pci:v00001001d00003D0sv0sd0bc03sc0i0') self.assertEqual(set(ui.get_displayed_handlers()), set(['kmod:vanilla3d', 'kmod:vanilla'])) self.assertEqual( result, (True, sandbox.fake_pkginfo['default']['mesa-vanilla']['files'])) self.assertEqual( ui.backend().handler_info('kmod:vanilla3d')['enabled'], 'True')
def test_search_driver_enable(self): '''D-BUS API: Search for a driver which gets enabled''' ui = sandbox.TestUI() self.stop_capture() ui.backend().handlers['kmod:vanilla3d'].package = 'mesa-vanilla' # don't enable the driver result = ui.search_driver('modalias:pci:v00001001d00003D0sv0sd0bc03sc0i0') self.assertEqual(set(ui.get_displayed_handlers()), set(['kmod:vanilla3d', 'kmod:vanilla'])) self.assertEqual(result, (False, [])) self.assertEqual(ui.backend().handler_info('kmod:vanilla3d')['enabled'], 'False') # enable it now ui.ui_main_loop = lambda: ui.set_handler_enable('kmod:vanilla3d', 'enable', False, False) # fake main loop to enable kmod:vanilla3d result = ui.search_driver('modalias:pci:v00001001d00003D0sv0sd0bc03sc0i0') self.assertEqual(set(ui.get_displayed_handlers()), set(['kmod:vanilla3d', 'kmod:vanilla'])) self.assertEqual(result, (True, sandbox.fake_pkginfo['default']['mesa-vanilla']['files'])) self.assertEqual(ui.backend().handler_info('kmod:vanilla3d')['enabled'], 'True')
def test_update(self): '''calling with --update''' sys.argv = ['ui-test', '--update'] ui = sandbox.TestUI() ui.backend().driver_dbs.append(sandbox.TestDriverDB()) self.assertEqual(ui.run(), 0) self.stop_capture() handlers = ui.backend().available() self.assert_('kmod:vanilla3d' in handlers) # from LocalKMod self.assert_('kmod:spam' in handlers) # from TestDriverDB
def test_disable(self): '''calling with --disable''' open(os.path.join(OSLib.inst.handler_dir, 'h.py'), 'w').write(sandbox.h_availability_py) sys.argv = ['ui-test', '--disable', 'kmod:mint'] ui = sandbox.TestUI() self.assertEqual(ui.run(), 0) self.stop_capture() for h in ui.backend().available(): en = jockey.ui.bool(ui.backend().handler_info(h)['enabled']) self.assertEqual(en, h != 'kmod:mint')
def test_disable_confirm_cancel(self): '''calling with --disable --confirm cancelling''' open (os.path.join(OSLib.inst.handler_dir, 'h.py'), 'w').write( sandbox.h_availability_py) sys.argv = ['ui-test', '--confirm', '--disable', 'kmod:mint'] ui = sandbox.TestUI() ui.confirm_response = False self.assertEqual(ui.run(), 1) self.stop_capture() for h in ui.backend().available(): self.assert_(jockey.ui.bool(ui.backend().handler_info(h)['enabled']))
def test_disable(self): '''calling with --disable''' open (os.path.join(OSLib.inst.handler_dir, 'h.py'), 'w').write( sandbox.h_availability_py) sys.argv = ['ui-test', '--disable', 'kmod:mint'] ui = sandbox.TestUI() self.assertEqual(ui.run(), 0) self.stop_capture() for h in ui.backend().available(): en = jockey.ui.bool(ui.backend().handler_info(h)['enabled']) self.assertEqual(en, h != 'kmod:mint')
def test_disable_confirm_cancel(self): '''calling with --disable --confirm cancelling''' open(os.path.join(OSLib.inst.handler_dir, 'h.py'), 'w').write(sandbox.h_availability_py) sys.argv = ['ui-test', '--confirm', '--disable', 'kmod:mint'] ui = sandbox.TestUI() ui.confirm_response = False self.assertEqual(ui.run(), 1) self.stop_capture() for h in ui.backend().available(): self.assert_( jockey.ui.bool(ui.backend().handler_info(h)['enabled']))
def test_disable_nochange(self): '''calling with --disable on a non-changeable handler''' open (os.path.join(OSLib.inst.handler_dir, 'h.py'), 'w').write( 'import jockey.handlers' + sandbox.h_nochangemod) sys.argv = ['ui-test', '--disable', 'kmod:vanilla'] ui = sandbox.TestUI() self.assertNotEqual(ui.run(), 0) self.stop_capture() for h in ui.backend().available(): self.assert_(jockey.ui.bool(ui.backend().handler_info(h)['enabled'])) self.assert_('I must live' in self.stderr)
def test_disable_nochange(self): '''calling with --disable on a non-changeable handler''' open(os.path.join(OSLib.inst.handler_dir, 'h.py'), 'w').write('import jockey.handlers' + sandbox.h_nochangemod) sys.argv = ['ui-test', '--disable', 'kmod:vanilla'] ui = sandbox.TestUI() self.assertNotEqual(ui.run(), 0) self.stop_capture() for h in ui.backend().available(): self.assert_( jockey.ui.bool(ui.backend().handler_info(h)['enabled'])) self.assert_('I must live' in self.stderr)
def test_check_composite_enabled(self): '''calling with --check-composite and already enabled driver''' sys.argv = ['ui-test', '--check-composite'] ui = sandbox.TestUI() class XorgComp(XorgDriverHandler): def __init__(self, ui): XorgDriverHandler.__init__(self, ui, 'vanilla3d', 'mesa-vanilla', 'v3d', 'vanilla') def enables_composite(self): return True def enabled(self): return True h = XorgComp(ui) ui.backend().handlers[h.id()] = h # note: do not set confirm_response here, shouldn't ask self.assertEqual(ui.run(), 1) self.stop_capture() self.assert_('already supports' in self.stderr, self.stderr)
def case(confirm_response, action, confirm, expected_return, expected_enabled): ui.confirm_response = confirm_response self.assertEqual(ui.set_handler_enable('kmod:vanilla', action, confirm), expected_return) self.assertEqual(jockey.ui.bool(ui.backend().handler_info('kmod:vanilla')['enabled']), expected_enabled) self.assertRaises(IndexError, ui.pop_error)
def case(confirm_response, action, confirm, expected_return, expected_enabled): ui.confirm_response = confirm_response self.assertEqual( ui.set_handler_enable('kmod:vanilla', action, confirm), expected_return) self.assertEqual( jockey.ui.bool( ui.backend().handler_info('kmod:vanilla')['enabled']), expected_enabled) self.assertRaises(IndexError, ui.pop_error)
def test_check_composite_avail(self): '''calling with --check-composite and available driver''' sys.argv = ['ui-test', '--check-composite'] ui = sandbox.TestUI() class XorgComp(XorgDriverHandler): def __init__(self, ui): XorgDriverHandler.__init__(self, ui, 'vanilla3d', 'mesa-vanilla', 'v3d', 'vanilla') def enables_composite(self): return True h = XorgComp(ui.backend()) h_id = h.id() self.failIf(h.enabled()) ui.backend().handlers[h_id] = h ui.confirm_response = True self.assertEqual(ui.run(), 0) self.stop_capture() self.assert_(jockey.ui.bool(ui.backend().handler_info(h_id)['enabled']))
def test_search_driver_disabled(self): '''D-BUS API: Search for a noninstalled driver''' # search_driver() should not display available==True handlers open (os.path.join(OSLib.inst.handler_dir, 'kmod_avail.py'), 'w').write( sandbox.h_availability_py) ui = sandbox.TestUI() self.assert_('kmod:spam' not in ui.backend().available()) sandbox.start_driverdb_server() try: ui.backend().add_driverdb('XMLRPCDriverDB', ['http://localhost:8080']) # first match is kmod:mint:UbuOne in our fake db result = ui.search_driver('pci:9876/FEDC') finally: sandbox.stop_driverdb_server() self.stop_capture() self.assertEqual(result, (False, [])) self.assertEqual(ui.get_displayed_handlers(), ['kmod:spam']) info = ui.backend().handler_info('kmod:spam') self.assertEqual(info['enabled'], 'True')
def test_check_composite_noavail(self): '''calling with --check-composite and no available driver''' sys.argv = ['ui-test', '--check-composite'] ui = sandbox.TestUI() h = XorgDriverHandler(ui, 'vanilla3d', 'mesa-vanilla', 'v3d', 'vanilla') self.failIf(h.enabled()) ui.backend().handlers[h.id()] = h self.assertEqual(ui.run(), 1) self.stop_capture() self.assert_('no available' in self.stderr)
def test_mode_any(self): '''calling with --mode any''' sys.argv = ['ui-test', '--list', '--mode', 'any'] ui = sandbox.TestUI() self.assertEqual(sandbox.TestUI().run(), 0) displayed = set(ui.get_displayed_handlers()) self.stop_capture() self.assertEqual(len(self.stdout.strip().splitlines()), 5) self.assert_('free module with available hardware, graphics card' in self.stdout) self.assert_('kmod:mint ' in self.stdout) self.assert_('kmod:vanilla ' in self.stdout) self.assert_('kmod:vanilla3d ' in self.stdout) self.assert_('kmod:firmwifi ' in self.stdout) self.assertEqual( displayed, set([ 'kmod:mint', 'kmod:vanilla', 'kmod:vanilla3d', 'kmod:firmwifi', 'kmod:foodmi' ])) # mint is not enabled by default self.failIf('Restricted' in ui.main_window_title()) (h, s) = ui.main_window_text() self.assert_('No proprietary drivers are in use' in h) self.assert_('cannot fix or improve' in s) # enable mint ui.backend().set_enabled('kmod:mint', True) (h, s) = ui.main_window_text() self.assert_('Proprietary drivers are being used' in h) self.assert_('cannot fix or improve' in s)
def test_check_auto_install(self): '''calling with --auto-install''' open(os.path.join(OSLib.inst.handler_dir, 'h.py'), 'w').write(sandbox.h_auto_install_mod) ui = sandbox.TestUI() for h in ui.backend().available(): if ui.backend().handler_info(h)['enabled']: ui.backend().set_enabled(h, False) self.assertEqual(ui.run(), 0) self.stop_capture() sys.argv = ['ui-test', '--auto-install'] ui = sandbox.TestUI() self.assertEqual(ui.run(), 0) for h in ui.backend().available(): enabled = jockey.ui.bool(ui.backend().handler_info(h)['enabled']) if h == 'kmod:vanilla': self.assert_(enabled) else: self.assert_(not enabled, '%s shouldn\'t be enabled' % h)
def test_check_auto_install(self): '''calling with --auto-install''' open (os.path.join(OSLib.inst.handler_dir, 'h.py'), 'w').write( sandbox.h_auto_install_mod) ui = sandbox.TestUI() for h in ui.backend().available(): if ui.backend().handler_info(h)['enabled']: ui.backend().set_enabled(h, False) self.assertEqual(ui.run(), 0) self.stop_capture() sys.argv = ['ui-test', '--auto-install'] ui = sandbox.TestUI() self.assertEqual(ui.run(), 0) for h in ui.backend().available(): enabled = jockey.ui.bool(ui.backend().handler_info(h)['enabled']) if h == 'kmod:vanilla': self.assert_(enabled) else: self.assert_(not enabled, '%s shouldn\'t be enabled' % h)
def test_check(self): '''calling with --check''' try: # new free and nonfree drivers which are already enabled -> no notification sys.argv = ['ui-test', '--check'] ui = sandbox.TestUI() self.assertEqual(ui.run(), 1) self.stop_capture() self.assertRaises(IndexError, ui.pop_error) self.assertRaises(IndexError, ui.pop_notification) self.failIf(ui.main_loop_active) self.assert_(os.path.exists(OSLib.inst.check_cache)) os.unlink(OSLib.inst.check_cache) # new free and nonfree drivers which are not enabled -> nonfree notification ui = sandbox.TestUI() for h in ui.backend().available(): ui.backend().set_enabled(h, False) self.assertEqual(ui.run(), 0) self.assertRaises(IndexError, ui.pop_error) self.assertEqual('Restricted drivers available', ui.pop_notification()[0]) # the next run does not report anything new self.assertEqual(ui.run(), 1) self.assertRaises(IndexError, ui.pop_error) self.assertRaises(IndexError, ui.pop_notification) self.assert_(ui.main_loop_active) os.unlink(OSLib.inst.check_cache) # non-announced handlers do not cause notifications ui = sandbox.TestUI() for h in ui.backend().available(): ui.backend().handlers[h].announce = False self.assertEqual(ui.run(), 1) self.assertRaises(IndexError, ui.pop_error) self.assertRaises(IndexError, ui.pop_notification) self.failIf(ui.main_loop_active) os.unlink(OSLib.inst.check_cache) # new free drivers which are not enabled -> free notification sys.argv = ['ui-test', '--check', '-m', 'free'] ui = sandbox.TestUI() self.assertEqual(ui.run(), 0) self.assertRaises(IndexError, ui.pop_error) self.assertEqual('New drivers available', ui.pop_notification()[0]) self.assert_(ui.main_loop_active) # enable the free drivers again and load them -> no notification ui.main_loop_active = False for h in ui.backend().available('free'): ui.backend().set_enabled(h, True) assert jockey.ui.bool(ui.backend().handler_info(h)['used']) self.assertEqual(ui.run(), 1) self.assertRaises(IndexError, ui.pop_error) self.assertRaises(IndexError, ui.pop_notification) self.failIf(ui.main_loop_active) # enable the non-free drivers again, too and load them -> # notification about usage sys.argv = ['ui-test', '--check', '-m', 'nonfree'] ui = sandbox.TestUI() for h in ui.backend().available('nonfree'): ui.backend().set_enabled(h, True) self.assert_(jockey.ui.bool(ui.backend().handler_info(h)['used'])) self.assertEqual(ui.run(), 1) self.assertRaises(IndexError, ui.pop_error) self.assertEqual('New restricted drivers in use', ui.pop_notification()[0]) self.assert_(ui.main_loop_active) # the next run does not report anything new ui.main_loop_active = False self.assertEqual(ui.run(), 1) self.assertRaises(IndexError, ui.pop_error) self.assertRaises(IndexError, ui.pop_notification) self.failIf(ui.main_loop_active) finally: try: os.unlink(OSLib.inst.check_cache) except OSError: pass
def test_set_handler_enable_error(self): '''set_handler_enable() on errors''' open (os.path.join(OSLib.inst.handler_dir, 'h.py'), 'w').write( 'import jockey.handlers' + sandbox.h_nochangemod) sys.argv = ['ui-test'] ui = sandbox.TestUI() self.stop_capture() for h_id in ui.backend().available(): self.assert_(jockey.ui.bool(ui.backend().handler_info(h_id)['enabled'])) if 'can_change' in ui.backend().handler_info(h_id): no_change_h = h_id else: change_h = h_id assert no_change_h assert change_h # change an unchangeable handler # note: don't set a confirmation response, it shouldn't ask here self.assertEqual(ui.set_handler_enable(no_change_h, 'enable', True), False) self.assertEqual(ui.pop_error()[1], 'I must live') self.assertRaises(IndexError, ui.pop_error) self.assertEqual(ui.set_handler_enable(no_change_h, 'disable', True), False) self.assertEqual(ui.pop_error()[1], 'I must live') self.assertRaises(IndexError, ui.pop_error) self.assertEqual(ui.set_handler_enable(no_change_h, 'toggle', True), False) self.assertEqual(ui.pop_error()[1], 'I must live') self.assertRaises(IndexError, ui.pop_error) # invalid operation self.assertRaises(ValueError, ui.set_handler_enable, no_change_h, 'foo', True) # package install failure ui.backend().handlers['kmod:mint'].package = 'pretzel' self.assertEqual(jockey.ui.bool(ui.backend().handler_info('kmod:mint')['enabled']), False) OSLib.inst.pending_install_remove_exception = 'OMGbroken' self.assertEqual(ui.set_handler_enable('kmod:mint', 'enable', False), False) self.assertEqual(jockey.ui.bool(ui.backend().handler_info('kmod:mint')['enabled']), False) # one error message about install failure (etitle, etext) = ui.pop_error() self.assert_('OMGbroken' in etext, '%s: %s' % (etitle, etext)) self.assertRaises(IndexError, ui.pop_error) # install it now self.assertEqual(ui.set_handler_enable('kmod:mint', 'enable', False), True) self.assertEqual(jockey.ui.bool(ui.backend().handler_info('kmod:mint')['enabled']), True) # package removal failure OSLib.inst.pending_install_remove_exception = 'OMGZombie' self.assertEqual(ui.set_handler_enable('kmod:mint', 'disable', False), False) self.assertEqual(jockey.ui.bool(ui.backend().handler_info('kmod:mint')['enabled']), True) # one error message about removal failure (etitle, etext) = ui.pop_error() self.assert_('OMGZombie' in etext, '%s: %s' % (etitle, etext)) self.assertRaises(IndexError, ui.pop_error)
def test_check(self): '''calling with --check''' try: # new free and nonfree drivers which are already enabled -> no notification sys.argv = ['ui-test', '--check'] ui = sandbox.TestUI() self.assertEqual(ui.run(), 1) self.stop_capture() self.assertRaises(IndexError, ui.pop_error) self.assertRaises(IndexError, ui.pop_notification) self.failIf(ui.main_loop_active) self.assert_(os.path.exists(OSLib.inst.check_cache)) os.unlink(OSLib.inst.check_cache) # new free and nonfree drivers which are not enabled -> nonfree notification ui = sandbox.TestUI() for h in ui.backend().available(): ui.backend().set_enabled(h, False) self.assertEqual(ui.run(), 0) self.assertRaises(IndexError, ui.pop_error) self.assertEqual('Restricted drivers available', ui.pop_notification()[0]) # the next run does not report anything new self.assertEqual(ui.run(), 1) self.assertRaises(IndexError, ui.pop_error) self.assertRaises(IndexError, ui.pop_notification) self.assert_(ui.main_loop_active) os.unlink(OSLib.inst.check_cache) # non-announced handlers do not cause notifications ui = sandbox.TestUI() for h in ui.backend().available(): ui.backend().handlers[h].announce = False self.assertEqual(ui.run(), 1) self.assertRaises(IndexError, ui.pop_error) self.assertRaises(IndexError, ui.pop_notification) self.failIf(ui.main_loop_active) os.unlink(OSLib.inst.check_cache) # new free drivers which are not enabled -> free notification sys.argv = ['ui-test', '--check', '-m', 'free'] ui = sandbox.TestUI() self.assertEqual(ui.run(), 0) self.assertRaises(IndexError, ui.pop_error) self.assertEqual('New drivers available', ui.pop_notification()[0]) self.assert_(ui.main_loop_active) # enable the free drivers again and load them -> no notification ui.main_loop_active = False for h in ui.backend().available('free'): ui.backend().set_enabled(h, True) assert jockey.ui.bool(ui.backend().handler_info(h)['used']) self.assertEqual(ui.run(), 1) self.assertRaises(IndexError, ui.pop_error) self.assertRaises(IndexError, ui.pop_notification) self.failIf(ui.main_loop_active) # enable the non-free drivers again, too and load them -> # notification about usage sys.argv = ['ui-test', '--check', '-m', 'nonfree'] ui = sandbox.TestUI() for h in ui.backend().available('nonfree'): ui.backend().set_enabled(h, True) self.assert_( jockey.ui.bool(ui.backend().handler_info(h)['used'])) self.assertEqual(ui.run(), 1) self.assertRaises(IndexError, ui.pop_error) self.assertEqual('New restricted drivers in use', ui.pop_notification()[0]) self.assert_(ui.main_loop_active) # the next run does not report anything new ui.main_loop_active = False self.assertEqual(ui.run(), 1) self.assertRaises(IndexError, ui.pop_error) self.assertRaises(IndexError, ui.pop_notification) self.failIf(ui.main_loop_active) finally: try: os.unlink(OSLib.inst.check_cache) except OSError: pass
def test_set_handler_enable_error(self): '''set_handler_enable() on errors''' open(os.path.join(OSLib.inst.handler_dir, 'h.py'), 'w').write('import jockey.handlers' + sandbox.h_nochangemod) sys.argv = ['ui-test'] ui = sandbox.TestUI() self.stop_capture() for h_id in ui.backend().available(): self.assert_( jockey.ui.bool(ui.backend().handler_info(h_id)['enabled'])) if 'can_change' in ui.backend().handler_info(h_id): no_change_h = h_id else: change_h = h_id assert no_change_h assert change_h # change an unchangeable handler # note: don't set a confirmation response, it shouldn't ask here self.assertEqual(ui.set_handler_enable(no_change_h, 'enable', True), False) self.assertEqual(ui.pop_error()[1], 'I must live') self.assertRaises(IndexError, ui.pop_error) self.assertEqual(ui.set_handler_enable(no_change_h, 'disable', True), False) self.assertEqual(ui.pop_error()[1], 'I must live') self.assertRaises(IndexError, ui.pop_error) self.assertEqual(ui.set_handler_enable(no_change_h, 'toggle', True), False) self.assertEqual(ui.pop_error()[1], 'I must live') self.assertRaises(IndexError, ui.pop_error) # invalid operation self.assertRaises(ValueError, ui.set_handler_enable, no_change_h, 'foo', True) # package install failure ui.backend().handlers['kmod:mint'].package = 'pretzel' self.assertEqual( jockey.ui.bool(ui.backend().handler_info('kmod:mint')['enabled']), False) OSLib.inst.pending_install_remove_exception = 'OMGbroken' self.assertEqual(ui.set_handler_enable('kmod:mint', 'enable', False), False) self.assertEqual( jockey.ui.bool(ui.backend().handler_info('kmod:mint')['enabled']), False) # one error message about install failure (etitle, etext) = ui.pop_error() self.assert_('OMGbroken' in etext, '%s: %s' % (etitle, etext)) self.assertRaises(IndexError, ui.pop_error) # install it now self.assertEqual(ui.set_handler_enable('kmod:mint', 'enable', False), True) self.assertEqual( jockey.ui.bool(ui.backend().handler_info('kmod:mint')['enabled']), True) # package removal failure OSLib.inst.pending_install_remove_exception = 'OMGZombie' self.assertEqual(ui.set_handler_enable('kmod:mint', 'disable', False), False) self.assertEqual( jockey.ui.bool(ui.backend().handler_info('kmod:mint')['enabled']), True) # one error message about removal failure (etitle, etext) = ui.pop_error() self.assert_('OMGZombie' in etext, '%s: %s' % (etitle, etext)) self.assertRaises(IndexError, ui.pop_error)