当前位置: 首页>>代码示例>>Python>>正文


Python vim._with函数代码示例

本文整理汇总了Python中tests.vim._with函数的典型用法代码示例。如果您正苦于以下问题:Python _with函数的具体用法?Python _with怎么用?Python _with使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了_with函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_vim

	def test_vim(self):
		from powerline.vim import VimPowerline
		cfg_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'powerline', 'config_files')
		buffers = ((('bufoptions',), {'buftype': 'help'}), (('buffer', '[Command Line]'), {}), (('bufoptions',), {'buftype': 'quickfix'}))
		with open(os.path.join(cfg_path, 'config.json'), 'r') as f:
			self.assertEqual(len(buffers), len(json.load(f)['ext']['vim']['local_themes']))
		outputs = {}
		i = 0
		mode = None

		with VimPowerline() as powerline:
			def check_output(*args):
				out = powerline.render(*args + (0 if mode == 'nc' else 1,))
				if out in outputs:
					self.fail('Duplicate in set #{0} for mode {1!r} (previously defined in set #{2} for mode {3!r})'.format(i, mode, *outputs[out]))
				outputs[out] = (i, mode)

			with vim_module._with('buffer', 'foo.txt'):
				with vim_module._with('globals', powerline_config_path=cfg_path):
					exclude = set(('no', 'v', 'V', VBLOCK, 's', 'S', SBLOCK, 'R', 'Rv', 'c', 'cv', 'ce', 'r', 'rm', 'r?', '!'))
					try:
						for mode in ['n', 'nc', 'no', 'v', 'V', VBLOCK, 's', 'S', SBLOCK, 'i', 'R', 'Rv', 'c', 'cv', 'ce', 'r', 'rm', 'r?', '!']:
							if mode != 'nc':
								vim_module._start_mode(mode)
							check_output(1, 0)
							for args, kwargs in buffers:
								i += 1
								if mode in exclude:
									continue
								with vim_module._with(*args, **kwargs):
									check_output(1, 0)
					finally:
						vim_module._start_mode('n')
开发者ID:DaneelOliwan,项目名称:dotfiles-vim,代码行数:33,代码来源:test_configuration.py

示例2: test_vim

	def test_vim(self):
		from powerline.vim import VimPowerline
		cfg_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'powerline', 'config_files')
		buffers = (
			(('bufoptions',), {'buftype': 'help'}),
			(('bufname', '[Command Line]'), {}),
			(('bufoptions',), {'buftype': 'quickfix'}),
			(('bufname', 'NERD_tree_1'), {}),
			(('bufname', '__Gundo__'), {}),
			(('bufname', '__Gundo_Preview__'), {}),
			(('bufname', 'ControlP'), {}),
			# No Command-T tests here: requires +ruby or emulation
			# No tabline here: tablines are tested separately
		)
		with open(os.path.join(cfg_path, 'config.json'), 'r') as f:
			local_themes_raw = json.load(f)['ext']['vim']['local_themes']
			# Don’t run tests on external/plugin segments
			local_themes = dict((k, v) for (k, v) in local_themes_raw.items())
			# See end of the buffers definition above for `- 2`
			self.assertEqual(len(buffers), len(local_themes) - 2)
		outputs = {}
		i = 0

		with vim_module._with('split'):
			with VimPowerline(logger=get_logger()) as powerline:
				def check_output(mode, args, kwargs):
					if mode == 'nc':
						window = vim_module.windows[0]
						window_id = 2
					else:
						vim_module._start_mode(mode)
						window = vim_module.current.window
						window_id = 1
					winnr = window.number
					out = powerline.render(window, window_id, winnr)
					if out in outputs:
						self.fail('Duplicate in set #{0} ({1}) for mode {2!r} (previously defined in set #{3} ({4!r}) for mode {5!r})'.format(i, (args, kwargs), mode, *outputs[out]))
					outputs[out] = (i, (args, kwargs), mode)

				with vim_module._with('bufname', '/tmp/foo.txt'):
					out = powerline.render(vim_module.current.window, 1, vim_module.current.window.number, is_tabline=True)
					outputs[out] = (-1, (None, None), 'tab')
					with vim_module._with('globals', powerline_config_paths=[cfg_path]):
						exclude = set(('no', 'v', 'V', VBLOCK, 's', 'S', SBLOCK, 'R', 'Rv', 'c', 'cv', 'ce', 'r', 'rm', 'r?', '!'))
						try:
							for mode in ['n', 'nc', 'no', 'v', 'V', VBLOCK, 's', 'S', SBLOCK, 'i', 'R', 'Rv', 'c', 'cv', 'ce', 'r', 'rm', 'r?', '!']:
								check_output(mode, None, None)
								for args, kwargs in buffers:
									i += 1
									if mode in exclude:
										continue
									if mode == 'nc' and args == ('bufname', 'ControlP'):
										# ControlP window is not supposed to not 
										# be in the focus
										continue
									with vim_module._with(*args, **kwargs):
										check_output(mode, args, kwargs)
						finally:
							vim_module._start_mode('n')
