Esempio n. 1
0
 def test_output_lister(self):
     pl = Pl()
     with replace_attr(i3wm, 'get_connected_xrandr_outputs',
                       self.get_outputs):
         self.assertEqual(
             list(i3wm.output_lister(pl=pl, segment_info={'a': 1})), [
                 ({
                     'a': 1,
                     'output': 'LVDS1'
                 }, {
                     'draw_inner_divider': None
                 }),
                 ({
                     'a': 1,
                     'output': 'HDMI1'
                 }, {
                     'draw_inner_divider': None
                 }),
                 ({
                     'a': 1,
                     'output': 'DVI01'
                 }, {
                     'draw_inner_divider': None
                 }),
             ])
Esempio n. 2
0
    def test_file_handler_create_dir(self):
        out = StringIO()
        err = StringIO()
        stream = StringIO()
        file_name = 'test_logging-test_file_handler_create_dir/file'

        self.assertFalse(os.path.isdir(os.path.dirname(file_name)))

        with replace_attr(sys, 'stdout', out, 'stderr', err):
            common_config = finish_common_config('utf-8',
                                                 {'log_file': file_name})
            try:
                logger, pl, get_module_attr = create_logger(common_config,
                                                            stream=stream)
                pl.error('Foo')
                close_handlers(logger)
                self.assertTrue(os.path.isdir(os.path.dirname(file_name)))
                with codecs.open(file_name, encoding='utf-8') as fp:
                    self.assertMatches(
                        fp.read(),
                        '^' + TIMESTAMP_RE + ':ERROR:__unknown__:Foo\n$')
            finally:
                rmtree(os.path.dirname(file_name))
            self.assertEqual(stream.getvalue(), '')
            self.assertEqual(err.getvalue(), '')
            self.assertEqual(out.getvalue(), '')
Esempio n. 3
0
    def test_top_log_level(self):
        out = StringIO()
        err = StringIO()
        stream = StringIO()
        stream1 = StringIO()

        with replace_attr(sys, 'stdout', out, 'stderr', err):
            common_config = finish_common_config(
                'utf-8', {
                    'log_file': [
                        ['logging.StreamHandler', [[stream1]], 'DEBUG'],
                    ],
                    'log_level': 'DEBUG'
                })
            logger, pl, get_module_attr = create_logger(common_config,
                                                        stream=stream)
            pl.debug('Foo')
            pl.error('Bar')
            close_handlers(logger)
            self.assertMatches(
                stream1.getvalue(),
                ('^' + TIMESTAMP_RE + ':DEBUG:__unknown__:Foo\n' +
                 TIMESTAMP_RE + ':ERROR:__unknown__:Bar\n$'))
            self.assertEqual(stream.getvalue(), '')
            self.assertEqual(err.getvalue(), '')
            self.assertEqual(out.getvalue(), '')
Esempio n. 4
0
    def test_top_log_format(self):
        out = StringIO()
        err = StringIO()
        stream = StringIO()
        stream1 = StringIO()
        stream2 = StringIO()

        with replace_attr(sys, 'stdout', out, 'stderr', err):
            common_config = finish_common_config(
                'utf-8', {
                    'log_file': [
                        [
                            'logging.StreamHandler', [[stream1]], 'WARNING',
                            'FOO'
                        ],
                        ['logging.StreamHandler', [[stream2]], 'WARNING'],
                    ],
                    'log_format':
                    'BAR'
                })
            logger, pl, get_module_attr = create_logger(common_config,
                                                        stream=stream)
            pl.warn('Foo')
            pl.error('Bar')
            close_handlers(logger)
            self.assertEqual(stream2.getvalue(), 'BAR\nBAR\n')
            self.assertEqual(stream1.getvalue(), 'FOO\nFOO\n')
            self.assertEqual(stream.getvalue(), '')
            self.assertEqual(err.getvalue(), '')
            self.assertEqual(out.getvalue(), '')
