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


Python lib.replace_item函数代码示例

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


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

示例1: test_reload_unexistent

	def test_reload_unexistent(self):
		with get_powerline(run_once=False) as p:
			with replace_item(globals(), 'config', deepcopy(config)):
				self.assertEqual(p.render(), '<1 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
				self.assertAccessEvents('config', 'colors', 'colorschemes/test/default', 'themes/test/default')

				config['config']['ext']['test']['colorscheme'] = 'nonexistentraise'
				add_watcher_events(p, 'config')
				# It may appear that p.logger._pop_msgs() is called after given 
				# exception is added to the mesagges, but before config_loader 
				# exception was added (this one: 
				# “exception:test:config_loader:Error while running condition 
				# function for key colorschemes/test/nonexistentraise: 
				# fcf:colorschemes/test/nonexistentraise”).
				# sleep(0.1)
				self.assertEqual(p.render(), '<1 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
				self.assertAccessEvents('config')
				self.assertIn('exception:test:powerline:Failed to create renderer: fcf:colorschemes/test/nonexistentraise', p.logger._pop_msgs())

				config['colorschemes/test/nonexistentraise'] = {
					'groups': {
						"str1": {"fg": "col1", "bg": "col3", "attr": ["bold"]},
						"str2": {"fg": "col2", "bg": "col4", "attr": ["underline"]},
					},
				}
				while not p._will_create_renderer():
					sleep(0.000001)
				self.assertEqual(p.render(), '<1 3 1> s<3 4 False>>><2 4 4>g<4 False False>>><None None None>')
				self.assertAccessEvents('colorschemes/test/nonexistentraise')
				self.assertEqual(p.logger._pop_msgs(), [])
		pop_events()
开发者ID:Aitem,项目名称:VIM,代码行数:31,代码来源:test_config_reload.py

示例2: test_reload_main

	def test_reload_main(self):
		with get_powerline(run_once=False) as p:
			with replace_item(globals(), 'config', deepcopy(config)):
				self.assertEqual(p.render(), '<1 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
				self.assertAccessEvents('config', 'colors', 'colorschemes/default', 'colorschemes/test/__main__', 'colorschemes/test/default', 'themes/test/default')

				config['config']['common']['spaces'] = 1
				add_watcher_events(p, 'config')
				self.assertEqual(p.render(), '<1 2 1> s <2 4 False>>><3 4 4>g <4 False False>>><None None None>')
				self.assertAccessEvents('config')
				self.assertEqual(p.logger._pop_msgs(), [])

				config['config']['ext']['test']['theme'] = 'nonexistent'
				add_watcher_events(p, 'config')
				self.assertEqual(p.render(), '<1 2 1> s <2 4 False>>><3 4 4>g <4 False False>>><None None None>')
				self.assertAccessEvents('config', 'themes/test/nonexistent')
				# It should normally handle file missing error
				self.assertEqual(p.logger._pop_msgs(), ['exception:test:powerline:Failed to create renderer: themes/test/nonexistent'])

				config['config']['ext']['test']['theme'] = 'default'
				add_watcher_events(p, 'config')
				self.assertEqual(p.render(), '<1 2 1> s <2 4 False>>><3 4 4>g <4 False False>>><None None None>')
				self.assertAccessEvents('config', 'themes/test/default')
				self.assertEqual(p.logger._pop_msgs(), [])

				config['config']['ext']['test']['colorscheme'] = 'nonexistent'
				add_watcher_events(p, 'config')
				self.assertEqual(p.render(), '<1 2 1> s <2 4 False>>><3 4 4>g <4 False False>>><None None None>')
				self.assertAccessEvents('config', 'colorschemes/nonexistent', 'colorschemes/test/__main__', 'colorschemes/test/nonexistent')
				# It should normally handle file missing error
				self.assertEqual(p.logger._pop_msgs(), [
					'exception:test:powerline:Failed to load colorscheme: colorschemes/nonexistent',
					'exception:test:powerline:Failed to load colorscheme: colorschemes/test/__main__',
					'exception:test:powerline:Failed to load colorscheme: colorschemes/test/nonexistent',
					'exception:test:powerline:Failed to create renderer: colorschemes/test/nonexistent'
				])

				config['config']['ext']['test']['colorscheme'] = '2'
				add_watcher_events(p, 'config')
				self.assertEqual(p.render(), '<2 3 1> s <3 4 False>>><1 4 4>g <4 False False>>><None None None>')
				self.assertAccessEvents('config', 'colorschemes/2', 'colorschemes/test/__main__', 'colorschemes/test/2')
				self.assertEqual(p.logger._pop_msgs(), [])

				config['config']['ext']['test']['theme'] = '2'
				add_watcher_events(p, 'config')
				self.assertEqual(p.render(), '<2 3 1> t <3 4 False>>><1 4 4>b <4 False False>>><None None None>')
				self.assertAccessEvents('config', 'themes/test/2')
				self.assertEqual(p.logger._pop_msgs(), [])

				self.assertEqual(p.renderer.local_themes, None)
				config['config']['ext']['test']['local_themes'] = 'something'
				add_watcher_events(p, 'config')
				self.assertEqual(p.render(), '<2 3 1> t <3 4 False>>><1 4 4>b <4 False False>>><None None None>')
				self.assertAccessEvents('config')
				self.assertEqual(p.logger._pop_msgs(), [])
				self.assertEqual(p.renderer.local_themes, 'something')
		pop_events()
开发者ID:liston,项目名称:Myvimrc,代码行数:57,代码来源:test_config_reload.py

示例3: test_group_redirects_only_test_default

	def test_group_redirects_only_test_default(self, p):
		with replace_item(globals(), 'config', deepcopy(config)):
			del config['colorschemes/default']
			del config['colorschemes/test/__main__']
			config['themes/test/default']['segments'] = {
				'left': [
					highlighted_string('s', 'str1', draw_hard_divider=False),
				],
				'right': [],
			}
			self.assertRenderEqual(p, '{121} s{--}')
开发者ID:liston,项目名称:Myvimrc,代码行数:11,代码来源:test_configuration.py

示例4: test_no_attributes

    def test_no_attributes(self, p, config):
        def m1(divider=',', **kwargs):
            return divider.join(kwargs.keys()) + divider

        config['themes/test/default']['segments'] = {
            'left': [{
                'function': 'bar.m1'
            }]
        }
        with replace_item(sys.modules, 'bar', Args(m1=m1)):
            self.assertRenderEqual(p, '{56} pl,{6-}>>{--}')
开发者ID:BrianODell,项目名称:dotfiles,代码行数:11,代码来源:test_configuration.py

示例5: test_group_redirects_no_top_default

	def test_group_redirects_no_top_default(self, p):
		with replace_item(globals(), 'config', deepcopy(config)):
			del config['colorschemes/default']
			config['themes/test/default']['segments'] = {
				'left': [
					highlighted_string('c', 'd3', draw_soft_divider=False),
					highlighted_string('C', 'm3', draw_hard_divider=False),
				],
				'right': [],
			}
			self.assertRenderEqual(p, '{1112} c{1112}C{--}')
开发者ID:liston,项目名称:Myvimrc,代码行数:11,代码来源:test_configuration.py

示例6: test_reload_theme

	def test_reload_theme(self):
		with get_powerline(run_once=False) as p:
			with replace_item(globals(), 'config', deepcopy(config)):
				self.assertEqual(p.render(), '<1 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
				self.assertAccessEvents('config', 'colors', 'colorschemes/default', 'colorschemes/test/__main__', 'colorschemes/test/default', 'themes/test/default')

				config['themes/test/default']['segments']['left'][0]['contents'] = 'col3'
				add_watcher_events(p, 'themes/test/default')
				self.assertEqual(p.render(), '<1 2 1> col3<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
				self.assertAccessEvents('themes/test/default')
				self.assertEqual(p.logger._pop_msgs(), [])
		pop_events()
开发者ID:liston,项目名称:Myvimrc,代码行数:12,代码来源:test_config_reload.py

示例7: test_group_redirects_no_main

	def test_group_redirects_no_main(self, p):
		with replace_item(globals(), 'config', deepcopy(config)):
			del config['colorschemes/test/__main__']
			config['themes/test/default']['segments'] = {
				'left': [
					highlighted_string('a', 'd1', draw_hard_divider=False),
					highlighted_string('1', 'g1', draw_hard_divider=False),
					highlighted_string('2', 'g2', draw_hard_divider=False),
					highlighted_string('3', 'g3', draw_hard_divider=False),
				],
				'right': [],
			}
			self.assertRenderEqual(p, '{78} a{56}1{78}2{910}3{--}')
开发者ID:liston,项目名称:Myvimrc,代码行数:13,代码来源:test_configuration.py

示例8: test_group_redirects_only_main

	def test_group_redirects_only_main(self, p):
		with replace_item(globals(), 'config', deepcopy(config)):
			del config['colorschemes/default']
			del config['colorschemes/test/default']
			config['themes/test/default']['segments'] = {
				'left': [
					highlighted_string('C', 'm3', draw_hard_divider=False),
				],
				'right': [],
			}
			# Powerline is not able to work without default colorscheme 
			# somewhere, thus it will output error string
			self.assertRenderEqual(p, 'colorschemes/test/default')
开发者ID:liston,项目名称:Myvimrc,代码行数:13,代码来源:test_configuration.py

示例9: test_exinclude_function

    def test_exinclude_function(self, p, config):
        config['themes/test/default']['segments'] = {
            'left': [
                highlighted_string('s1', 'g1', exclude_function='mod.foo'),
                highlighted_string(
                    's2',
                    'g1',
                    exclude_function='mod.foo',
                    include_function='mod.bar'),
                highlighted_string('s3', 'g1', include_function='mod.bar'),
            ]
        }
        launched = set()
        fool = [None]
        barl = [None]

        def foo(*args, **kwargs):
            launched.add('foo')
            self.assertEqual(
                set(kwargs.keys()), set(('pl', 'segment_info', 'mode')))
            self.assertEqual(args, ())
            return fool[0]

        def bar(*args, **kwargs):
            launched.add('bar')
            self.assertEqual(
                set(kwargs.keys()), set(('pl', 'segment_info', 'mode')))
            self.assertEqual(args, ())
            return barl[0]

        with replace_item(sys.modules, 'mod', Args(foo=foo, bar=bar)):
            fool[0] = True
            barl[0] = True
            self.assertRenderEqual(p, '{56} s3{6-}>>{--}')
            self.assertEqual(launched, set(('foo', 'bar')))

            fool[0] = False
            barl[0] = True
            self.assertRenderEqual(p,
                                   '{56} s1{56}>{56}s2{56}>{56}s3{6-}>>{--}')
            self.assertEqual(launched, set(('foo', 'bar')))

            fool[0] = False
            barl[0] = False
            self.assertRenderEqual(p, '{56} s1{6-}>>{--}')
            self.assertEqual(launched, set(('foo', 'bar')))

            fool[0] = True
            barl[0] = False
            self.assertRenderEqual(p, '{--}')
            self.assertEqual(launched, set(('foo', 'bar')))
开发者ID:BrianODell,项目名称:dotfiles,代码行数:51,代码来源:test_configuration.py

示例10: test_run_once_no_theme_reload

	def test_run_once_no_theme_reload(self):
		with replace_item(globals(), 'config', deepcopy(config)):
			config['config']['common']['interval'] = None
			with get_powerline(run_once=True) as p:
				self.assertEqual(p.render(), '<1 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
				self.assertAccessEvents('config', 'colors', 'colorschemes/test/default', 'themes/test/default')

				config['themes/test/default']['segments']['left'][0]['contents'] = 'col3'
				add_watcher_events(p, 'themes/test/default', wait=False)
				self.assertEqual(p.render(), '<1 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
				self.assertAccessEvents()
				self.assertEqual(p.logger._pop_msgs(), [])
				self.assertEqual(p._watcher._calls, [])
		pop_events()
开发者ID:Aitem,项目名称:VIM,代码行数:14,代码来源:test_config_reload.py

示例11: test_noreload

	def test_noreload(self):
		with get_powerline(run_once=True) as p:
			with replace_item(globals(), 'config', deepcopy(config)):
				self.assertEqual(p.render(), '<1 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
				self.assertAccessEvents('config', 'colors', 'colorschemes/default', 'colorschemes/test/__main__', 'colorschemes/test/default', 'themes/test/default')
				config['config']['common']['spaces'] = 1
				add_watcher_events(p, 'config', wait=False, interval=0.05)
				# When running once thread should not start
				self.assertEqual(p.render(), '<1 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
				self.assertAccessEvents()
				self.assertEqual(p.logger._pop_msgs(), [])
		# Without the following assertion test_reload_colors may fail for 
		# unknown reason (with AssertionError telling about “config” accessed 
		# one more time then needed)
		pop_events()
开发者ID:liston,项目名称:Myvimrc,代码行数:15,代码来源:test_config_reload.py

示例12: test_truncate

    def test_truncate(self, p, config):
        def m1(divider=',', **kwargs):
            return divider.join(kwargs.keys()) + divider

        def truncate(pl, amount, segment, **kwargs):
            return segment['contents'][:-amount]

        m1.truncate = truncate
        config['themes/test/default']['segments'] = {
            'left': [{
                'function': 'bar.m1'
            }]
        }
        with replace_item(sys.modules, 'bar', Args(m1=m1)):
            self.assertRenderEqual(p, '{56} p{6-}>>{--}', width=4)
开发者ID:BrianODell,项目名称:dotfiles,代码行数:15,代码来源:test_configuration.py

示例13: test_expand

    def test_expand(self, p, config):
        def m1(divider=',', **kwargs):
            return divider.join(kwargs.keys()) + divider

        def expand(pl, amount, segment, **kwargs):
            return ('-' * amount) + segment['contents']

        m1.expand = expand
        config['themes/test/default']['segments'] = {
            'left': [{
                'function': 'bar.m1',
                'width': 'auto'
            }]
        }
        with replace_item(sys.modules, 'bar', Args(m1=m1)):
            self.assertRenderEqual(p, '{56} ----pl,{6-}>>{--}', width=10)
开发者ID:BrianODell,项目名称:dotfiles,代码行数:16,代码来源:test_configuration.py

示例14: test_group_redirects_no_test_default

	def test_group_redirects_no_test_default(self, p):
		with replace_item(globals(), 'config', deepcopy(config)):
			del config['colorschemes/test/default']
			config['themes/test/default']['segments'] = {
				'left': [
					highlighted_string('A', 'm1', draw_hard_divider=False),
					highlighted_string('B', 'm2', draw_hard_divider=False),
					highlighted_string('C', 'm3', draw_hard_divider=False),
					highlighted_string('1', 'g1', draw_hard_divider=False),
					highlighted_string('2', 'g2', draw_hard_divider=False),
					highlighted_string('3', 'g3', draw_hard_divider=False),
				],
				'right': [],
			}
			self.assertRenderEqual(p, '{56} A{910}B{1112}C{56}1{78}2{910}3{--}')
			self.assertEqual(p.logger._pop_msgs(), [])
开发者ID:wezhang,项目名称:vim-setup,代码行数:16,代码来源:test_configuration.py

示例15: test_group_redirects

	def test_group_redirects(self, p):
		with replace_item(globals(), 'config', deepcopy(config)):
			config['themes/test/default']['segments'] = {
				'left': [
					highlighted_string('a', 'd1', draw_hard_divider=False),
					highlighted_string('b', 'd2', draw_hard_divider=False),
					highlighted_string('c', 'd3', draw_hard_divider=False),
					highlighted_string('A', 'm1', draw_hard_divider=False),
					highlighted_string('B', 'm2', draw_hard_divider=False),
					highlighted_string('C', 'm3', draw_hard_divider=False),
					highlighted_string('1', 'g1', draw_hard_divider=False),
					highlighted_string('2', 'g2', draw_hard_divider=False),
					highlighted_string('3', 'g3', draw_hard_divider=False),
				],
				'right': [],
			}
			self.assertRenderEqual(p, '{78} a{910}b{1112}c{56}A{910}B{1112}C{56}1{78}2{910}3{--}')
开发者ID:liston,项目名称:Myvimrc,代码行数:17,代码来源:test_configuration.py


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