开发者ID:DataThinkMonkey,项目名称:vimrc,代码行数:59,代码来源:test_provided_config_files.py

示例3: test_mode

	def test_mode(self):
		segment_info = vim_module._get_segment_info()
		self.assertEqual(vim.mode(segment_info=segment_info), 'NORMAL')
		self.assertEqual(vim.mode(segment_info=segment_info, override={'i': 'INS'}), 'NORMAL')
		self.assertEqual(vim.mode(segment_info=segment_info, override={'n': 'NORM'}), 'NORM')
		with vim_module._with('mode', 'i') as segment_info:
			self.assertEqual(vim.mode(segment_info=segment_info), 'INSERT')
		with vim_module._with('mode', chr(ord('V') - 0x40)) as segment_info:
			self.assertEqual(vim.mode(segment_info=segment_info), 'V·BLCK')
			self.assertEqual(vim.mode(segment_info=segment_info, override={'^V': 'VBLK'}), 'VBLK')
开发者ID:kovidgoyal,项目名称:powerline,代码行数:10,代码来源:test_segments.py

示例4: test_file_name

	def test_file_name(self):
		segment_info = vim_module._get_segment_info()
		self.assertEqual(vim.file_name(segment_info=segment_info), None)
		self.assertEqual(vim.file_name(segment_info=segment_info, display_no_file=True),
				[{'contents': '[No file]', 'highlight_group': ['file_name_no_file', 'file_name']}])
		self.assertEqual(vim.file_name(segment_info=segment_info, display_no_file=True, no_file_text='X'),
				[{'contents': 'X', 'highlight_group': ['file_name_no_file', 'file_name']}])
		with vim_module._with('buffer', '/tmp/abc') as segment_info:
			self.assertEqual(vim.file_name(segment_info=segment_info), 'abc')
		with vim_module._with('buffer', '/tmp/’’') as segment_info:
			self.assertEqual(vim.file_name(segment_info=segment_info), '’’')
开发者ID:kovidgoyal,项目名称:powerline,代码行数:11,代码来源:test_segments.py

示例5: test_file_vcs_status

	def test_file_vcs_status(self):
		pl = Pl()
		with vim_module._with('buffer', '/foo') as segment_info:
			with replace_attr(vim, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda file: 'M', directory=path)):
				self.assertEqual(vim.file_vcs_status(pl=pl, segment_info=segment_info),
						[{'highlight_group': ['file_vcs_status_M', 'file_vcs_status'], 'contents': 'M'}])
			with replace_attr(vim, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda file: None, directory=path)):
				self.assertEqual(vim.file_vcs_status(pl=pl, segment_info=segment_info), None)
		with vim_module._with('buffer', '/bar') as segment_info:
			with vim_module._with('bufoptions', buftype='nofile'):
				with replace_attr(vim, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda file: 'M', directory=path)):
					self.assertEqual(vim.file_vcs_status(pl=pl, segment_info=segment_info), None)
开发者ID:KinzataDev,项目名称:dotfiles,代码行数:12,代码来源:test_segments.py

示例6: test_file_directory

	def test_file_directory(self):
		pl = Pl()
		segment_info = vim_module._get_segment_info()
		self.assertEqual(vim.file_directory(pl=pl, segment_info=segment_info), None)
		with replace_env('HOME', '/home/foo', os.environ):
			with vim_module._with('buffer', '/tmp/’’/abc') as segment_info:
				self.assertEqual(vim.file_directory(pl=pl, segment_info=segment_info), '/tmp/’’/')
			with vim_module._with('buffer', b'/tmp/\xFF\xFF/abc') as segment_info:
				self.assertEqual(vim.file_directory(pl=pl, segment_info=segment_info), '/tmp/<ff><ff>/')
			with vim_module._with('buffer', '/tmp/abc') as segment_info:
				self.assertEqual(vim.file_directory(pl=pl, segment_info=segment_info), '/tmp/')
				os.environ['HOME'] = '/tmp'
				self.assertEqual(vim.file_directory(pl=pl, segment_info=segment_info), '~/')
开发者ID:liston,项目名称:Myvimrc,代码行数:13,代码来源:test_segments.py