Esempio n. 5
0
    def test_multiple_files_and_stream(self):
        out = StringIO()
        err = StringIO()
        stream = StringIO()
        file_name_1 = 'test_logging-test_multiple_files_and_stream-1'
        file_name_2 = file_name_1[:-1] + '2'

        with replace_attr(sys, 'stdout', out, 'stderr', err):
            common_config = finish_common_config(
                'utf-8', {'log_file': [file_name_1, file_name_2, None]})
            try:
                try:
                    logger, pl, get_module_attr = create_logger(common_config,
                                                                stream=stream)
                    pl.error('Foo')
                    close_handlers(logger)
                    for file_name in (file_name_1, file_name_2):
                        with codecs.open(file_name, encoding='utf-8') as fp:
                            self.assertMatches(
                                fp.read(), '^' + TIMESTAMP_RE +
                                ':ERROR:__unknown__:Foo\n$')
                finally:
                    os.unlink(file_name_1)
            finally:
                os.unlink(file_name_2)
            self.assertMatches(
                stream.getvalue(),
                '^' + TIMESTAMP_RE + ':ERROR:__unknown__:Foo\n$')
            self.assertEqual(err.getvalue(), '')
            self.assertEqual(out.getvalue(), '')
	def test_wm(self):
		from powerline.segments import common
		from imp import reload
		reload(common)
		from powerline import Powerline
		with replace_attr(wthr, 'urllib_read', urllib_read):
			Powerline(logger=get_logger(), ext='wm', renderer_module='pango_markup', run_once=True).render()
		reload(common)
	def test_tmux(self):
		from powerline.segments import common
		from imp import reload
		reload(common)
		from powerline.shell import ShellPowerline
		with replace_attr(common, 'urllib_read', urllib_read):
			with ShellPowerline(Args(ext=['tmux']), logger=get_logger(), run_once=False) as powerline:
				powerline.render()
			with ShellPowerline(Args(ext=['tmux']), logger=get_logger(), run_once=False) as powerline:
				powerline.render()
Esempio n. 8
0
def swap_attributes(config, powerline_module):
	return replace_attr(powerline_module, 'os', Args(
		path=Args(
			isfile=lambda path: path.lstrip('/').replace('.json', '') in config,
			join=os.path.join,
			expanduser=lambda path: path,
			realpath=lambda path: path,
			dirname=os.path.dirname,
		),
		environ={},
	))
Esempio n. 9
0
def swap_attributes(config, powerline_module):
	return replace_attr(powerline_module, 'os', Args(
		path=Args(
			isfile=lambda path: path.lstrip('/').replace('.json', '') in config,
			join=os.path.join,
			expanduser=lambda path: path,
			realpath=lambda path: path,
			dirname=os.path.dirname,
		),
		environ={},
	))
Esempio n. 10
0
	def test_output_lister(self):
		pl = Pl()
		with replace_attr(i3wm, 'get_connected_xrandr_outputs', self.get_outputs):
			self.assertEqual(
				list(i3wm.output_lister(pl=pl, segment_info={'a': 1})),
				[
					({'a': 1, 'output': 'LVDS1'}, {'draw_inner_divider': None}),
					({'a': 1, 'output': 'HDMI1'}, {'draw_inner_divider': None}),
					({'a': 1, 'output': 'DVI01'}, {'draw_inner_divider': None}),
				]
			)
 def test_wm(self):
     from powerline.segments import common
     from imp import reload
     reload(common)
     from powerline import Powerline
     with replace_attr(wthr, 'urllib_read', urllib_read):
         Powerline(logger=get_logger(),
                   ext='wm',
                   renderer_module='pango_markup',
                   run_once=True).render()
     reload(common)
