How to use is_enabled method in lisa

Best Python code snippet using lisa_python

feature_test.py

Source:feature_test.py Github

copy

Full Screen

...51 return MockState('test_state', world)52 def test_enabled(self):53 cfg = {'enabled': 'on'}54 feature_state = self._make_state(cfg)55 self.assertTrue(feature_state.is_enabled())56 self.assertTrue(feature_state.is_enabled(user=gary))57 def test_disabled(self):58 cfg = {'enabled': 'off'}59 feature_state = self._make_state(cfg)60 self.assertFalse(feature_state.is_enabled())61 self.assertFalse(feature_state.is_enabled(user=gary))62 def test_admin_enabled(self):63 cfg = {'admin': True}64 mock_world = self.world()65 mock_world.is_admin = mock.Mock(return_value=True)66 feature_state = self._make_state(cfg, mock_world)67 self.assertTrue(feature_state.is_enabled(user=gary))68 def test_admin_disabled(self):69 cfg = {'admin': True}70 mock_world = self.world()71 mock_world.is_admin = mock.Mock(return_value=False)72 feature_state = self._make_state(cfg, mock_world)73 self.assertFalse(feature_state.is_enabled(user=gary))74 def test_employee_enabled(self):75 cfg = {'employee': True}76 mock_world = self.world()77 mock_world.is_employee = mock.Mock(return_value=True)78 feature_state = self._make_state(cfg, mock_world)79 self.assertTrue(feature_state.is_enabled(user=gary))80 def test_employee_disabled(self):81 cfg = {'employee': True}82 mock_world = self.world()83 mock_world.is_employee = mock.Mock(return_value=False)84 feature_state = self._make_state(cfg, mock_world)85 self.assertFalse(feature_state.is_enabled(user=gary))86 def test_beta_enabled(self):87 cfg = {'beta': True}88 mock_world = self.world()89 mock_world.user_has_beta_enabled = mock.Mock(return_value=True)90 feature_state = self._make_state(cfg, mock_world)91 self.assertTrue(feature_state.is_enabled(user=gary))92 def test_beta_disabled(self):93 cfg = {'beta': True}94 mock_world = self.world()95 mock_world.user_has_beta_enabled = mock.Mock(return_value=False)96 feature_state = self._make_state(cfg, mock_world)97 self.assertFalse(feature_state.is_enabled(user=gary))98 def test_gold_enabled(self):99 cfg = {'gold': True}100 mock_world = self.world()101 mock_world.has_gold = mock.Mock(return_value=True)102 feature_state = self._make_state(cfg, mock_world)103 self.assertTrue(feature_state.is_enabled(user=gary))104 def test_gold_disabled(self):105 cfg = {'gold': True}106 mock_world = self.world()107 mock_world.has_gold = mock.Mock(return_value=False)108 feature_state = self._make_state(cfg, mock_world)109 self.assertFalse(feature_state.is_enabled(user=gary))110 def test_loggedin_enabled(self):111 cfg = {'loggedin': True}112 mock_world = self.world()113 mock_world.is_user_loggedin = mock.Mock(return_value=True)114 feature_state = self._make_state(cfg, mock_world)115 self.assertTrue(feature_state.is_enabled(user=gary))116 def test_loggedin_disabled(self):117 cfg = {'loggedin': False}118 mock_world = self.world()119 mock_world.is_user_loggedin = mock.Mock(return_value=True)120 feature_state = self._make_state(cfg, mock_world)121 self.assertFalse(feature_state.is_enabled(user=gary))122 def test_loggedout_enabled(self):123 cfg = {'loggedout': True}124 mock_world = self.world()125 mock_world.is_user_loggedin = mock.Mock(return_value=False)126 feature_state = self._make_state(cfg, mock_world)127 self.assertTrue(feature_state.is_enabled(user=gary))128 def test_loggedout_disabled(self):129 cfg = {'loggedout': False}130 mock_world = self.world()131 mock_world.is_user_loggedin = mock.Mock(return_value=False)132 feature_state = self._make_state(cfg, mock_world)133 self.assertFalse(feature_state.is_enabled(user=gary))134 def test_percent_loggedin(self):135 num_users = 2000136 users = []137 for i in xrange(num_users):138 users.append(MockAccount(name=str(i), _fullname="t2_%s" % str(i)))139 def simulate_percent_loggedin(wanted_percent):140 cfg = {'percent_loggedin': wanted_percent}141 mock_world = self.world()142 mock_world.is_user_loggedin = mock.Mock(return_value=True)143 feature_state = self._make_state(cfg, mock_world)144 return (feature_state.is_enabled(x) for x in users)145 def assert_fuzzy_percent_true(results, percent):146 stats = collections.Counter(results)147 # _roughly_ `percent` should have been `True`148 diff = abs((float(stats[True]) / num_users) - (percent / 100.0))149 self.assertTrue(diff < 0.1)150 self.assertFalse(any(simulate_percent_loggedin(0)))151 self.assertTrue(all(simulate_percent_loggedin(100)))152 assert_fuzzy_percent_true(simulate_percent_loggedin(25), 25)153 assert_fuzzy_percent_true(simulate_percent_loggedin(10), 10)154 assert_fuzzy_percent_true(simulate_percent_loggedin(50), 50)155 assert_fuzzy_percent_true(simulate_percent_loggedin(99), 99)156 def test_url_enabled(self):157 mock_world = self.world()158 cfg = {'url': 'test_state'}159 mock_world.url_features = mock.Mock(return_value={'test_state'})160 feature_state = self._make_state(cfg, mock_world)161 self.assertTrue(feature_state.is_enabled())162 self.assertTrue(feature_state.is_enabled(user=gary))163 cfg = {'url': 'test_state'}164 mock_world.url_features = mock.Mock(return_value={'x', 'test_state'})165 feature_state = self._make_state(cfg, mock_world)166 self.assertTrue(feature_state.is_enabled())167 self.assertTrue(feature_state.is_enabled(user=gary))168 def test_url_disabled(self):169 mock_world = self.world()170 cfg = {'url': 'test_state'}171 mock_world.url_features = mock.Mock(return_value={})172 feature_state = self._make_state(cfg, mock_world)173 self.assertFalse(feature_state.is_enabled())174 self.assertFalse(feature_state.is_enabled(user=gary))175 cfg = {'url': 'test_state'}176 mock_world.url_features = mock.Mock(return_value={'x'})177 feature_state = self._make_state(cfg, mock_world)178 self.assertFalse(feature_state.is_enabled())179 self.assertFalse(feature_state.is_enabled(user=gary))180 def test_user_in(self):181 cfg = {'users': ['Gary']}182 feature_state = self._make_state(cfg)183 self.assertTrue(feature_state.is_enabled(user=gary))184 cfg = {'users': ['ALL_UPPERCASE']}185 feature_state = self._make_state(cfg)186 self.assertTrue(feature_state.is_enabled(user=all_uppercase))187 cfg = {'users': ['dave', 'gary']}188 feature_state = self._make_state(cfg)189 self.assertTrue(feature_state.is_enabled(user=gary))190 def test_user_not_in(self):191 cfg = {'users': ['']}192 featurestate = self._make_state(cfg)193 self.assertFalse(featurestate.is_enabled(user=gary))194 cfg = {'users': ['dave', 'joe']}195 featurestate = self._make_state(cfg)196 self.assertFalse(featurestate.is_enabled(user=gary))197 def test_subreddit_in(self):198 cfg = {'subreddits': ['WTF']}199 feature_state = self._make_state(cfg)200 self.assertTrue(feature_state.is_enabled(subreddit='wtf'))201 cfg = {'subreddits': ['wtf']}202 feature_state = self._make_state(cfg)203 self.assertTrue(feature_state.is_enabled(subreddit='WTF'))204 cfg = {'subreddits': ['aww', 'wtf']}205 feature_state = self._make_state(cfg)206 self.assertTrue(feature_state.is_enabled(subreddit='wtf'))207 def test_subreddit_not_in(self):208 cfg = {'subreddits': []}209 feature_state = self._make_state(cfg)210 self.assertFalse(feature_state.is_enabled(subreddit='wtf'))211 cfg = {'subreddits': ['aww', 'wtfoobar']}212 feature_state = self._make_state(cfg)213 self.assertFalse(feature_state.is_enabled(subreddit='wtf'))214 def test_subdomain_in(self):215 cfg = {'subdomains': ['BETA']}216 feature_state = self._make_state(cfg)217 self.assertTrue(feature_state.is_enabled(subdomain='beta'))218 cfg = {'subdomains': ['beta']}219 feature_state = self._make_state(cfg)220 self.assertTrue(feature_state.is_enabled(subdomain='BETA'))221 cfg = {'subdomains': ['www', 'beta']}222 feature_state = self._make_state(cfg)223 self.assertTrue(feature_state.is_enabled(subdomain='beta'))224 def test_subdomain_not_in(self):225 cfg = {'subdomains': []}226 feature_state = self._make_state(cfg)227 self.assertFalse(feature_state.is_enabled(subdomain='beta'))228 self.assertFalse(feature_state.is_enabled(subdomain=''))229 cfg = {'subdomains': ['www', 'betanauts']}230 feature_state = self._make_state(cfg)231 self.assertFalse(feature_state.is_enabled(subdomain='beta'))232 def test_multiple(self):233 # is_admin, globally off should still be False234 cfg = {'enabled': 'off', 'admin': True}235 mock_world = self.world()236 mock_world.is_admin = mock.Mock(return_value=True)237 featurestate = self._make_state(cfg, mock_world)238 self.assertFalse(featurestate.is_enabled(user=gary))239 # globally on but not admin should still be True240 cfg = {'enabled': 'on', 'admin': True}241 mock_world = self.world()242 mock_world.is_admin = mock.Mock(return_value=False)243 featurestate = self._make_state(cfg, mock_world)244 self.assertTrue(featurestate.is_enabled(user=gary))245 self.assertTrue(featurestate.is_enabled())246 # no URL but admin should still be True247 cfg = {'url': 'test_featurestate', 'admin': True}248 mock_world = self.world()249 mock_world.url_features = mock.Mock(return_value={})250 mock_world.is_admin = mock.Mock(return_value=True)251 featurestate = self._make_state(cfg, mock_world)...

