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


Python Preprocessor.process_content_with_dict方法代码示例

本文整理汇总了Python中Preprocessor.Preprocessor.process_content_with_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Preprocessor.process_content_with_dict方法的具体用法?Python Preprocessor.process_content_with_dict怎么用?Python Preprocessor.process_content_with_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Preprocessor.Preprocessor的用法示例。


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

示例1: TestPreprocessor

# 需要导入模块: from Preprocessor import Preprocessor [as 别名]
# 或者: from Preprocessor.Preprocessor import process_content_with_dict [as 别名]
class TestPreprocessor(unittest.TestCase):
	def setUp(self):
		cur_dir = os.path.dirname(os.path.realpath(__file__))
		self.tpl_dir = os.path.join(cur_dir,'..','UnitTests','test_templates')
		self.preprocessor = Preprocessor(self.tpl_dir)

	def process_content(self,content,dict,expected):
		actual = self.preprocessor.process_content_with_dict(content,dict)
		self.assertEqual(actual,expected)

	def test_ifs(self):
		dict = {'basic_key':'_trivial_', 'yes_key':True, 'no_key':False}
		self.process_content("basic%basic_key%basic",dict,"basic_trivial_basic")
		self.process_content("%if yes_key%%basic_key%%endif%",dict,"_trivial_")
		self.process_content("%if no_key%%basic_key%%endif%",dict,"")
		self.process_content("aa%if yes_key%%if no_key%%basic_key%%endif%%endif%bb",dict,"aabb")
		self.process_content("start %if non_existant_key%non_existant%endif% finish",dict,"start  finish")
		self.process_content("start %if non_existant_key%%if yes_key%%basic_key%%endif%%endif% finish",dict,"start  finish")
		self.process_content("start %if yes_key%yes%else%no%endif%",dict,"start yes")
		self.process_content("start %if no_key%yes%else%no%endif%",dict,"start no")
		self.process_content("start %if non_existant_key%yes%else%non_exist%endif%",dict,"start non_exist")

		self.process_content("%if yes_key%%if no_key%yes%else%no%endif%%endif%",dict,"no")
		self.process_content("%if no_key% hello1 %else% %if yes_key% hello2 %else% hello3 %endif% %endif%",dict,"  hello2  ")


	def test_includes(self):
		content = self.preprocessor.process_tpl_name_with_dict('test_include',{'a':True,'aa':'a'})
		self.assertEqual(content,'<html><body> a </body></html>')
开发者ID:Hyacinth,项目名称:Finch,代码行数:31,代码来源:TestPreprocessor.py


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