Esempio n. 12
0
	def test_safe_unicode(self):
		self.assertStringsIdentical('abc', plu.safe_unicode('abc'))
		self.assertStringsIdentical('abc', plu.safe_unicode(b'abc'))
		self.assertStringsIdentical('«»', plu.safe_unicode(b'\xc2\xab\xc2\xbb'))
		with replace_attr(plu, 'get_preferred_output_encoding', lambda: 'latin1'):
			self.assertStringsIdentical('ÿ', plu.safe_unicode(b'\xFF'))
		self.assertStringsIdentical('None', plu.safe_unicode(None))

		class FailingStr(object):
			def __str__(self):
				raise NotImplementedError('Fail!')

		self.assertStringsIdentical('Fail!', plu.safe_unicode(FailingStr()))
Esempio n. 13
0
    def test_stderr_handler_is_default(self):
        out = StringIO()
        err = StringIO()

        with replace_attr(sys, 'stdout', out, 'stderr', err):
            common_config = finish_common_config('utf-8', {})
            logger, pl, get_module_attr = create_logger(common_config)
            pl.error('Foo')
            close_handlers(logger)
            self.assertMatches(
                err.getvalue(),
                '^' + TIMESTAMP_RE + ':ERROR:__unknown__:Foo\n$')
            self.assertEqual(out.getvalue(), '')
 def test_tmux(self):
     from powerline.segments import common
     from imp import reload
     reload(common)
     from powerline.shell import ShellPowerline
     with replace_attr(common, 'urllib_read', urllib_read):
         with ShellPowerline(Args(ext=['tmux']),
                             logger=get_logger(),
                             run_once=False) as powerline:
             powerline.render()
         with ShellPowerline(Args(ext=['tmux']),
                             logger=get_logger(),
                             run_once=False) as powerline:
             powerline.render()
Esempio n. 15
0
    def test_strwidth_ucs_4(self):
        self.assertEqual(4, plu.strwidth_ucs_4(width_data, 'abcd'))
        self.assertEqual(4, plu.strwidth_ucs_4(width_data, 'AB'))
        if sys.maxunicode < 0x10FFFF:
            raise SkipTest('Can only test strwidth_ucs_4 in UCS-4 Pythons')

        def east_asian_width(ch):
            assert (len(ch) == 1)
            assert ord(ch) == 0x1F48E
            return 'F'

        with replace_attr(plu, 'east_asian_width', east_asian_width):
            # Warning: travis unicodedata.east_asian_width for some reason
            # thinks this character is 5 symbols wide.
            self.assertEqual(2, plu.strwidth_ucs_4(width_data, '\U0001F48E'))
Esempio n. 16
0
	def test_strwidth_ucs_4(self):
		self.assertEqual(4, plu.strwidth_ucs_4(width_data, 'abcd'))
		self.assertEqual(4, plu.strwidth_ucs_4(width_data, 'AB'))
		if sys.maxunicode < 0x10FFFF:
			raise SkipTest('Can only test strwidth_ucs_4 in UCS-4 Pythons')

		def east_asian_width(ch):
			assert (len(ch) == 1)
			assert ord(ch) == 0x1F48E
			return 'F'

		with replace_attr(plu, 'east_asian_width', east_asian_width):
			# Warning: travis unicodedata.east_asian_width for some reason 
			# thinks this character is 5 symbols wide.
			self.assertEqual(2, plu.strwidth_ucs_4(width_data, '\U0001F48E'))
Esempio n. 17
0
    def test_safe_unicode(self):
        self.assertStringsIdentical('abc', plu.safe_unicode('abc'))
        self.assertStringsIdentical('abc', plu.safe_unicode(b'abc'))
        self.assertStringsIdentical('«»',
                                    plu.safe_unicode(b'\xc2\xab\xc2\xbb'))
        with replace_attr(plu, 'get_preferred_output_encoding',
                          lambda: 'latin1'):
            self.assertStringsIdentical('ÿ', plu.safe_unicode(b'\xFF'))
        self.assertStringsIdentical('None', plu.safe_unicode(None))

        class FailingStr(object):
            def __str__(self):
                raise NotImplementedError('Fail!')

        self.assertStringsIdentical('Fail!', plu.safe_unicode(FailingStr()))
