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


Python Log.write方法代码示例

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


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

示例1: TestObject

# 需要导入模块: from logger import Log [as 别名]
# 或者: from logger.Log import write [as 别名]
class TestObject():
	def __init__(self, config='tests.conf'):
		'''
			Class constructor, takes config filename. Also checks command-line parameters:
			-b, --browser
			-c, --config
			-l, --level
			-u, --url
			-d, --debug -- takes no parameter, sets log level to debug
		'''
		options,operands = getopt.getopt(sys.argv[1:], 'b:c:l:u:d', ['browser=', 'config=', 'level=', 'url=', 'debug'])
		for name, value in options:
			if name in ('-c', '--config'):
				if os.path.exists(value):
					config = value
		
		self.log = Log(config)
		cnf = ConfigParser.ConfigParser()
		cnf.read(config)

		self.login = cnf.get('net-creds', 'login')
		self.password = cnf.get('net-creds', 'passwd')
		self.url = cnf.get('net-creds', 'server')
		self.browser = cnf.get('browser', 'browser')
		self.proxy_host = cnf.get('proxy', 'proxy_host')
		self.proxy_port = cnf.get('proxy', 'proxy_port')
		self.aslogin = cnf.get('user2', 'login')
		self.aspwd = cnf.get('user2', 'passwd')

		for name, value in options:
			value = value.strip()
			if name in ('-d', '--debug'):
				self.log.level = 'debug'
			elif name in ('-u', '--url'):
				self.url = value or self.url
			elif name in ('-b', '--browser'):
				self.browser = value or self.browser
			elif name in ('-l', '--level'):
				self.log.level = value or self.log.level

		self.log.write('debug', 'starting instance with parameters:')
		self.log.write('debug', 'config: %s' % config)
		self.log.write('debug', 'login: %s' % self.login)
		self.log.write('debug', 'password: %s' % self.password)
		self.log.write('debug', 'url: %s' % self.url)
		self.log.write('debug', 'browser: %s' % self.browser)
		self.log.write('debug', 'proxy_host: %s' % self.proxy_host)
		self.log.write('debug', 'proxy_port: %s' % self.proxy_port)

		self.driver = get_browser(self.browser) # FIXME :: proxy
		self.driver.get(self.url)
		self.links = []
		self.log.write('debug', 'initialized self.links')
		self.edits = []
		self.log.write('debug', 'initialized self.edits')
		self.results = []
		self.log.write('debug', 'initialized self.results')
		self.errors = []
		self.log.write('debug', 'initialized self.errors')
		self.info = {}
		self.log.write('debug', 'initialized self.info')

	def find_stuff(self, stuff):
		'''
		Finds something using the site's search engine. Takes a text fragment to search for
		'''
		try:
			search = self.driver.find_element_by_name('q')
		except NoSuchElementException:
			self.log.write('error', 'no search form, aborting right now')
			return False
		search.clear()
		search.send_keys(stuff)
		search.submit()
		try:
			WebDriverWait(self.driver, 10).until(lambda driver : self.check_div('global-search-result'))
		except TimeoutException:
			self.log.write('error', 'timeout waiting for shit to load')
			return False

		return True

	def json_info(self, id_=None, entity='person'):
		'''
		Takes the site's json info (aka common_data), takes id_ of entity and entity type ('person' or 'company')
		'''
		url = self.driver.current_url
		if id_ is None:
			self.go('%s/settings/s' % self.url)
		elif entity == 'company':
			self.go('%s/profile/i/%s' % (self.url, id_))
		elif entity == 'person':
			self.go('%s/person/%s/s' % (self.url, id_))
		else:
			return None
		
		text = self.get_value('//pre', by='xpath')
		self.go(url)
		return json.loads(text)

#.........这里部分代码省略.........
开发者ID:part1zano,项目名称:autotest,代码行数:103,代码来源:testcase.py


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