def test_get_edid_name_cache(self, monkeypatch): """ Tests that the get_edid_name function returns the correct cached values. It explicitly sets the cache for the function and mocks the "live" model such that if the cache isn't respected, it would return the "live" model. Args: monkeypatch - pytest fixture which gives mocking functionality edid - parameterised fixture containing raw, rpi_dumps, expected test data """ cached_screen_name = 'CHACHE-SCR' live_screen_name = 'LIVE-SCR' # Mock the run_cmd function such that it returns the cached screen name and # call the function to explicitly set the cache. monkeypatch.setattr(display, 'run_cmd', lambda x: (cached_screen_name, '', 0)) display.get_edid_name(use_cached=False) # Mock the run_cmd function such that it returns the "live" screen name and # get the cached and live values from the function. monkeypatch.setattr(display, 'run_cmd', lambda x: (live_screen_name, '', 0)) rv_cache = display.get_edid_name(use_cached=True) rv_no_cache = display.get_edid_name(use_cached=False) assert (rv_cache == cached_screen_name and rv_no_cache == live_screen_name)
def test_get_edid_name_cache(self, monkeypatch): """ Tests that the get_edid_name function returns the correct cached values. It explicitly sets the cache for the function and mocks the "live" model such that if the cache isn't respected, it would return the "live" model. Args: monkeypatch - pytest fixture which gives mocking functionality edid - parameterised fixture containing raw, rpi_dumps, expected test data """ from kano_settings.system import display cached_screen_name = 'CHACHE-SCR' live_screen_name = 'LIVE-SCR' # Mock the run_cmd function such that it returns the cached screen name and # call the function to explicitly set the cache. monkeypatch.setattr( display, 'run_cmd', lambda x: (cached_screen_name, '', 0) ) display.get_edid_name(use_cached=False) # Mock the run_cmd function such that it returns the "live" screen name and # get the cached and live values from the function. monkeypatch.setattr( display, 'run_cmd', lambda x: (live_screen_name, '', 0) ) rv_cache = display.get_edid_name(use_cached=True) rv_no_cache = display.get_edid_name(use_cached=False) assert(rv_cache == cached_screen_name and rv_no_cache == live_screen_name)
def test_get_cached_edid(self): with patched_run_cmd(self.VALID_DISPLAY_NAME): edid = display.get_edid_name(use_cached=True) self.assertEqual(edid, self.VALID_EDID_VAL) edid = display.get_edid_name(use_cached=True) self.assertEqual(edid, self.VALID_EDID_VAL)
def get_screen_log(): """Get display information using kano-settings display functions. Returns: dict: An aggregate of display characteristics """ try: from kano_settings.system.display import get_edid, get_edid_name, get_status, \ list_supported_modes, get_optimal_resolution_mode, override_models edid = get_edid() model = get_edid_name(use_cached=False) override_models(edid, model) status = get_status() supported = list_supported_modes(use_cached=False) optimal = get_optimal_resolution_mode(edid, supported) log_data = { 'model': model, 'status': status, 'edid': edid, 'supported': supported, 'optimal': optimal, } log = json.dumps(log_data, sort_keys=True, indent=4) except: return traceback.format_exc() return log
def test_get_edid_name(self, monkeypatch, edid): """ Tests that the get_edid_name function returns the correct display model. Args: monkeypatch - pytest fixture which gives mocking functionality edid - parameterised fixture containing raw, rpi_dumps, expected test data """ try: from kano_settings.system import display except RuntimeError as err: pytest.skip( 'FIXME: RuntimeError: `kano_settings.system.display import ' \ 'fails randomly when Pytest decides to fiddle around with ' \ 'threads.\n{}'.format(err) ) # Mock the run_cmd function such that it returns the dump for the device name. monkeypatch.setattr( display, 'run_cmd', lambda x: (edid['rpi_dumps']['device_name'], '', 0) ) rv = display.get_edid_name(use_cached=False) assert(rv == edid['expected']['model'])
def test_get_edid_name(self, monkeypatch, edid): """ Tests that the get_edid_name function returns the correct display model. Args: monkeypatch - pytest fixture which gives mocking functionality edid - parameterised fixture containing raw, rpi_dumps, expected test data """ try: from kano_settings.system import display except RuntimeError as err: pytest.skip( 'FIXME: RuntimeError: `kano_settings.system.display import ' \ 'fails randomly when Pytest decides to fiddle around with ' \ 'threads.\n{}'.format(err) ) # Mock the run_cmd function such that it returns the dump for the device name. monkeypatch.setattr( display, 'run_cmd', lambda x: (edid['rpi_dumps']['device_name'], '', 0)) rv = display.get_edid_name(use_cached=False) assert (rv == edid['expected']['model'])
def set_hdmi_mode_from_str(self, mode): if mode == 'auto': if get_edid_name(): set_hdmi_mode() else: set_unflashed_sk_resolution() return group, number = mode.split(":") set_hdmi_mode(group, number)
def get_screen_version(): '''Retrieves the kit type and version from the EDID data Returns: (int, distutils.version.LooseVersion): Tuple of the kit identifier and the version associated with that kit. If this fails, (None, None) is returned ''' edid_model = get_edid_name() return EDID_MAP.get(edid_model, (None, None))
def test_get_edid_name(self, monkeypatch, edid): """ Tests that the get_edid_name function returns the correct display model. Args: monkeypatch - pytest fixture which gives mocking functionality edid - parameterised fixture containing raw, rpi_dumps, expected test data """ # Mock the run_cmd function such that it returns the dump for the device name. monkeypatch.setattr( display, 'run_cmd', lambda x: (edid['rpi_dumps']['device_name'], '', 0)) rv = display.get_edid_name(use_cached=False) assert (rv == edid['expected']['model'])
def __init__(self, win): # Show the Display brand and model self.model = get_edid_name() info_message = _("\nScreen Model: {}".format(self.model)) # And the current display resolution try: current_resolution = get_status()['resolution'] info_message += _("\nCurrent Resolution: {}").format(_(current_resolution)) except: pass Template.__init__( self, _("Display"), info_message, _("APPLY CHANGES") ) self.win = win self.win.set_main_widget(self) self.win.top_bar.enable_prev() self.win.change_prev_callback(self.win.go_to_home) self.kano_button.connect('button-release-event', self.apply_changes) self.kano_button.connect('key-release-event', self.apply_changes) horizontal_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=40) horizontal_container.set_valign(Gtk.Align.CENTER) # HDMI mode combo box self.mode_combo = KanoComboBox(max_display_items=7) self.mode_combo.connect('changed', self.on_mode_changed) # Fill list of modes modes = list_supported_modes() self.mode_combo.append('auto') mode_string = '{hdmi_group}:{hdmi_mode} {width}x{height} {refresh_rate}Hz {aspect_ratio}' if modes: for mode in modes: self.mode_combo.append(mode_string.format( hdmi_group=mode['group'], hdmi_mode=mode['mode'], width=mode['width'], height=mode['height'], refresh_rate=mode['rate'], aspect_ratio=mode['aspect_ratio'] )) horizontal_container.pack_start(self.mode_combo, False, False, 0) self.mode_combo.props.valign = Gtk.Align.CENTER # Select the current setting in the dropdown list saved_group, saved_mode = read_hdmi_mode() active_item = find_matching_mode(modes, saved_group, saved_mode) self.mode_combo.set_selected_item_index(active_item) self.init_item = active_item self.mode_index = active_item # Overscan button overscan_button = OrangeButton(_("Overscan")) horizontal_container.pack_end(overscan_button, False, False, 0) overscan_button.connect('button-release-event', self.go_to_overscan) self.box.pack_start(horizontal_container, False, False, 0) # Create Flip 180 checkbox flip_button = Gtk.CheckButton(_("Flip Screen")) flip_button.set_can_focus(False) flip_button.props.valign = Gtk.Align.CENTER flip_button.set_active(get_screen_value('display_rotate') == 2) flip_button.connect('clicked', self.flip) self.box.pack_start(flip_button, False, False, 0) self.kano_button.set_sensitive(False) # Add apply changes button under the main settings content self.win.show_all()
def test_get_failure(self): with patched_run_cmd('unused', returncode=1): edid = display.get_edid_name(use_cached=False) self.assertEqual(edid, None)
def test_get_empty_edid(self): with patched_run_cmd(self.EMPTY_DISPLAY_NAME): edid = display.get_edid_name(use_cached=False) self.assertEqual(edid, self.EMPTY_EDID_VAL)
def __init__(self, win): # Show the Display brand and model self.model = get_edid_name() info_message = _("\nScreen Model: {}".format(self.model)) # And the current display resolution try: current_resolution = get_status()['resolution'] info_message += _("\nCurrent Resolution: {}").format(_(current_resolution)) except: pass Template.__init__( self, _("Display"), info_message, _("APPLY CHANGES") ) self.win = win self.win.set_main_widget(self) self.win.top_bar.enable_prev() self.win.change_prev_callback(self.win.go_to_home) self.kano_button.connect('button-release-event', self.apply_changes) self.kano_button.connect('key-release-event', self.apply_changes) horizontal_container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=40) horizontal_container.set_valign(Gtk.Align.CENTER) # HDMI mode combo box self.mode_combo = KanoComboBox(max_display_items=7) self.mode_combo.connect('changed', self.on_mode_changed) # Fill list of modes modes = list_supported_modes() self.mode_combo.append('auto') mode_string = '{hdmi_group}:{hdmi_mode} {width}x{height} {refresh_rate}Hz {aspect_ratio}' if modes: for mode in modes: self.mode_combo.append(mode_string.format( hdmi_group=mode['group'], hdmi_mode=mode['mode'], width=mode['width'], height=mode['height'], refresh_rate=mode['rate'], aspect_ratio=mode['aspect_ratio'] )) horizontal_container.pack_start(self.mode_combo, False, False, 0) self.mode_combo.props.valign = Gtk.Align.CENTER # Select the current setting in the dropdown list saved_group, saved_mode = read_hdmi_mode() active_item = find_matching_mode(modes, saved_group, saved_mode) self.mode_combo.set_selected_item_index(active_item) self.init_item = active_item self.mode_index = active_item # Overscan button overscan_button = OrangeButton(_("Overscan")) horizontal_container.pack_end(overscan_button, False, False, 0) overscan_button.connect('button-release-event', self.go_to_overscan) self.box.pack_start(horizontal_container, False, False, 0) # Create Flip 180 checkbox flip_button = Gtk.CheckButton(_("Flip Screen")) flip_button.set_can_focus(False) flip_button.props.valign = Gtk.Align.CENTER self.flip_preference_start = (get_screen_value('display_rotate') == 2) self.flip_preference_end = self.flip_preference_start flip_button.set_active(self.flip_preference_start) flip_button.connect('clicked', self.on_flip_screen_clicked) self.box.pack_start(flip_button, False, False, 0) self.kano_button.set_sensitive(False) # Add apply changes button under the main settings content self.win.show_all()