Esempio n. 18
0
    def test_explicit_none(self):
        out = StringIO()
        err = StringIO()
        stream = StringIO()

        with replace_attr(sys, 'stdout', out, 'stderr', err):
            common_config = finish_common_config('utf-8', {'log_file': [None]})
            logger, pl, get_module_attr = create_logger(common_config,
                                                        stream=stream)
            pl.error('Foo')
            close_handlers(logger)
            self.assertMatches(
                stream.getvalue(),
                '^' + TIMESTAMP_RE + ':ERROR:__unknown__:Foo\n$')
            self.assertEqual(err.getvalue(), '')
            self.assertEqual(out.getvalue(), '')
Esempio n. 19
0
    def test_main_err(self):
        parser = get_argparser()
        out = StrIO()
        err = StrIO()

        def flush():
            out.truncate(0)
            err.truncate(0)

        with replace_attr(sys, 'stdout', out, 'stderr', err):
            for raising_args, raising_reg in [
                ([],
                 'too few arguments|the following arguments are required: ext'
                 ),
                (['-r'], 'expected one argument'),
                (['shell', '-r'], 'expected one argument'),
                (['shell', '-w'], 'expected one argument'),
                (['shell', '-c'], 'expected one argument'),
                (['shell', '-t'], 'expected one argument'),
                (['shell', '-p'], 'expected one argument'),
                (['shell', '-R'], 'expected one argument'),
                (['shell', '--renderer-module'], 'expected one argument'),
                (['shell', '--width'], 'expected one argument'),
                (['shell', '--last-exit-code'], 'expected one argument'),
                (['shell', '--last-pipe-status'], 'expected one argument'),
                (['shell', '--config-override'], 'expected one argument'),
                (['shell', '--theme-override'], 'expected one argument'),
                (['shell', '--config-path'], 'expected one argument'),
                (['shell', '--renderer-arg'], 'expected one argument'),
                (['shell', '--jobnum'], 'expected one argument'),
                (['-r', '.zsh'],
                 'too few arguments|the following arguments are required: ext'
                 ),
                (['shell', '--last-exit-code',
                  'i'], 'invalid int_or_sig value'),
                (['shell', '--last-pipe-status',
                  '1 i'], 'invalid <lambda> value'),
            ]:
                self.assertRaises(SystemExit, parser.parse_args, raising_args)
                self.assertFalse(out.getvalue())
                self.assertRegexpMatches(err.getvalue(), raising_reg)
                flush()
Esempio n. 20
0
    def test_handler_args_kwargs(self):
        out = StringIO()
        err = StringIO()
        stream = StringIO()
        file_name = 'test_logging-test_handler_args_kwargs'

        with replace_attr(sys, 'stdout', out, 'stderr', err):
            common_config = finish_common_config(
                'utf-8', {
                    'log_file': [[
                        'RotatingFileHandler',
                        [[file_name], {
                            'maxBytes': 1,
                            'backupCount': 1
                        }]
                    ]]
                })
            try:
                try:
                    logger, pl, get_module_attr = create_logger(common_config,
                                                                stream=stream)
                    pl.error('Foo')
                    pl.error('Bar')
                    close_handlers(logger)
                    with codecs.open(file_name, encoding='utf-8') as fp:
                        self.assertMatches(
                            fp.read(),
                            '^' + TIMESTAMP_RE + ':ERROR:__unknown__:Bar\n$')
                    with codecs.open(file_name + '.1', encoding='utf-8') as fp:
                        self.assertMatches(
                            fp.read(),
                            '^' + TIMESTAMP_RE + ':ERROR:__unknown__:Foo\n$')
                finally:
                    os.unlink(file_name + '.1')
            finally:
                os.unlink(file_name)
            self.assertEqual(stream.getvalue(), '')
            self.assertEqual(err.getvalue(), '')
            self.assertEqual(out.getvalue(), '')
