class Module01Test(unittest.TestCase):
    """
	Use this to setup your tests. This is where you may want to load configuration
	information (if needed), initialize class-scoped variables, create class-scoped
	instances of complex objects, initialize any requisite connections, etc.
	"""
    def setUp(self):
        self.c = SystemCpuUtilTask()
        self.m = SystemMemUtilTask()

    """
	Use this to tear down any allocated resources after your tests are complete. This
	is where you may want to release connections, zero out any long-term data, etc.
	"""

    def tearDown(self):
        pass

    """
	getDataFromSensor() function returns a float value representing the on-demand CPU utilization
	passing values will be anything between 0.0 and 100.0	
	"""

    def testSystemCpuUtil(self):
        assert self.c.getDataFromSensor() > 0 and self.c.getDataFromSensor(
        ) < 100

    """
	getDataFromSensor() function returns a float value representing the on-demand Memory utilization
	passing values will be anything between 0.0 and 100.0	
	"""

    def testSystemMemUtil(self):
        assert self.m.getDataFromSensor() > 0 and self.m.getDataFromSensor(
        ) < 100
 def util(self):
     for i in range(10):                    #loop for calling function 10 times to 10 the 10 log outputs.
         sysCpu=SystemCpuUtilTask();         #object of SystemCpuUtilTask is created 
         cpuUtil=sysCpu.getDataFromSensor()  #function is called
         sysMem=SystemMemUtilTask()          #object of SystemMemUtilTask is created 
         memUtil=sysMem.getDataFromSensor()  #function is called
         logging.basicConfig(level=logging.INFO,format='%(asctime)s:%(levelname)s:%(message)s')
         data='CPU Utilization='+str(cpuUtil)
         logging.info(data)                  #CPU data is logged
         data='Memory Utilization='+str(memUtil)
         logging.info(data)                  # Memory data is logged.
 def run(self):
     while True:
         if self.enableAdaptor:
             c = SystemCpuUtilTask()
             cpuUtil = c.getDataFromSensor()
             m = SystemMemUtilTask()
             memUtil = m.getDataFromSensor()
             perfData1 = 'CPU Utilization=' + str(cpuUtil) 
             perfData2 ='Memory Utilization=' +str(memUtil)
             
             logging.info(perfData1)
             logging.info(perfData2)
             sleep(self.rateInSec)
示例#4
0
 def run(self):
     count = 10
     while count > 0:
         sysCpuUtilTask = SystemCpuUtilTask()
         cpuUtil = sysCpuUtilTask.getDataFromSensor()
         sysMemUtilTask = SystemMemUtilTask()
         memUtil = sysMemUtilTask.getDataFromSensor()
         perfData = 'CPU Utilization=' + str(cpuUtil)
         logging.info(perfData)
         perfData = "Memory Utilization=" + str(memUtil)
         logging.info(perfData)
         time.sleep(5)
         count = count - 1
示例#5
0
class Module01Test(unittest.TestCase):
	cpuUtil=SystemCpuUtilTask()
	
	'''
	 This function tests the outcomes of Memory Utilization.
	 1. Case 1 is that it will check for the output to be of data type float.
	 2. Case 2 is that it will check for the output should be within the range 0.0 to 100.0
	 test case will pass if the condition is true.
	'''
	
	
	def testMemUtil(self):
		memUtil=SystemMemUtilTask();
		self.assertTrue(isinstance(memUtil.getDataFromSensor(),float),"Float Value")
		self.assertTrue(memUtil.getDataFromSensor()>=0.0 and memUtil.getDataFromSensor()<=100.0,"in range")
	
	"""
	This function tests the outcomes of CPU Utilization.
	1. Case 1 is that it will check for the output to be of data type float.
	2. Case 2 is that it will check for the output should be within the range 0.0 to 100.0
	test case will pass if the condition is true.
	"""
	def testCpuUtil(self):
		cpuUtil=SystemCpuUtilTask();
		self.assertTrue(isinstance(cpuUtil.getDataFromSensor(),float),"Float value")
		self.assertTrue(cpuUtil.getDataFromSensor()>=0.0 and cpuUtil.getDataFromSensor()<=100.0,"in range")
示例#6
0
	def testCpuUtil(self):
		cpuUtil=SystemCpuUtilTask();
		self.assertTrue(isinstance(cpuUtil.getDataFromSensor(),float),"Float value")
		self.assertTrue(cpuUtil.getDataFromSensor()>=0.0 and cpuUtil.getDataFromSensor()<=100.0,"in range")
示例#7
0
 def testCpurate(self):
     cpurate = SystemCpuUtilTask.getDataFromSensor(self)
     assert cpurate > 0.0 and cpurate < 100.0
 def setUp(self):
     self.c = SystemCpuUtilTask()
     self.m = SystemMemUtilTask()
示例#9
0
	def testSystemCpuUtilTask(self):

		cpuTestData = SystemCpuUtilTask.getDataFromSensor(self)
		self.assertTrue(isinstance(cpuTestData, float), 'CPU Utilization is not a float type number') 	#Default Case
		self.assertTrue(0 <= cpuTestData , 'CPU Usage dropped below 0%') 								#Exception Case 1
		self.assertTrue(cpuTestData <= 100 , 'CPU Usage shot-up above 100%') 							#Exception Case 2