def test_find_best_ambiguous(self): """ Test matching for similarly scored profiles """ edid = "office" edidhash = profile.md5(edid) connected_outputs = [ XrandrOutput("LVDS1", True), XrandrOutput("DP1", True, supported_modes=["1920x1080"], edid=edid) ] profile_outputs = [ Output("LVDS1", Geometry('1366x768'), True), Output("DP1", Geometry('1920x1080')) ] p1 = Profile("p1", profile_outputs, { "LVDS1": Rule(), "DP1": Rule(edidhash) }) p2 = Profile("p2", profile_outputs, { "LVDS1": Rule(), "DP1": Rule(edidhash) }) best = self.matcher.find_best([p1, p2], connected_outputs) self.assertEqual(p1, best)
def test_compose_mode_args(self): xrandr = Xrandr() xrandr.EXECUTABLE = "stub" outputs = [ Output("LVDS1", Geometry(1366, 768), primary=True), Output("DP1", Geometry(1920, 1080, 1366, 0)), Output("VGA1", Geometry(800, 600, 0, 768)) ] p = Profile("default", outputs) xrandr_connections = [XrandrOutput("HDMI1"), XrandrOutput("HDMI2")] command = xrandr.__compose_mode_args__(p, xrandr_connections) num_of_outputs = len(outputs) + len(xrandr_connections) self.assertEqual(num_of_outputs, command.count(xrandr.OUTPUT_KEY)) self.assertEqual(len(outputs), command.count(xrandr.POS_KEY)) self.assertEqual(len(outputs), command.count(xrandr.MODE_KEY)) self.assertEqual(len(xrandr_connections), command.count(xrandr.OFF_KEY)) self.assertEqual(1, command.count(xrandr.PRIMARY_KEY)) self.assertEqual(1, command.count("LVDS1")) self.assertEqual(1, command.count("DP1")) self.assertEqual(1, command.count("VGA1")) self.assertEqual(1, command.count("HDMI1")) self.assertEqual(1, command.count("HDMI2"))
def output_from_query_item(self, item_lines: list): """ Creates XrandrOutput from lines returned by xrandr --query. First line is an output description. Subsequent, if any, are supported modes. Example: LVDS1 connected 1366x768+0+312 (normal left inverted right x axis y axis) 277mm x 156mm 1366x768 60.02*+ 1024x768 60.00 """ output_info = item_lines[0] tokens = output_info.split(' ', 2) name = tokens[0] status = tokens[1] connected = status == 'connected' if not connected: # if we are not connected, do not parse the rest return XrandrOutput(name, connected) # we are connected parse supported modes supported_modes = [] preferred_mode = None current_mode = None current_rate = None for mode_line in item_lines[1:]: mode_line = mode_line.strip() (mode, rate, extra) = self.CURRENT_MODE_REGEX.match(mode_line).groups() current = (extra.find("*") >= 0) preferred = (extra.find("+") >= 0) supported_modes.append(mode) if current: current_mode = mode current_rate = round(float(rate)) if preferred: preferred_mode = mode if current_mode is None: # inactive output return XrandrOutput(name, connected, supported_modes=supported_modes, preferred_mode=preferred_mode) # if we are active parse the rest and return full-blown output details = tokens[2] output_details = self.parse_output_details(details) res = output_details['res'] pos = output_details['pos'] primary = output_details['primary'] rotate = output_details['rotate'] panning = res if res != current_mode else '0x0' rotate = rotate if rotate else 'normal' geometry = Geometry(current_mode, pos, rotate, panning, current_rate) return XrandrOutput(name, connected, geometry, primary, supported_modes, preferred_mode)
def test_find_best_mode(self): outputs = [ XrandrOutput("LVDS1", True), XrandrOutput("DP1", True, supported_modes=["1920x1080"], edid="office") ] best = self.matcher.find_best(self.profiles, outputs) self.assertEqual(self.profiles[1], best)
def test_find_best_no_match(self): outputs = [ XrandrOutput("LVDS1", True), XrandrOutput("DP1", True, supported_modes=["1280x1024"], edid="guest") ] best = self.matcher.find_best(self.profiles, outputs) self.assertIsNone(best)
def test_find_best_prefers_over_supports(self): outputs = [ XrandrOutput("LVDS1", True), XrandrOutput("DP1", True, supported_modes=["1920x1080", "1920x1200"], preferred_mode="1920x1200", edid="office") ] best = self.matcher.find_best(self.profiles, outputs) self.assertEqual(self.profiles[2], best)
def test_profile_from_xrandr(self): xc = [ XrandrOutput("LVDS1", True, Geometry("1366x768"), False), XrandrOutput("DP1", True, Geometry("1920x1080", pos="1366x0"), True), XrandrOutput("HDMI1", False, Geometry("1366x768"), False) ] p = self.manager.profile_from_xrandr(xc) self.assertEqual("profile", p.name) self.assertEqual(2, len(p.outputs))
def test_find_best_default(self): outputs = [XrandrOutput("LVDS1", True)] best = self.matcher.find_best(self.profiles, outputs) self.assertEqual(self.profiles[0], best)