示例7: test_file_vcs_status

	def test_file_vcs_status(self):
		pl = Pl()
		create_watcher = get_fallback_create_watcher()
		file_vcs_status = partial(vim.file_vcs_status, pl=pl, create_watcher=create_watcher)
		with vim_module._with('buffer', '/foo') as segment_info:
			with replace_attr(vim, 'guess', get_dummy_guess(status=lambda file: 'M')):
				self.assertEqual(file_vcs_status(segment_info=segment_info),
						[{'highlight_group': ['file_vcs_status_M', 'file_vcs_status'], 'contents': 'M'}])
			with replace_attr(vim, 'guess', get_dummy_guess(status=lambda file: None)):
				self.assertEqual(file_vcs_status(segment_info=segment_info), None)
		with vim_module._with('buffer', '/bar') as segment_info:
			with vim_module._with('bufoptions', buftype='nofile'):
				with replace_attr(vim, 'guess', get_dummy_guess(status=lambda file: 'M')):
					self.assertEqual(file_vcs_status(segment_info=segment_info), None)
开发者ID:liston,项目名称:Myvimrc,代码行数:14,代码来源:test_segments.py

示例8: test_paste_indicator

	def test_paste_indicator(self):
		pl = Pl()
		segment_info = vim_module._get_segment_info()
		self.assertEqual(vim.paste_indicator(pl=pl, segment_info=segment_info), None)
		with vim_module._with('options', paste=1):
			self.assertEqual(vim.paste_indicator(pl=pl, segment_info=segment_info), 'PASTE')
			self.assertEqual(vim.paste_indicator(pl=pl, segment_info=segment_info, text='P'), 'P')
开发者ID:KinzataDev,项目名称:dotfiles,代码行数:7,代码来源:test_segments.py

示例9: test_readonly_indicator

	def test_readonly_indicator(self):
		pl = Pl()
		segment_info = vim_module._get_segment_info()
		self.assertEqual(vim.readonly_indicator(pl=pl, segment_info=segment_info), None)
		with vim_module._with('bufoptions', readonly=1):
			self.assertEqual(vim.readonly_indicator(pl=pl, segment_info=segment_info), '')
			self.assertEqual(vim.readonly_indicator(pl=pl, segment_info=segment_info, text='L'), 'L')
开发者ID:KinzataDev,项目名称:dotfiles,代码行数:7,代码来源:test_segments.py

示例10: test_environ_update

	def test_environ_update(self):
		# Regression test: test that segment obtains environment from vim, not 
		# from os.environ.
		import tests.vim as vim_module
		with vim_module._with('globals', powerline_config_paths=['/']):
			from powerline.vim import VimPowerline
			import powerline as powerline_module
			with swap_attributes(config, powerline_module):
				with vim_module._with('environ', TEST='abc'):
					with get_powerline_raw(config, VimPowerline) as powerline:
						window = vim_module.current.window
						window_id = 1
						winnr = window.number
						self.assertEqual(powerline.render(window, window_id, winnr), b'%#Pl_3_8404992_4_192_underline#\xc2\xa0abc%#Pl_4_192_NONE_None_NONE#>>')
						vim_module._environ['TEST'] = 'def'
						self.assertEqual(powerline.render(window, window_id, winnr), b'%#Pl_3_8404992_4_192_underline#\xc2\xa0def%#Pl_4_192_NONE_None_NONE#>>')
开发者ID:21gunnns,项目名称:powerline,代码行数:16,代码来源:test_configuration.py

示例11: test_file_directory

	def test_file_directory(self):
		segment_info = vim_module._get_segment_info()
		self.assertEqual(vim.file_directory(segment_info=segment_info), None)
		with replace_env('HOME', '/home/foo'):
			with vim_module._with('buffer', '/tmp/abc') as segment_info:
				self.assertEqual(vim.file_directory(segment_info=segment_info), '/tmp/')
				os.environ['HOME'] = '/tmp'
				self.assertEqual(vim.file_directory(segment_info=segment_info), '~/')
开发者ID:kovidgoyal,项目名称:powerline,代码行数:8,代码来源:test_segments.py