Esempio n. 21
0
    def test_workspace_lister(self):
        pl = Pl()
        with replace_attr(i3wm, 'get_i3_connection',
                          lambda: Args(get_workspaces=self.get_workspaces)):
            self.assertEqual(
                list(i3wm.workspace_lister(pl=pl, segment_info={'a': 1})), [
                    ({
                        'a': 1,
                        'output': 'LVDS1',
                        'workspace': self.workspaces[0],
                    }, {
                        'draw_inner_divider': None
                    }),
                    ({
                        'a': 1,
                        'output': 'LVDS1',
                        'workspace': self.workspaces[1],
                    }, {
                        'draw_inner_divider': None
                    }),
                    ({
                        'a': 1,
                        'output': 'HDMI1',
                        'workspace': self.workspaces[2],
                    }, {
                        'draw_inner_divider': None
                    }),
                    ({
                        'a': 1,
                        'output': 'DVI01',
                        'workspace': self.workspaces[3],
                    }, {
                        'draw_inner_divider': None
                    }),
                ])

            self.assertEqual(
                list(
                    i3wm.workspace_lister(pl=pl,
                                          segment_info={'a': 1},
                                          output='LVDS1')),
                [
                    ({
                        'a': 1,
                        'output': 'LVDS1',
                        'workspace': self.workspaces[0],
                    }, {
                        'draw_inner_divider': None
                    }),
                    ({
                        'a': 1,
                        'output': 'LVDS1',
                        'workspace': self.workspaces[1],
                    }, {
                        'draw_inner_divider': None
                    }),
                ])

            self.assertEqual(
                list(
                    i3wm.workspace_lister(pl=pl,
                                          segment_info={
                                              'a': 1,
                                              'output': 'LVDS1'
                                          })),
                [
                    ({
                        'a': 1,
                        'output': 'LVDS1',
                        'workspace': self.workspaces[0],
                    }, {
                        'draw_inner_divider': None
                    }),
                    ({
                        'a': 1,
                        'output': 'LVDS1',
                        'workspace': self.workspaces[1],
                    }, {
                        'draw_inner_divider': None
                    }),
                ])

            self.assertEqual(
                list(
                    i3wm.workspace_lister(pl=pl,
                                          segment_info={
                                              'a': 1,
                                              'output': 'LVDS1'
                                          },
                                          output=False)),
                [
                    ({
                        'a': 1,
                        'output': 'LVDS1',
                        'workspace': self.workspaces[0],
                    }, {
                        'draw_inner_divider': None
                    }),
                    ({
                        'a': 1,
                        'output': 'LVDS1',
                        'workspace': self.workspaces[1],
                    }, {
                        'draw_inner_divider': None
                    }),
                    ({
                        'a': 1,
                        'output': 'HDMI1',
                        'workspace': self.workspaces[2],
                    }, {
                        'draw_inner_divider': None
                    }),
                    ({
                        'a': 1,
                        'output': 'DVI01',
                        'workspace': self.workspaces[3],
                    }, {
                        'draw_inner_divider': None
                    }),
                ])

            self.assertEqual(
                list(
                    i3wm.workspace_lister(pl=pl,
                                          segment_info={'a': 1},
                                          only_show=['focused', 'urgent'])),
                [
                    ({
                        'a': 1,
                        'output': 'HDMI1',
                        'workspace': self.workspaces[2],
                    }, {
                        'draw_inner_divider': None
                    }),
                    ({
                        'a': 1,
                        'output': 'DVI01',
                        'workspace': self.workspaces[3],
                    }, {
                        'draw_inner_divider': None
                    }),
                ])