Full Screen

Full Screen

dialogs.py

Source:dialogs.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""3 Copyright (C) 2017 Sebastian Golasch (plugin.video.netflix)4 Copyright (C) 2018 Caphm (original implementation module)5 Various simple dialogs6 SPDX-License-Identifier: MIT7 See LICENSES/MIT.md for more information.8"""9import xbmc10import xbmcgui11from resources.lib.globals import G12import resources.lib.common as common13def show_notification(msg, title='Netflix', time=3000):14 """Show a notification"""15 xbmc.executebuiltin(f'Notification({title}, {msg}, {time}, {G.ICON})')16def ask_credentials():17 """18 Show some dialogs and ask the user for account credentials19 """20 email = xbmcgui.Dialog().input(21 heading=common.get_local_string(30005),22 type=xbmcgui.INPUT_ALPHANUM) or None23 common.verify_credentials(email)24 password = ask_for_password()25 common.verify_credentials(password)26 return {27 'email': email.strip(),28 'password': password.strip()29 }30def ask_for_password():31 """Ask the user for the password"""32 return xbmcgui.Dialog().input(33 heading=common.get_local_string(30004),34 type=xbmcgui.INPUT_ALPHANUM,35 option=xbmcgui.ALPHANUM_HIDE_INPUT) or None36def ask_for_rating():37 """Ask the user for a rating"""38 heading = f'{common.get_local_string(30019)} {common.get_local_string(30022)}'39 try:40 return int(xbmcgui.Dialog().numeric(heading=heading, type=0,41 defaultt=''))42 except ValueError:43 return None44def show_dlg_input_numeric(message, mask_input=True):45 """Ask the user to enter numbers"""46 args = {'heading': message,47 'type': 0,48 'defaultt': '',49 'bHiddenInput': mask_input}50 return xbmcgui.Dialog().numeric(**args) or None51def ask_for_search_term(default_text=None):52 """Ask the user for a search term"""53 return ask_for_input(common.get_local_string(30402), default_text)54def ask_for_input(heading, default_text=None):55 return xbmcgui.Dialog().input(56 defaultt=default_text,57 heading=heading,58 type=xbmcgui.INPUT_ALPHANUM) or None59def ask_for_confirmation(title, message):60 """Ask the user to confirm an operation"""61 return xbmcgui.Dialog().yesno(title, message)62def ask_for_resume(resume_position):63 """Ask the user for resuming a video"""64 return xbmcgui.Dialog().contextmenu(65 [66 common.get_local_string(12022).format(common.convert_seconds_to_hms_str(resume_position)),67 common.get_local_string(12021)68 ])69def show_backend_not_ready(error_details=None):70 message = common.get_local_string(30138)71 if error_details:72 message += f'[CR][CR]Error details:[CR]{error_details}'73 return xbmcgui.Dialog().ok(common.get_local_string(30105), message)74def show_ok_dialog(title, message):75 return xbmcgui.Dialog().ok(title, message)76def show_yesno_dialog(title, message, yeslabel=None, nolabel=None, default_yes_button=False):77 if G.KODI_VERSION < '20':78 return xbmcgui.Dialog().yesno(title, message, yeslabel=yeslabel, nolabel=nolabel)79 # pylint: disable=no-member,unexpected-keyword-arg80 default_button = xbmcgui.DLG_YESNO_YES_BTN if default_yes_button else xbmcgui.DLG_YESNO_NO_BTN81 return xbmcgui.Dialog().yesno(title, message,82 yeslabel=yeslabel, nolabel=nolabel, defaultbutton=default_button)83def show_error_info(title, message, unknown_error=False, netflix_error=False):84 """Show a dialog that displays the error message"""85 prefix = (30104, 30102, 30101)[unknown_error + netflix_error]86 return xbmcgui.Dialog().ok(title, (common.get_local_string(prefix) + '[CR]' +87 message + '[CR][CR]' +88 common.get_local_string(30103)))89def show_addon_error_info(exc):90 """Show a dialog to notify of an addon internal error"""91 show_error_info(title=common.get_local_string(30105),92 message=': '.join((exc.__class__.__name__, str(exc))),93 netflix_error=False)94def show_library_task_errors(notify_errors, errors):95 if notify_errors and errors:96 xbmcgui.Dialog().ok(common.get_local_string(0),97 '[CR]'.join([f'{err["title"]} ({err["error"]})'98 for err in errors]))99def show_browse_dialog(title, browse_type=0, default_path=None, multi_selection=False, extensions=None):100 """101 Show a browse dialog to select files or folders102 :param title: The window title103 :param browse_type: Type of dialog as int value (0 = ShowAndGetDirectory, 1 = ShowAndGetFile, ..see doc)104 :param default_path: The initial path105 :param multi_selection: Allow multi selection106 :param extensions: extensions allowed e.g. '.jpg|.png'107 :return: The selected path as string (or tuple of selected items) if user pressed 'Ok', else None108 """109 ret = xbmcgui.Dialog().browse(browse_type, title, shares='', useThumbs=False, treatAsFolder=False,110 defaultt=default_path, enableMultiple=multi_selection, mask=extensions)111 # Note: when defaultt is set and the user cancel the action (when enableMultiple is False),112 # will be returned the defaultt value again, so we avoid this strange behavior...113 return None if not ret or ret == default_path else ret114def show_dlg_select(title, item_list):115 """116 Show a select dialog for a list of objects117 :return index of selected item, or -1 when cancelled118 """119 return xbmcgui.Dialog().select(title, item_list)120class ProgressDialog(xbmcgui.DialogProgress):121 """Context manager to handle a progress dialog window"""122 # Keep the same arguments for all progress bar classes123 def __init__(self, is_enabled, title=None, initial_value=0, max_value=1):124 super().__init__()125 self.is_enabled = is_enabled126 self.max_value = max_value127 self.value = initial_value128 self._percent = int(initial_value * 100 / max_value) if max_value else 0129 if is_enabled:130 self.create(title or common.get_local_string(30047))131 def __enter__(self):132 if self.is_enabled:133 self.update(self._percent, common.get_local_string(261)) # "Waiting for start..."134 return self135 def set_message(self, message):136 if self.is_enabled:137 self.update(self._percent, message)138 def set_wait_message(self):139 if self.is_enabled:140 self.update(self._percent, common.get_local_string(20186)) # "Please wait"141 def is_cancelled(self):142 """Return True when the user has pressed cancel button"""143 return self.is_enabled and self.iscanceled()144 def perform_step(self):145 self.value += 1146 self._percent = int(self.value * 100 / self.max_value)147 def __exit__(self, exc_type, exc_value, exc_traceback):148 if self.is_enabled:149 self.close()150class ProgressBarBG(xbmcgui.DialogProgressBG):151 """Context manager to handle a progress bar in background"""152 # Keep the same arguments for all progress bar classes153 def __init__(self, is_enabled, title, initial_value=None, max_value=None):154 super().__init__()155 self.is_enabled = is_enabled156 self.max_value = max_value157 self.value = 0 if max_value and initial_value is None else initial_value158 self._percent = int(initial_value * 100 / max_value) if initial_value and max_value else None159 if is_enabled:160 self.create(title)161 def __enter__(self):162 if self.is_enabled:163 self._update(common.get_local_string(261)) # "Waiting for start..."164 return self165 def set_message(self, message):166 if self.is_enabled:167 self._update(message)168 def set_wait_message(self):169 if self.is_enabled:170 self._update(common.get_local_string(20186)) # "Please wait"171 def perform_step(self):172 self.value += 1173 self._percent = int(self.value * 100 / self.max_value)174 def _update(self, message):175 kwargs = {'message': message}176 if self._percent is not None:177 kwargs['percent'] = self._percent178 self.update(**kwargs) # Here all the arguments are optionals179 def is_cancelled(self):180 # Not supported - only need to ensure consistency in dynamic class management181 return False182 def __exit__(self, exc_type, exc_value, exc_traceback):183 if self.is_enabled:...

Full Screen

Full Screen

MemoryPool.py

Source:MemoryPool.py Github

copy

Full Screen

...49 self.default_reserved_memory = 0 50 self.enable_memory_pool = 0 51 self.dom0_ballooning = 0 52 def available_memory_check(self, need_mem):53 return self.is_enabled() and self.reserved_memory > need_mem54 def decrease_memory(self, value):55 if not self.is_enabled() or value <= 4096: #4M for PV guest kernel and ramdisk unzip56 return 57 elif self.reserve_memory < value: 58 raise VMError(('I need %d KiB, but only have %d KiB in Memory Pool') %(value,self.reserve_memory))59 else:60 self.reserve_memory -= value61 log.debug("MemoryPool: decrease_memory: decrease: %d reserved_memory %d KiB" %(value,self.reserve_memory))62 return63 def decrease_untouched_memory(self, value):64 if not self.is_enabled():65 return 66 elif self.untouched_memory < value: 67 raise VmError(('I need %d KiB untouch mem, but only have %d KiB untouched mem in Memory Pool') %(value,self.reserve_memory))68 else:69 self.untouched_memory -= value70 log.debug("MemoryPool: decrease_untouched_memory: untouched_memory %d KiB" %self.untouched_memory)71 return72 def increase_memory(self, value):73 if not self.is_enabled():74 return 75 else:76 self.reserve_memory += value77 if self.reserve_memory > self.default_reserved_memory:78 raise VmError(('the maxsize of memory pool is %d KiB, but current is %d KiB') %(value,self.reserve_memory))79 log.debug("MemoryPool: increase_memory:%d, reserved_memory %d KiB" %(value,self.reserve_memory))80 return81 def is_enabled(self):82 return self.enable_memory_pool and self.dom0_ballooning83 84 def get_pool_size(self): 85 if self.is_enabled():86 return self.default_reserved_memory87 else:88 return 089 def get_left_memory(self):90 if self.is_enabled():91 return self.reserve_memory92 else:93 return 094 def get_untouched_memory(self):95 if self.is_enabled():96 return self.untouched_memory97 else:98 return 099def instance():100 """Singleton constructor. Use this instead of the class constructor.101 """102 global MP_inst103 try:104 MP_inst105 except:106 MP_inst = MemoryPool()107 MP_inst.init()...

Full Screen

Full Screen

MixerComponent.py

Source:MixerComponent.py Github

copy

Full Screen

...7from _Framework.Util import nop8from _APC.MixerComponent import MixerComponent as MixerComponentBase, ChanStripComponent as ChannelStripComponentBase9class ChannelStripComponent(ChannelStripComponentBase):10 def _on_cf_assign_changed(self):11 if self.is_enabled() and self._crossfade_toggle:12 state = self._track.mixer_device.crossfade_assign if self._track else 113 value_to_send = None14 if state == 0:15 value_to_send = 'Mixer.Crossfade.A'16 else:17 if state == 1:18 value_to_send = 'Mixer.Crossfade.Off'19 else:20 if state == 2:21 value_to_send = 'Mixer.Crossfade.B'22 self._crossfade_toggle.set_light(value_to_send)23 return24def _set_channel(controls, channel):25 for control in ifilter(None, controls or []):26 control.set_channel(channel)27 return28class MixerComponent(MixerComponentBase):29 send_select_buttons = control_list(RadioButtonControl)30 @depends(show_message=nop)31 def __init__(self, num_tracks=0, show_message=nop, *a, **k):32 super(MixerComponent, self).__init__(num_tracks=num_tracks, *a, **k)33 self._show_message = show_message34 self.on_num_sends_changed()35 self._pan_controls = None36 self._send_controls = None37 self._user_controls = None38 return39 def _create_strip(self):40 return ChannelStripComponent()41 @send_select_buttons.checked42 def send_select_buttons(self, button):43 self.send_index = button.index44 def on_num_sends_changed(self):45 self.send_select_buttons.control_count = self.num_sends46 def on_send_index_changed(self):47 if self.send_index is None:48 self.send_select_buttons.control_count = 049 else:50 if self.send_index < self.send_select_buttons.control_count:51 self.send_select_buttons[self.send_index].is_checked = True52 if self.is_enabled() and self._send_controls:53 self._show_controlled_sends_message()54 return55 def _show_controlled_sends_message(self):56 if self._send_index is not None:57 send_name = chr(ord('A') + self._send_index)58 self._show_message('Controlling Send %s' % send_name)59 return60 def set_pan_controls(self, controls):61 super(MixerComponent, self).set_pan_controls(controls)62 self._pan_controls = controls63 self._update_pan_controls()64 if self.is_enabled() and controls:65 self._show_message('Controlling Pans')66 def set_send_controls(self, controls):67 super(MixerComponent, self).set_send_controls(controls)68 self._send_controls = controls69 self._update_send_controls()70 if self.is_enabled() and controls:71 self._show_controlled_sends_message()72 def set_user_controls(self, controls):73 self._user_controls = controls74 self._update_user_controls()75 if self.is_enabled() and controls:76 self._show_message('Controlling User Mappings')77 def set_crossfade_buttons(self, buttons):78 for strip, button in izip_longest(self._channel_strips, buttons or []):79 strip.set_crossfade_toggle(button)80 def _update_pan_controls(self):81 _set_channel(self._pan_controls, 0)82 def _update_send_controls(self):83 _set_channel(self._send_controls, 1)84 def _update_user_controls(self):85 _set_channel(self._user_controls, 2)86 def update(self):87 super(MixerComponent, self).update()88 if self.is_enabled():89 self._update_pan_controls()90 self._update_send_controls()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful