Example #1
0
def main():
	global test
	#count, data = self.db.query(query)
	l = Logger()
	
	l.start("Begin DataFetcher Self Test")

	db = statmon.datasource.MySQLDataSource(l,host='statmon.basis.is')

	test = TestA(db=db)
	#test = DataFetcher(db=db,logger=l)
	#l.show(test.getDatasets())

	l.end()
Example #2
0
def main():
	"""Unit tests for config.py"""
	from utils import Logger
	l = Logger()
	l.start('Starting Unit Tests for Config')

	l.start('config = Config()')
	global config
	config = Config()
	l.end()
	
	testReg(l,config,'root',description='Root Item')
	testGetValue(l,config,'root')
	testSetValue(l,config,'root',value='foo')
	testGetValue(l,config,'root',wanted='foo')

	testReg(l,config,'.root.sub1',description='Sub-Root Item 1')
	testGetValue(l,config,'.root.sub1')
	testSetValue(l,config,'.root.sub1',value='foo')
	testGetValue(l,config,'.root.sub1',wanted='foo')

	rootConfig = config.root
	testReg(l,rootConfig,'.sub2',description='Sub-Root Item 2')
	testGetValue(l,rootConfig,'.sub2')
	testSetValue(l,rootConfig,'.sub2',value='foo')
	testGetValue(l,rootConfig,'.sub2',wanted='foo')

	subConfig2 = rootConfig.sub2
	testReg(l,subConfig2,'.sub2sub',description='Sub-Sub-Root Item 1')
	testGetValue(l,subConfig2,'.sub2sub')
	testSetValue(l,subConfig2,'.sub2sub',value='foo')
	testGetValue(l,subConfig2,'.sub2sub',wanted='foo')

	typesConfig = rootConfig._get('.types',create=True)
	testReg(l,typesConfig,'.typeNoneType',description = 'Test Setting - None Type')
	testReg(l,typesConfig,'.typeStr',description = 'Test Setting - Str Type',default='Blabla')
	testReg(l,typesConfig,'.typeInt',description = 'Test Setting - Int Type',default=123)
	testReg(l,typesConfig,'.typeFloat',description = 'Test Setting - Float Type',default=1.23)
	testReg(l,typesConfig,'.typeBool',description = 'Test Setting - Bool Type',default=True)
	testReg(l,typesConfig,'.typeList',description = 'Test Setting - List Type',default=[1,'a',None])
	testReg(l,typesConfig,'.typeDict',description = 'Test Setting - Dict Type',default={'a':1,'b':'a','c':None})
	testReg(l,rootConfig,'.types',description = 'Test Types')

	global before
	before = config.getAll()

	l.start("""config.saveXML('config.xml')""")
	config.saveXML('config.xml')
	l.end()

	l.start('newConfig = Config()')
	newConfig = Config()
	l.end()

	l.start("""newConfig.loadXML('config.xml')""")
	newConfig.loadXML('config.xml')
	l.end()

	global after
	after = newConfig.getAll()

	newTypesConfig = newConfig.root.types
	testGetValue(l,newTypesConfig,'.typeNoneType')
	testGetValue(l,newTypesConfig,'.typeStr',wanted='Blabla')
	testGetValue(l,newTypesConfig,'.typeInt',wanted=123)
	testGetValue(l,newTypesConfig,'.typeFloat',wanted=1.23)
	testGetValue(l,newTypesConfig,'.typeBool',wanted=True)
	testGetValue(l,newTypesConfig,'.typeList',wanted=[1,'a',None])
	testGetValue(l,newTypesConfig,'.typeDict',wanted={'a':1,'b':'a','c':None})

	l.start("""newConfig.saveXML('newConfig.xml')""")
	newConfig.saveXML('newConfig.xml')
	l.end()

	l.start("""system('diff config.xml newConfig.xml')""")
	import os
	code = os.system('diff config.xml newConfig.xml')
	assert(code == 0)
	l.end('code = %d' % code)

	l.start("""system('rm -f config.xml newConfig.xml')""")
	import os
	code = os.system('rm -f config.xml newConfig.xml')
	assert(code == 0)
	l.end('code = %d' % code)

	l.end()