Esempio n. 22
0
	def test_workspace_lister(self):
		pl = Pl()
		with replace_attr(i3wm, 'get_i3_connection', lambda: Args(get_workspaces=self.get_workspaces)):
			self.assertEqual(
				list(i3wm.workspace_lister(pl=pl, segment_info={'a': 1})),
				[
					({
						'a': 1,
						'output': 'LVDS1',
						'workspace': {
							'name': '1: w1',
							'focused': False,
							'urgent': False,
							'visible': False
						}
					}, {'draw_inner_divider': None}),
					({
						'a': 1,
						'output': 'LVDS1',
						'workspace': {
							'name': '2: w2',
							'focused': False,
							'urgent': False,
							'visible': True
						}
					}, {'draw_inner_divider': None}),
					({
						'a': 1,
						'output': 'HDMI1',
						'workspace': {
							'name': '3: w3',
							'focused': False,
							'urgent': True,
							'visible': True
						}
					}, {'draw_inner_divider': None}),
					({
						'a': 1,
						'output': 'DVI01',
						'workspace': {
							'name': '4: w4',
							'focused': True,
							'urgent': True,
							'visible': True
						}
					}, {'draw_inner_divider': None}),
				]
			)

			self.assertEqual(
				list(i3wm.workspace_lister(pl=pl, segment_info={'a': 1}, output='LVDS1')),
				[
					({
						'a': 1,
						'output': 'LVDS1',
						'workspace': {
							'name': '1: w1',
							'focused': False,
							'urgent': False,
							'visible': False
						}
					}, {'draw_inner_divider': None}),
					({
						'a': 1,
						'output': 'LVDS1',
						'workspace': {
							'name': '2: w2',
							'focused': False,
							'urgent': False,
							'visible': True
						}
					}, {'draw_inner_divider': None}),
				]
			)

			self.assertEqual(
				list(i3wm.workspace_lister(
					pl=pl,
					segment_info={'a': 1, 'output': 'LVDS1'}
				)),
				[
					({
						'a': 1,
						'output': 'LVDS1',
						'workspace': {
							'name': '1: w1',
							'focused': False,
							'urgent': False,
							'visible': False
						}
					}, {'draw_inner_divider': None}),
					({
						'a': 1,
						'output': 'LVDS1',
						'workspace': {
							'name': '2: w2',
							'focused': False,
							'urgent': False,
							'visible': True
						}
					}, {'draw_inner_divider': None}),
				]
			)

			self.assertEqual(
				list(i3wm.workspace_lister(
					pl=pl,
					segment_info={'a': 1, 'output': 'LVDS1'},
					output=False
				)),
				[
					({
						'a': 1,
						'output': 'LVDS1',
						'workspace': {
							'name': '1: w1',
							'focused': False,
							'urgent': False,
							'visible': False
						}
					}, {'draw_inner_divider': None}),
					({
						'a': 1,
						'output': 'LVDS1',
						'workspace': {
							'name': '2: w2',
							'focused': False,
							'urgent': False,
							'visible': True
						}
					}, {'draw_inner_divider': None}),
					({
						'a': 1,
						'output': 'HDMI1',
						'workspace': {
							'name': '3: w3',
							'focused': False,
							'urgent': True,
							'visible': True
						}
					}, {'draw_inner_divider': None}),
					({
						'a': 1,
						'output': 'DVI01',
						'workspace': {
							'name': '4: w4',
							'focused': True,
							'urgent': True,
							'visible': True
						}
					}, {'draw_inner_divider': None}),
				]
			)

			self.assertEqual(
				list(i3wm.workspace_lister(
					pl=pl,
					segment_info={'a': 1},
					only_show=['focused', 'urgent']
				)),
				[
					({
						'a': 1,
						'output': 'HDMI1',
						'workspace': {
							'name': '3: w3',
							'focused': False,
							'urgent': True,
							'visible': True
						}
					}, {'draw_inner_divider': None}),
					({
						'a': 1,
						'output': 'DVI01',
						'workspace': {
							'name': '4: w4',
							'focused': True,
							'urgent': True,
							'visible': True
						}
					}, {'draw_inner_divider': None}),
				]
			)
