class TestOpenCloseDS_basic(unittest.TestCase): def setUp(self): print "\n Open / close the data source for DS_basic" self.ds = None self.ds = DS_basic("Test") def tearDown(self): pass def runTest(self): # Low level test, opening and closing of the data source if single_test: print " Test opening / closing of data source (low level)" try: self.ds._open_data_source([]) except: print " Low level method _open_data_source() raised exception" try: self.ds._close_data_source() except: print " Low level method _close_data_source() raised exception" # Function test for open() and close() method if single_test: print " Open method for the DS_basic object" self.ds.open([]) assert self.ds.ds_status == "open", "Method open() could not open the data source" self.ds.close() assert self.ds.ds_status == "closed", "Method close() could not close the data source"
class TestNextDS_basic(unittest.TestCase): def setUp(self): print "\n Get next record from DS_basic" self.ds = None self.ds = DS_basic("Test") self.ds.open() def tearDown(self): try: self.ds.close() except: pass def runTest(self): # Low level test, get the next record with _get_next_record method if single_test: print " Test _get_next_record (Low level)" rec = None procBytes = self.ds.ds_processedBytes try: rec = self.ds._get_next_record() except: print " Low level method _get_next_record() raised exception" assert rec != None, "Method _get_next_record did not return a record" assert rec.__class__.__name__ == "dict", "Method _get_next_record did not return a dictionary as record" assert ( self.ds.ds_processedBytes != procBytes ), "Method _get_next_record did not change number of processed Bytes" if single_test: print " Test next() method - single shot" rec = None try: rec = self.ds.next() except: print " Method next() raised exception" assert rec != None, "Method next() did not return a record" assert rec.__class__.__name__ == "dict", "Method next() did not return a dictionary as record" assert self.ds.ds_numRows == 1, "Method next() did not count number of Rows provided" assert self.ds.ds_processedBytes == 44, "Counting of processed Bytes did not work properly" if single_test: print " Test next() method - repeated calls" try: count = 0 while count < 10: rec = self.ds.next() assert rec != None, "Method next() did not return a record" assert rec.__class__.__name__ == "dict", "Method next() did not return a dictionary as record" count += 1 except: print " Test next() method - repeated calls raised exception" assert self.ds.ds_numRows == 11, "Method next() did not count number of Rows provided" # print self.ds.ds_processedBytes assert self.ds.ds_processedBytes == 264, "Counting of processed Bytes did not work properly"