示例12: test_vim

	def test_vim(self):
		from powerline.vim import VimPowerline
		cfg_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'powerline', 'config_files')
		buffers = (
			(('bufoptions',), {'buftype': 'help'}),
			(('bufname', '[Command Line]'), {}),
			(('bufoptions',), {'buftype': 'quickfix'}),
		)
		with open(os.path.join(cfg_path, 'config.json'), 'r') as f:
			local_themes_raw = json.load(f)['ext']['vim']['local_themes']
			# Don't run tests on external/plugin segments
			local_themes = dict((k, v) for (k, v) in local_themes_raw.items() if not '.' in k)
			self.assertEqual(len(buffers), len(local_themes))
		outputs = {}
		i = 0

		with vim_module._with('split'):
			with VimPowerline() as powerline:
				def check_output(mode, args, kwargs):
					if mode == 'nc':
						window = vim_module.windows[0]
						window_id = 2
					else:
						vim_module._start_mode(mode)
						window = vim_module.current.window
						window_id = 1
					winnr = window.number
					out = powerline.render(window, window_id, winnr)
					if out in outputs:
						self.fail('Duplicate in set #{0} ({1}) for mode {2!r} (previously defined in set #{3} ({4!r}) for mode {5!r})'.format(i, (args, kwargs), mode, *outputs[out]))
					outputs[out] = (i, (args, kwargs), mode)

				with vim_module._with('bufname', '/tmp/foo.txt'):
					with vim_module._with('globals', powerline_config_path=cfg_path):
						exclude = set(('no', 'v', 'V', VBLOCK, 's', 'S', SBLOCK, 'R', 'Rv', 'c', 'cv', 'ce', 'r', 'rm', 'r?', '!'))
						try:
							for mode in ['n', 'nc', 'no', 'v', 'V', VBLOCK, 's', 'S', SBLOCK, 'i', 'R', 'Rv', 'c', 'cv', 'ce', 'r', 'rm', 'r?', '!']:
								check_output(mode, None, None)
								for args, kwargs in buffers:
									i += 1
									if mode in exclude:
										continue
									with vim_module._with(*args, **kwargs):
										check_output(mode, args, kwargs)
						finally:
							vim_module._start_mode('n')
开发者ID:AureoleMoka,项目名称:current-config,代码行数:46,代码来源:test_configuration.py

示例13: test_file_opts

	def test_file_opts(self):
		segment_info = vim_module._get_segment_info()
		self.assertEqual(vim.file_format(segment_info=segment_info),
				[{'divider_highlight_group': 'background:divider', 'contents': 'unix'}])
		self.assertEqual(vim.file_encoding(segment_info=segment_info),
				[{'divider_highlight_group': 'background:divider', 'contents': 'utf-8'}])
		self.assertEqual(vim.file_type(segment_info=segment_info), None)
		with vim_module._with('bufoptions', filetype='python'):
			self.assertEqual(vim.file_type(segment_info=segment_info),
					[{'divider_highlight_group': 'background:divider', 'contents': 'python'}])
开发者ID:kovidgoyal,项目名称:powerline,代码行数:10,代码来源:test_segments.py

示例14: test_environ_update

	def test_environ_update(self):
		# Regression test: test that segment obtains environment from vim, not 
		# from os.environ.
		from powerline.vim import VimPowerline
		with vim_module._with('environ', TEST='abc'):
			with get_powerline_raw(VimPowerline) as powerline:
				window = vim_module.current.window
				window_id = 1
				winnr = window.number
				self.assertEqual(powerline.render(window, window_id, winnr), '%#Pl_3_8404992_4_192_underline#\xa0abc%#Pl_4_192_NONE_None_NONE#>>')
				vim_module._environ['TEST'] = 'def'
				self.assertEqual(powerline.render(window, window_id, winnr), '%#Pl_3_8404992_4_192_underline#\xa0def%#Pl_4_192_NONE_None_NONE#>>')
开发者ID:wezhang,项目名称:vim-setup,代码行数:12,代码来源:test_configuration.py

示例15: test_branch

	def test_branch(self):
		pl = Pl()
		with vim_module._with('buffer', '/foo') as segment_info:
			with replace_attr(vim, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda: None, directory=path)):
				self.assertEqual(vim.branch(pl=pl, segment_info=segment_info),
						[{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch'], 'contents': 'foo'}])
				self.assertEqual(vim.branch(pl=pl, segment_info=segment_info, status_colors=True),
						[{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch_clean', 'branch'], 'contents': 'foo'}])
			with replace_attr(vim, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda: 'DU', directory=path)):
				self.assertEqual(vim.branch(pl=pl, segment_info=segment_info),
						[{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch'], 'contents': 'foo'}])
				self.assertEqual(vim.branch(pl=pl, segment_info=segment_info, status_colors=True),
						[{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch_dirty', 'branch'], 'contents': 'foo'}])
开发者ID:DaneelOliwan,项目名称:dotfiles-vim,代码行数:13,代码来源:test_segments.py


注:本文中的tests.vim._with函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。