Esempio n. 23
0
	def test_main_normal(self):
		parser = get_argparser()
		out = StrIO()
		err = StrIO()
		with replace_attr(sys, 'stdout', out, 'stderr', err):
			for argv, expargs in [
				(['shell', 'left'],       {'ext': ['shell'], 'side': 'left'}),
				(['shell', 'left', '-r', '.zsh'], {'ext': ['shell'], 'renderer_module': '.zsh', 'side': 'left'}),
				([
					'shell',
					'left',
					'-r', '.zsh',
					'--last-exit-code', '10',
					'--last-pipe-status', '10 20 30',
					'--jobnum=10',
					'-w', '100',
					'-c', 'common.term_truecolor=true',
					'-c', 'common.spaces=4',
					'-t', 'default.segment_data.hostname.before=H:',
					'-p', '.',
					'-p', '..',
					'-R', 'smth={"abc":"def"}',
				], {
					'ext': ['shell'],
					'side': 'left',
					'renderer_module': '.zsh',
					'last_exit_code': 10,
					'last_pipe_status': [10, 20, 30],
					'jobnum': 10,
					'width': 100,
					'config_override': {'common': {'term_truecolor': True, 'spaces': 4}},
					'theme_override': {
						'default': {
							'segment_data': {
								'hostname': {
									'before': 'H:'
								}
							}
						}
					},
					'config_path': ['.', '..'],
					'renderer_arg': {'smth': {'abc': 'def'}},
				}),
				(['shell', 'left', '-R', 'arg=true'], {
					'ext': ['shell'],
					'side': 'left',
					'renderer_arg': {'arg': True},
				}),
				(['shell', 'left', '-R', 'arg=true', '-R', 'arg='], {
					'ext': ['shell'],
					'side': 'left',
					'renderer_arg': {},
				}),
				(['shell', 'left', '-R', 'arg='], {'ext': ['shell'], 'renderer_arg': {}, 'side': 'left'}),
				(['shell', 'left', '-t', 'default.segment_info={"hostname": {}}'], {
					'ext': ['shell'],
					'side': 'left',
					'theme_override': {
						'default': {
							'segment_info': {
								'hostname': {}
							}
						}
					},
				}),
				(['shell', 'left', '-c', 'common={ }'], {
					'ext': ['shell'],
					'side': 'left',
					'config_override': {'common': {}},
				}),
			]:
				args = parser.parse_args(argv)
				finish_args(parser, {}, args)
				for key, val in expargs.items():
					self.assertEqual(getattr(args, key), val)
				for key, val in args.__dict__.items():
					if key not in expargs:
						self.assertFalse(val, msg='key {0} is {1} while it should be something false'.format(key, val))
				self.assertFalse(err.getvalue() + out.getvalue(), msg='unexpected output: {0!r} {1!r}'.format(
					err.getvalue(),
					out.getvalue(),
				))
