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


Python Messages.output方法代码示例

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


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

示例1: class

# 需要导入模块: from messages import Messages [as 别名]
# 或者: from messages.Messages import output [as 别名]
class Tdd:
	'''
	path - 
	newclass - create new class with every new method
	messages - output information messages which occurred during process of generation .py file
	configure - path to configuration of json file

	configure:
	construct - construct classes from testCase class(with name of class. For example:

	[code]
	class TestCalculator(unittest.TestCase):
		def setUp(self):
			self.calculator = Calculator()

		def test_multiply(self):
			self.assertEqual(self.calculator.multi(7,6), 42)
	[/code]
	In output .py file will be class Calculator with method multi

	Configuration can be for all classes or methdos and individual configuration

	'''
	def __init__(self, newclass=False, ismessages=False, comments=False, configure=None,\
		construct=None):
		self.configure = None
		if configure != None:
			self.configure = self._load_configure(configure)
		else:
			self.newclass = newclass
			self.comments = comments
			self.messages = Messages(ismessages)
			self.construct = construct

	def _load_configure(self, path):
		if path != None:
			with open(path) as f:
				return json.loads(f.read())

	def ast_parse(self, filename):
		""" 
			Parse TestCase classes with test cases and functions 
			for construct functions
		"""
		if not os.path.isfile(filename):
			raise Exception("File not found")
		validmethdos = ['setUp']
		fdata = open(filename, 'r')
		data = fdata.read()
		tree = ast.parse(data)
		result = {}
		imported = []
		#Create objects for 
		objects = {}
		for node in ast.walk(tree):
			if isinstance(node, ast.ClassDef):
				#If function with same name exist - report the message
				self._check_exist_function(node.name, result)
				result[node.name] = []
				for subdata in node.body:
					if isinstance(subdata, ast.FunctionDef):
						funcs = result[node.name]
						parse_result, checker = self._parse_inside_function(subdata.body, objects)
						if parse_result != None:
							objects.update(parse_result)
						#If function name not in fucs store with known functions
						if self.construct != True:
							""" If construct not in True, doesn't matter how many in checker """
							checker = 0
						if subdata.name not in funcs and checker == 0:
							cand_func = self._parse_test_function(subdata.name)
							#if cand_func return None
							#It is function from unittest
							if cand_func != None:
								result[node.name].append(cand_func)
							elif isinstance(subdata, ast.Assign):
								#In case with one function
								objects[subdata.body[0].targets[0].attr] = {'name':\
								subdata.body[0].value.func.id}
							elif subdata.name not in validmethdos:
								self.messages.error("During process of generation file, found error. Not valid TestCase file. method names should looks like test_name.",1)
								return ErrorOutput("Some error")
						else:
							self.messages.output("function {0} already exist in class {1}. Second function will not be generated.".\
								format(subdata.name, node.name))
						'''
							Parsing inside function to get expressions for create 
							classes and methods In the generated file
						'''
					if isinstance(subdata, ast.Expr):
						print("Some expression", subdata.value.s)
			if isinstance(node, ast.Import):
				imported += list(map(lambda x: 'import ' + x.name, 
					filter(lambda x: x.name != 'unittest', node.names)))
		fdata.close()
		return TddOutput(objects, imported, result)

	def _check_exist_function(self, funcname, store):
		if funcname in store:
			self.messages.output("function {0} already exist in store. New function with same name will be overwritten".\
#.........这里部分代码省略.........
开发者ID:saromanov,项目名称:pygentesto,代码行数:103,代码来源:tdd.py


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