Esempio n. 24
0
    def test_workspace_lister(self):
        pl = Pl()
        with replace_attr(i3wm, 'get_i3_connection',
                          lambda: Args(get_workspaces=self.get_workspaces)):
            self.assertEqual(
                list(i3wm.workspace_lister(pl=pl, segment_info={'a': 1})), [
                    ({
                        'a': 1,
                        'output': 'LVDS1',
                        'workspace': {
                            'name': '1: w1',
                            'focused': False,
                            'urgent': False,
                            'visible': False
                        }
                    }, {
                        'draw_inner_divider': None
                    }),
                    ({
                        'a': 1,
                        'output': 'LVDS1',
                        'workspace': {
                            'name': '2: w2',
                            'focused': False,
                            'urgent': False,
                            'visible': True
                        }
                    }, {
                        'draw_inner_divider': None
                    }),
                    ({
                        'a': 1,
                        'output': 'HDMI1',
                        'workspace': {
                            'name': '3: w3',
                            'focused': False,
                            'urgent': True,
                            'visible': True
                        }
                    }, {
                        'draw_inner_divider': None
                    }),
                    ({
                        'a': 1,
                        'output': 'DVI01',
                        'workspace': {
                            'name': '4: w4',
                            'focused': True,
                            'urgent': True,
                            'visible': True
                        }
                    }, {
                        'draw_inner_divider': None
                    }),
                ])

            self.assertEqual(
                list(
                    i3wm.workspace_lister(pl=pl,
                                          segment_info={'a': 1},
                                          output='LVDS1')), [
                                              ({
                                                  'a': 1,
                                                  'output': 'LVDS1',
                                                  'workspace': {
                                                      'name': '1: w1',
                                                      'focused': False,
                                                      'urgent': False,
                                                      'visible': False
                                                  }
                                              }, {
                                                  'draw_inner_divider': None
                                              }),
                                              ({
                                                  'a': 1,
                                                  'output': 'LVDS1',
                                                  'workspace': {
                                                      'name': '2: w2',
                                                      'focused': False,
                                                      'urgent': False,
                                                      'visible': True
                                                  }
                                              }, {
                                                  'draw_inner_divider': None
                                              }),
                                          ])

            self.assertEqual(
                list(
                    i3wm.workspace_lister(pl=pl,
                                          segment_info={
                                              'a': 1,
                                              'output': 'LVDS1'
                                          })), [
                                              ({
                                                  'a': 1,
                                                  'output': 'LVDS1',
                                                  'workspace': {
                                                      'name': '1: w1',
                                                      'focused': False,
                                                      'urgent': False,
                                                      'visible': False
                                                  }
                                              }, {
                                                  'draw_inner_divider': None
                                              }),
                                              ({
                                                  'a': 1,
                                                  'output': 'LVDS1',
                                                  'workspace': {
                                                      'name': '2: w2',
                                                      'focused': False,
                                                      'urgent': False,
                                                      'visible': True
                                                  }
                                              }, {
                                                  'draw_inner_divider': None
                                              }),
                                          ])

            self.assertEqual(
                list(
                    i3wm.workspace_lister(pl=pl,
                                          segment_info={
                                              'a': 1,
                                              'output': 'LVDS1'
                                          },
                                          output=False)), [
                                              ({
                                                  'a': 1,
                                                  'output': 'LVDS1',
                                                  'workspace': {
                                                      'name': '1: w1',
                                                      'focused': False,
                                                      'urgent': False,
                                                      'visible': False
                                                  }
                                              }, {
                                                  'draw_inner_divider': None
                                              }),
                                              ({
                                                  'a': 1,
                                                  'output': 'LVDS1',
                                                  'workspace': {
                                                      'name': '2: w2',
                                                      'focused': False,
                                                      'urgent': False,
                                                      'visible': True
                                                  }
                                              }, {
                                                  'draw_inner_divider': None
                                              }),
                                              ({
                                                  'a': 1,
                                                  'output': 'HDMI1',
                                                  'workspace': {
                                                      'name': '3: w3',
                                                      'focused': False,
                                                      'urgent': True,
                                                      'visible': True
                                                  }
                                              }, {
                                                  'draw_inner_divider': None
                                              }),
                                              ({
                                                  'a': 1,
                                                  'output': 'DVI01',
                                                  'workspace': {
                                                      'name': '4: w4',
                                                      'focused': True,
                                                      'urgent': True,
                                                      'visible': True
                                                  }
                                              }, {
                                                  'draw_inner_divider': None
                                              }),
                                          ])

            self.assertEqual(
                list(
                    i3wm.workspace_lister(pl=pl,
                                          segment_info={'a': 1},
                                          only_show=['focused', 'urgent'])), [
                                              ({
                                                  'a': 1,
                                                  'output': 'HDMI1',
                                                  'workspace': {
                                                      'name': '3: w3',
                                                      'focused': False,
                                                      'urgent': True,
                                                      'visible': True
                                                  }
                                              }, {
                                                  'draw_inner_divider': None
                                              }),
                                              ({
                                                  'a': 1,
                                                  'output': 'DVI01',
                                                  'workspace': {
                                                      'name': '4: w4',
                                                      'focused': True,
                                                      'urgent': True,
                                                      'visible': True
                                                  }
                                              }, {
                                                  'draw_inner_divider': None
                                              }),
                                          ])