00001
00002
00003
00004
00005 '''rtshell
00006
00007 Copyright (C) 2009-2010
00008 Geoffrey Biggs
00009 RT-Synthesis Research Group
00010 Intelligent Systems Research Institute,
00011 National Institute of Advanced Industrial Science and Technology (AIST),
00012 Japan
00013 All rights reserved.
00014 Licensed under the Eclipse Public License -v 1.0 (EPL)
00015 http://www.opensource.org/licenses/eclipse-1.0.txt
00016
00017 Unit tests for the log classes
00018
00019 '''
00020
00021
00022 import os
00023 import os.path
00024 import sys
00025 import unittest
00026
00027 import rtshell.ilog
00028 import rtshell.simpkl_log
00029
00030
00031 METADATA=[1, 'lot', 'of', ('meta', 'data')]
00032 TIMESTAMPS=[0.2, 0.5, 1, 1.3, 1.7, 2.001, 3.2, 3.3, 3.4, 5.3]
00033 DATA=['Val1', 'Value2', 'Entry 3', 'Data block 4', 'Value 5', 'Entry6',
00034 'Data 7', 'Val8', 'Entry 9', 'Val 10']
00035
00036
00037 VERBOSITY=False
00038
00039
00040
00041 class WriteBase():
00042 def setUp(self):
00043 self.log = rtshell.simpkl_log.SimplePickleLog(filename='test.log',
00044 mode='w', meta=METADATA, verbose=VERBOSITY)
00045
00046 def tearDown(self):
00047 self.log.close()
00048 if os.path.isfile(os.path.join(os.getcwd(), 'test.log')):
00049 os.remove(os.path.join(os.getcwd(), 'test.log'))
00050
00051
00052 class ReadBase(unittest.TestCase):
00053 def setUp(self):
00054 self.write_test_log()
00055 self.log = rtshell.simpkl_log.SimplePickleLog(filename='test.log',
00056 mode='r', meta=METADATA, verbose=VERBOSITY)
00057
00058 def tearDown(self):
00059 self.log.close()
00060 if os.path.isfile(os.path.join(os.getcwd(), 'test.log')):
00061 os.remove(os.path.join(os.getcwd(), 'test.log'))
00062
00063 def write_test_log(self):
00064 log = rtshell.simpkl_log.SimplePickleLog(filename='test.log', mode='w',
00065 meta=METADATA, verbose=VERBOSITY)
00066 for t, d in zip(TIMESTAMPS, DATA):
00067 log.write(t, d)
00068 log.close()
00069
00070
00071 class WriteTests(WriteBase):
00072 def test_write(self):
00073 if VERBOSITY:
00074 print >>sys.stderr, '===== write ====='
00075 for t, d in zip(TIMESTAMPS, DATA):
00076 self.log.write(t, d)
00077 if VERBOSITY:
00078 print >>sys.stderr, '===== ===== ====='
00079
00080
00081 class ReadTests(ReadBase):
00082 def test_read_whole_log(self):
00083 if VERBOSITY:
00084 print >>sys.stderr, '===== read_whole_log ====='
00085 for ii in range(10):
00086 entry = self.log.read()
00087 if not entry:
00088
00089 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00090 else:
00091 ind, ts, d = entry[0]
00092 self.assertEqual(ind, ii)
00093 self.assertEqual(ts, TIMESTAMPS[ii])
00094 self.assertEqual(d, DATA[ii])
00095 if not self.log.eof:
00096 self.assertEqual(self.log.pos, (ii + 1, TIMESTAMPS[ii + 1]))
00097 else:
00098 self.assertEqual(self.log.pos, (ii + 1, TIMESTAMPS[-1]))
00099 self.assert_(self.log.eof)
00100 if VERBOSITY:
00101 print >>sys.stderr, '===== ===== ====='
00102
00103 def test_get_start_at_start(self):
00104 if VERBOSITY:
00105 print >>sys.stderr, '===== get_start_at_start ====='
00106 self.assertEqual(self.log.start, (0, TIMESTAMPS[0]))
00107 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00108 ind, ts, d = self.log.read()[0]
00109 self.assertEqual(ind, 0)
00110 self.assertEqual(ts, TIMESTAMPS[0])
00111 self.assertEqual(d, DATA[0])
00112 self.assert_(not self.log.eof)
00113 if VERBOSITY:
00114 print >>sys.stderr, '===== ===== ====='
00115
00116 def test_get_start_at_mid(self):
00117 if VERBOSITY:
00118 print >>sys.stderr, '===== get_start_at_mid ====='
00119 for ii in range(5):
00120 self.log.read()
00121 self.assertEqual(self.log.start, (0, TIMESTAMPS[0]))
00122 self.assertEqual(self.log.pos, (5, TIMESTAMPS[5]))
00123 ind, ts, d = self.log.read()[0]
00124 self.assertEqual(ind, 5)
00125 self.assertEqual(ts, TIMESTAMPS[5])
00126 self.assertEqual(d, DATA[5])
00127 self.assert_(not self.log.eof)
00128 if VERBOSITY:
00129 print >>sys.stderr, '===== ===== ====='
00130
00131 def test_get_start_at_eof(self):
00132 if VERBOSITY:
00133 print >>sys.stderr, '===== get_start_at_eof ====='
00134 for ii in range(11):
00135 self.log.read()
00136 self.assertEqual(self.log.start, (0, TIMESTAMPS[0]))
00137 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00138 self.assertEqual(self.log.read(), [])
00139 self.assert_(self.log.eof)
00140 if VERBOSITY:
00141 print >>sys.stderr, '===== ===== ====='
00142
00143 def test_get_end_at_start(self):
00144 if VERBOSITY:
00145 print >>sys.stderr, '===== get_end_at_start ====='
00146 self.assertEqual(self.log.end, (9, TIMESTAMPS[-1]))
00147 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00148 ind, ts, d = self.log.read()[0]
00149 self.assertEqual(ind, 0)
00150 self.assertEqual(ts, TIMESTAMPS[0])
00151 self.assertEqual(d, DATA[0])
00152 self.assert_(not self.log.eof)
00153 if VERBOSITY:
00154 print >>sys.stderr, '===== ===== ====='
00155
00156 def test_get_end_at_mid(self):
00157 if VERBOSITY:
00158 print >>sys.stderr, '===== get_end_at_mid ====='
00159 for ii in range(5):
00160 self.log.read()
00161 self.assertEqual(self.log.end, (9, TIMESTAMPS[-1]))
00162 self.assertEqual(self.log.pos, (5, TIMESTAMPS[5]))
00163 ind, ts, d = self.log.read()[0]
00164 self.assertEqual(ind, 5)
00165 self.assertEqual(ts, TIMESTAMPS[5])
00166 self.assertEqual(d, DATA[5])
00167 self.assert_(not self.log.eof)
00168 if VERBOSITY:
00169 print >>sys.stderr, '===== ===== ====='
00170
00171 def test_get_end_at_eof(self):
00172 if VERBOSITY:
00173 print >>sys.stderr, '===== get_end_at_eof ====='
00174 for ii in range(11):
00175 self.log.read()
00176 self.assertEqual(self.log.end, (9, TIMESTAMPS[9]))
00177 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00178 self.assertEqual(self.log.read(), [])
00179 self.assert_(self.log.eof)
00180 if VERBOSITY:
00181 print >>sys.stderr, '===== ===== ====='
00182
00183 def test_read_eof(self):
00184 if VERBOSITY:
00185 print >>sys.stderr, '===== read_eof ====='
00186 for ii in range(10):
00187 self.log.read()
00188 self.assert_(self.log.eof)
00189 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00190 self.assertEqual(self.log.read(), [])
00191 self.assert_(self.log.eof)
00192 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00193 if VERBOSITY:
00194 print >>sys.stderr, '===== ===== ====='
00195
00196 def test_read_num_start_start(self):
00197 if VERBOSITY:
00198 print >>sys.stderr, '===== read_num_start_mid ====='
00199 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00200 self.assertEqual([], self.log.read(number=0))
00201 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00202 self.assert_(not self.log.eof)
00203 if VERBOSITY:
00204 print >>sys.stderr, '===== ===== ====='
00205
00206 def test_read_num_start_mid(self):
00207 if VERBOSITY:
00208 print >>sys.stderr, '===== read_num_start_mid ====='
00209 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00210 d = self.log.read(number=4)
00211 self.assertEqual(4, len(d))
00212 for ii in range(4):
00213 self.assertEqual(d[ii][0], ii)
00214 self.assertEqual(d[ii][1], TIMESTAMPS[ii])
00215 self.assertEqual(d[ii][2], DATA[ii])
00216 self.assertEqual(self.log.pos, (4, TIMESTAMPS[4]))
00217 self.assert_(not self.log.eof)
00218 if VERBOSITY:
00219 print >>sys.stderr, '===== ===== ====='
00220
00221 def test_read_num_start_end(self):
00222 if VERBOSITY:
00223 print >>sys.stderr, '===== read_num_start_mid ====='
00224 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00225 d = self.log.read(number=10)
00226 self.assertEqual(10, len(d))
00227 for ii in range(10):
00228 self.assertEqual(d[ii][0], ii)
00229 self.assertEqual(d[ii][1], TIMESTAMPS[ii])
00230 self.assertEqual(d[ii][2], DATA[ii])
00231 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00232 self.assert_(self.log.eof)
00233 if VERBOSITY:
00234 print >>sys.stderr, '===== ===== ====='
00235
00236 def test_read_num_start_eof(self):
00237 if VERBOSITY:
00238 print >>sys.stderr, '===== read_num_start_mid ====='
00239 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00240 d = self.log.read(number=11)
00241 self.assertEqual(10, len(d))
00242 for ii in range(10):
00243 self.assertEqual(d[ii][0], ii)
00244 self.assertEqual(d[ii][1], TIMESTAMPS[ii])
00245 self.assertEqual(d[ii][2], DATA[ii])
00246 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00247 self.assert_(self.log.eof)
00248 if VERBOSITY:
00249 print >>sys.stderr, '===== ===== ====='
00250
00251 def test_read_num_mid_start(self):
00252 if VERBOSITY:
00253 print >>sys.stderr, '===== read_num_mid_start ====='
00254 for ii in range(3):
00255 self.log.read()
00256 self.assertEqual(self.log.pos, (3, TIMESTAMPS[3]))
00257 self.assertRaises(ValueError, self.log.read, number=-1)
00258 self.assert_(not self.log.eof)
00259 if VERBOSITY:
00260 print >>sys.stderr, '===== ===== ====='
00261
00262 def test_read_num_mid_mid(self):
00263 if VERBOSITY:
00264 print >>sys.stderr, '===== read_num_mid_mid ====='
00265 for ii in range(3):
00266 self.log.read()
00267 self.assertEqual(self.log.pos, (3, TIMESTAMPS[3]))
00268 d = self.log.read(number=4)
00269 self.assertEqual(4, len(d))
00270 for ii in range(4):
00271 self.assertEqual(d[ii][0], ii + 3)
00272 self.assertEqual(d[ii][1], TIMESTAMPS[ii + 3])
00273 self.assertEqual(d[ii][2], DATA[ii + 3])
00274 self.assertEqual(self.log.pos, (7, TIMESTAMPS[7]))
00275 self.assert_(not self.log.eof)
00276 if VERBOSITY:
00277 print >>sys.stderr, '===== ===== ====='
00278
00279 def test_read_num_mid_end(self):
00280 if VERBOSITY:
00281 print >>sys.stderr, '===== read_num_mid_end ====='
00282 for ii in range(3):
00283 self.log.read()
00284 self.assertEqual(self.log.pos, (3, TIMESTAMPS[3]))
00285 d = self.log.read(number=7)
00286 self.assertEqual(7, len(d))
00287 for ii in range(7):
00288 self.assertEqual(d[ii][0], ii + 3)
00289 self.assertEqual(d[ii][1], TIMESTAMPS[ii + 3])
00290 self.assertEqual(d[ii][2], DATA[ii + 3])
00291 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00292 self.assert_(self.log.eof)
00293 if VERBOSITY:
00294 print >>sys.stderr, '===== ===== ====='
00295
00296 def test_read_num_mid_eof(self):
00297 if VERBOSITY:
00298 print >>sys.stderr, '===== read_num_mid_eof ====='
00299 for ii in range(3):
00300 self.log.read()
00301 self.assertEqual(self.log.pos, (3, TIMESTAMPS[3]))
00302 d = self.log.read(number=8)
00303 self.assertEqual(7, len(d))
00304 for ii in range(7):
00305 self.assertEqual(d[ii][0], ii + 3)
00306 self.assertEqual(d[ii][1], TIMESTAMPS[ii + 3])
00307 self.assertEqual(d[ii][2], DATA[ii + 3])
00308 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00309 self.assert_(self.log.eof)
00310 if VERBOSITY:
00311 print >>sys.stderr, '===== ===== ====='
00312
00313 def test_read_num_end_eof(self):
00314 if VERBOSITY:
00315 print >>sys.stderr, '===== read_num_end_eof ====='
00316 for ii in range(10):
00317 self.log.read()
00318 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00319 self.assertEqual([], self.log.read(number=2))
00320 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00321 self.assert_(self.log.eof)
00322 if VERBOSITY:
00323 print >>sys.stderr, '===== ===== ====='
00324
00325 def test_read_ts_start_start(self):
00326 if VERBOSITY:
00327 print >>sys.stderr, '===== read_ts_start_mid ====='
00328 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00329 self.assertEqual([], self.log.read(timestamp=0.1))
00330 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00331 d = self.log.read(timestamp=0.2)
00332 self.assertEqual(d[0][0], 0)
00333 self.assertEqual(d[0][1], TIMESTAMPS[0])
00334 self.assertEqual(d[0][2], DATA[0])
00335 self.assertEqual(self.log.pos, (1, TIMESTAMPS[1]))
00336 self.assert_(not self.log.eof)
00337 if VERBOSITY:
00338 print >>sys.stderr, '===== ===== ====='
00339
00340 def test_read_ts_start_mid(self):
00341 if VERBOSITY:
00342 print >>sys.stderr, '===== read_ts_start_mid ====='
00343 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00344 d = self.log.read(timestamp=1.3)
00345 self.assertEqual(4, len(d))
00346 for ii in range(4):
00347 self.assertEqual(d[ii][0], ii)
00348 self.assertEqual(d[ii][1], TIMESTAMPS[ii])
00349 self.assertEqual(d[ii][2], DATA[ii])
00350 self.assertEqual(self.log.pos, (4, TIMESTAMPS[4]))
00351 self.assert_(not self.log.eof)
00352 if VERBOSITY:
00353 print >>sys.stderr, '===== ===== ====='
00354
00355 def test_read_ts_start_mid_between(self):
00356 if VERBOSITY:
00357 print >>sys.stderr, '===== read_ts_start_mid_between ====='
00358 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00359 d = self.log.read(timestamp=1.45)
00360 self.assertEqual(4, len(d))
00361 for ii in range(4):
00362 self.assertEqual(d[ii][0], ii)
00363 self.assertEqual(d[ii][1], TIMESTAMPS[ii])
00364 self.assertEqual(d[ii][2], DATA[ii])
00365 self.assertEqual(self.log.pos, (4, TIMESTAMPS[4]))
00366 self.assert_(not self.log.eof)
00367 if VERBOSITY:
00368 print >>sys.stderr, '===== ===== ====='
00369
00370 def test_read_ts_start_end(self):
00371 if VERBOSITY:
00372 print >>sys.stderr, '===== read_ts_start_mid ====='
00373 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00374 d = self.log.read(timestamp=5.3)
00375 self.assertEqual(10, len(d))
00376 for ii in range(10):
00377 self.assertEqual(d[ii][0], ii)
00378 self.assertEqual(d[ii][1], TIMESTAMPS[ii])
00379 self.assertEqual(d[ii][2], DATA[ii])
00380 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00381 self.assert_(self.log.eof)
00382 if VERBOSITY:
00383 print >>sys.stderr, '===== ===== ====='
00384
00385 def test_read_ts_start_eof(self):
00386 if VERBOSITY:
00387 print >>sys.stderr, '===== read_ts_start_mid ====='
00388 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00389 d = self.log.read(timestamp=5.4)
00390 self.assertEqual(10, len(d))
00391 for ii in range(10):
00392 self.assertEqual(d[ii][0], ii)
00393 self.assertEqual(d[ii][1], TIMESTAMPS[ii])
00394 self.assertEqual(d[ii][2], DATA[ii])
00395 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00396 self.assert_(self.log.eof)
00397 if VERBOSITY:
00398 print >>sys.stderr, '===== ===== ====='
00399
00400 def test_read_ts_mid_start(self):
00401 if VERBOSITY:
00402 print >>sys.stderr, '===== read_ts_mid_start ====='
00403 for ii in range(3):
00404 self.log.read()
00405 self.assertEqual(self.log.pos, (3, TIMESTAMPS[3]))
00406 self.assertRaises(ValueError, self.log.read, timestamp=-1)
00407 self.assertEqual([], self.log.read(timestamp=0.1))
00408 self.assert_(not self.log.eof)
00409 if VERBOSITY:
00410 print >>sys.stderr, '===== ===== ====='
00411
00412 def test_read_ts_mid_mid(self):
00413 if VERBOSITY:
00414 print >>sys.stderr, '===== read_ts_mid_mid ====='
00415 for ii in range(3):
00416 self.log.read()
00417 self.assertEqual(self.log.pos, (3, TIMESTAMPS[3]))
00418 d = self.log.read(timestamp=3.25)
00419 self.assertEqual(4, len(d))
00420 for ii in range(4):
00421 self.assertEqual(d[ii][0], ii + 3)
00422 self.assertEqual(d[ii][1], TIMESTAMPS[ii + 3])
00423 self.assertEqual(d[ii][2], DATA[ii + 3])
00424 self.assertEqual(self.log.pos, (7, TIMESTAMPS[7]))
00425 self.assert_(not self.log.eof)
00426 if VERBOSITY:
00427 print >>sys.stderr, '===== ===== ====='
00428
00429 def test_read_ts_mid_end(self):
00430 if VERBOSITY:
00431 print >>sys.stderr, '===== read_ts_mid_end ====='
00432 for ii in range(3):
00433 self.log.read()
00434 self.assertEqual(self.log.pos, (3, TIMESTAMPS[3]))
00435 d = self.log.read(timestamp=5.3)
00436 self.assertEqual(7, len(d))
00437 for ii in range(7):
00438 self.assertEqual(d[ii][0], ii + 3)
00439 self.assertEqual(d[ii][1], TIMESTAMPS[ii + 3])
00440 self.assertEqual(d[ii][2], DATA[ii + 3])
00441 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00442 self.assert_(self.log.eof)
00443 if VERBOSITY:
00444 print >>sys.stderr, '===== ===== ====='
00445
00446 def test_read_ts_mid_eof(self):
00447 if VERBOSITY:
00448 print >>sys.stderr, '===== read_ts_mid_eof ====='
00449 for ii in range(3):
00450 self.log.read()
00451 self.assertEqual(self.log.pos, (3, TIMESTAMPS[3]))
00452 d = self.log.read(timestamp=5.4)
00453 self.assertEqual(7, len(d))
00454 for ii in range(7):
00455 self.assertEqual(d[ii][0], ii + 3)
00456 self.assertEqual(d[ii][1], TIMESTAMPS[ii + 3])
00457 self.assertEqual(d[ii][2], DATA[ii + 3])
00458 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00459 self.assert_(self.log.eof)
00460 if VERBOSITY:
00461 print >>sys.stderr, '===== ===== ====='
00462
00463 def test_read_ts_end_eof(self):
00464 if VERBOSITY:
00465 print >>sys.stderr, '===== read_ts_end_eof ====='
00466 for ii in range(10):
00467 self.log.read()
00468 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00469 self.assert_(self.log.eof)
00470 self.assertEqual([], self.log.read(timestamp=5.4))
00471 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00472 self.assert_(self.log.eof)
00473 if VERBOSITY:
00474 print >>sys.stderr, '===== ===== ====='
00475
00476 def test_backup_start(self):
00477 if VERBOSITY:
00478 print >>sys.stderr, '===== backup_start ====='
00479 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00480 self.log._backup_one()
00481 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00482 ind, ts, d = self.log.read()[0]
00483 self.assertEqual(ind, 0)
00484 self.assertEqual(ts, TIMESTAMPS[0])
00485 self.assertEqual(d, DATA[0])
00486 self.assertEqual(self.log.pos, (1, TIMESTAMPS[1]))
00487 self.assert_(not self.log.eof)
00488 if VERBOSITY:
00489 print >>sys.stderr, '===== ===== ====='
00490
00491 def test_backup_to_start(self):
00492 if VERBOSITY:
00493 print >>sys.stderr, '===== backup_to_start ====='
00494 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00495 self.log.read()
00496 self.assertEqual(self.log.pos, (1, TIMESTAMPS[1]))
00497 self.log._backup_one()
00498 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00499 ind, ts, d = self.log.read()[0]
00500 self.assertEqual(ind, 0)
00501 self.assertEqual(ts, TIMESTAMPS[0])
00502 self.assertEqual(d, DATA[0])
00503 self.log.read()
00504 self.log._backup_one()
00505 self.log._backup_one()
00506 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00507 ind, ts, d = self.log.read()[0]
00508 self.assertEqual(ind, 0)
00509 self.assertEqual(ts, TIMESTAMPS[0])
00510 self.assertEqual(d, DATA[0])
00511 self.assertEqual(self.log.pos, (1, TIMESTAMPS[1]))
00512 self.assert_(not self.log.eof)
00513 if VERBOSITY:
00514 print >>sys.stderr, '===== ===== ====='
00515
00516 def test_backup_mid(self):
00517 if VERBOSITY:
00518 print >>sys.stderr, '===== backup_mid ====='
00519 for ii in range(3):
00520 self.log.read()
00521 self.assertEqual(self.log.pos, (3, TIMESTAMPS[3]))
00522 self.log._backup_one()
00523 self.assertEqual(self.log.pos, (2, TIMESTAMPS[2]))
00524 ind, ts, d = self.log.read()[0]
00525 self.assertEqual(ind, 2)
00526 self.assertEqual(ts, TIMESTAMPS[2])
00527 self.assertEqual(d, DATA[2])
00528 self.assert_(not self.log.eof)
00529 if VERBOSITY:
00530 print >>sys.stderr, '===== ===== ====='
00531
00532 def test_backup_end(self):
00533 if VERBOSITY:
00534 print >>sys.stderr, '===== backup_end ====='
00535 for ii in range(9):
00536 self.log.read()
00537 self.assertEqual(self.log.pos, (9, TIMESTAMPS[9]))
00538 self.log._backup_one()
00539 self.assertEqual(self.log.pos, (8, TIMESTAMPS[8]))
00540 ind, ts, d = self.log.read()[0]
00541 self.assertEqual(ind, 8)
00542 self.assertEqual(ts, TIMESTAMPS[8])
00543 self.assertEqual(d, DATA[8])
00544 self.assert_(not self.log.eof)
00545 if VERBOSITY:
00546 print >>sys.stderr, '===== ===== ====='
00547
00548 def test_backup_eof(self):
00549 if VERBOSITY:
00550 print >>sys.stderr, '===== backup_eof ====='
00551 for ii in range(10):
00552 self.log.read()
00553 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00554 self.assert_(self.log.eof)
00555 self.log._backup_one()
00556 self.assertEqual(self.log.pos, (9, TIMESTAMPS[9]))
00557 self.assert_(not self.log.eof)
00558 ind, ts, d = self.log.read()[0]
00559 self.assertEqual(ind, 9)
00560 self.assertEqual(ts, TIMESTAMPS[9])
00561 self.assertEqual(d, DATA[9])
00562 self.assert_(self.log.eof)
00563 if VERBOSITY:
00564 print >>sys.stderr, '===== ===== ====='
00565
00566 def test_rewind_at_start(self):
00567 if VERBOSITY:
00568 print >>sys.stderr, '===== rewind_at_start ====='
00569 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00570 self.log.rewind()
00571 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00572 ind, ts, d = self.log.read()[0]
00573 self.assertEqual(ind, 0)
00574 self.assertEqual(ts, TIMESTAMPS[0])
00575 self.assertEqual(d, DATA[0])
00576 self.assert_(not self.log.eof)
00577 if VERBOSITY:
00578 print >>sys.stderr, '===== ===== ====='
00579
00580 def test_rewind_at_mid(self):
00581 if VERBOSITY:
00582 print >>sys.stderr, '===== rewind_at_mid ====='
00583 for ii in range(4):
00584 self.log.read()
00585 self.assertEqual(self.log.pos, (4, TIMESTAMPS[4]))
00586 self.log.rewind()
00587 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00588 ind, ts, d = self.log.read()[0]
00589 self.assertEqual(ind, 0)
00590 self.assertEqual(ts, TIMESTAMPS[0])
00591 self.assertEqual(d, DATA[0])
00592 self.assert_(not self.log.eof)
00593 if VERBOSITY:
00594 print >>sys.stderr, '===== ===== ====='
00595
00596 def test_rewind_at_end(self):
00597 if VERBOSITY:
00598 print >>sys.stderr, '===== rewind_at_mid ====='
00599 for ii in range(9):
00600 self.log.read()
00601 self.assertEqual(self.log.pos, (9, TIMESTAMPS[9]))
00602 self.log.rewind()
00603 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00604 ind, ts, d = self.log.read()[0]
00605 self.assertEqual(ind, 0)
00606 self.assertEqual(ts, TIMESTAMPS[0])
00607 self.assertEqual(d, DATA[0])
00608 self.assert_(not self.log.eof)
00609 if VERBOSITY:
00610 print >>sys.stderr, '===== ===== ====='
00611
00612 def test_rewind_at_eof(self):
00613 if VERBOSITY:
00614 print >>sys.stderr, '===== rewind_at_mid ====='
00615 for ii in range(10):
00616 self.log.read()
00617 self.assert_(self.log.eof)
00618 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00619 self.log.rewind()
00620 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00621 self.assert_(not self.log.eof)
00622 ind, ts, d = self.log.read()[0]
00623 self.assertEqual(ind, 0)
00624 self.assertEqual(ts, TIMESTAMPS[0])
00625 self.assertEqual(d, DATA[0])
00626 self.assert_(not self.log.eof)
00627 if VERBOSITY:
00628 print >>sys.stderr, '===== ===== ====='
00629
00630 def test_seek_start_start_ind(self):
00631 if VERBOSITY:
00632 print >>sys.stderr, '===== seek_start_start_ind ====='
00633 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00634 self.log.seek(index=0)
00635 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00636 ind, ts, d = self.log.read()[0]
00637 self.assertEqual(ind, 0)
00638 self.assertEqual(ts, TIMESTAMPS[0])
00639 self.assertEqual(d, DATA[0])
00640 self.assert_(not self.log.eof)
00641 if VERBOSITY:
00642 print >>sys.stderr, '===== ===== ====='
00643
00644 def test_seek_start_mid_ind(self):
00645 if VERBOSITY:
00646 print >>sys.stderr, '===== seek_start_mid_ind ====='
00647 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00648 self.log.seek(index=2)
00649 self.assertEqual(self.log.pos, (2, TIMESTAMPS[2]))
00650 ind, ts, d = self.log.read()[0]
00651 self.assertEqual(ind, 2)
00652 self.assertEqual(ts, TIMESTAMPS[2])
00653 self.assertEqual(d, DATA[2])
00654 self.assert_(not self.log.eof)
00655 if VERBOSITY:
00656 print >>sys.stderr, '===== ===== ====='
00657
00658 def test_seek_start_end_ind(self):
00659 if VERBOSITY:
00660 print >>sys.stderr, '===== seek_start_end_ind ====='
00661 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00662 self.log.seek(index=9)
00663 self.assertEqual(self.log.pos, (9, TIMESTAMPS[9]))
00664 ind, ts, d = self.log.read()[0]
00665 self.assertEqual(ind, 9)
00666 self.assertEqual(ts, TIMESTAMPS[9])
00667 self.assertEqual(d, DATA[9])
00668 self.assert_(self.log.eof)
00669 if VERBOSITY:
00670 print >>sys.stderr, '===== ===== ====='
00671
00672 def test_seek_start_eof_ind(self):
00673 if VERBOSITY:
00674 print >>sys.stderr, '===== seek_start_eof_ind ====='
00675 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00676 self.log.seek(index=11)
00677 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00678 self.assertEqual([], self.log.read())
00679 self.assert_(self.log.eof)
00680 if VERBOSITY:
00681 print >>sys.stderr, '===== ===== ====='
00682
00683 def test_seek_mid_start_ind(self):
00684 if VERBOSITY:
00685 print >>sys.stderr, '===== seek_mid_start_ind ====='
00686 for ii in range(5):
00687 self.log.read()
00688 self.assertEqual(self.log.pos, (5, TIMESTAMPS[5]))
00689 self.log.seek(index=0)
00690 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00691 ind, ts, d = self.log.read()[0]
00692 self.assertEqual(ind, 0)
00693 self.assertEqual(ts, TIMESTAMPS[0])
00694 self.assertEqual(d, DATA[0])
00695 self.assert_(not self.log.eof)
00696 if VERBOSITY:
00697 print >>sys.stderr, '===== ===== ====='
00698
00699 def test_seek_mid_rewind_ind(self):
00700 if VERBOSITY:
00701 print >>sys.stderr, '===== seek_mid_rewind_ind ====='
00702 for ii in range(5):
00703 self.log.read()
00704 self.assertEqual(self.log.pos, (5, TIMESTAMPS[5]))
00705 self.log.seek(index=2)
00706 self.assertEqual(self.log.pos, (2, TIMESTAMPS[2]))
00707 ind, ts, d = self.log.read()[0]
00708 self.assertEqual(ind, 2)
00709 self.assertEqual(ts, TIMESTAMPS[2])
00710 self.assertEqual(d, DATA[2])
00711 self.assert_(not self.log.eof)
00712 if VERBOSITY:
00713 print >>sys.stderr, '===== ===== ====='
00714
00715 def test_seek_mid_mid_ind(self):
00716 if VERBOSITY:
00717 print >>sys.stderr, '===== seek_mid_mid_ind ====='
00718 for ii in range(5):
00719 self.log.read()
00720 self.assertEqual(self.log.pos, (5, TIMESTAMPS[5]))
00721 self.log.seek(index=5)
00722 self.assertEqual(self.log.pos, (5, TIMESTAMPS[5]))
00723 ind, ts, d = self.log.read()[0]
00724 self.assertEqual(ind, 5)
00725 self.assertEqual(ts, TIMESTAMPS[5])
00726 self.assertEqual(d, DATA[5])
00727 self.assert_(not self.log.eof)
00728 if VERBOSITY:
00729 print >>sys.stderr, '===== ===== ====='
00730
00731 def test_seek_mid_ff_ind(self):
00732 if VERBOSITY:
00733 print >>sys.stderr, '===== seek_mid_ff_ind ====='
00734 for ii in range(5):
00735 self.log.read()
00736 self.assertEqual(self.log.pos, (5, TIMESTAMPS[5]))
00737 self.log.seek(index=7)
00738 self.assertEqual(self.log.pos, (7, TIMESTAMPS[7]))
00739 ind, ts, d = self.log.read()[0]
00740 self.assertEqual(ind, 7)
00741 self.assertEqual(ts, TIMESTAMPS[7])
00742 self.assertEqual(d, DATA[7])
00743 self.assert_(not self.log.eof)
00744 if VERBOSITY:
00745 print >>sys.stderr, '===== ===== ====='
00746
00747 def test_seek_mid_end_ind(self):
00748 if VERBOSITY:
00749 print >>sys.stderr, '===== seek_mid_end_ind ====='
00750 for ii in range(5):
00751 self.log.read()
00752 self.assertEqual(self.log.pos, (5, TIMESTAMPS[5]))
00753 self.log.seek(index=9)
00754 self.assertEqual(self.log.pos, (9, TIMESTAMPS[9]))
00755 ind, ts, d = self.log.read()[0]
00756 self.assertEqual(ind, 9)
00757 self.assertEqual(ts, TIMESTAMPS[9])
00758 self.assertEqual(d, DATA[9])
00759 self.assert_(self.log.eof)
00760 if VERBOSITY:
00761 print >>sys.stderr, '===== ===== ====='
00762
00763 def test_seek_mid_eof_ind(self):
00764 if VERBOSITY:
00765 print >>sys.stderr, '===== seek_mid_eof_ind ====='
00766 for ii in range(5):
00767 self.log.read()
00768 self.assertEqual(self.log.pos, (5, TIMESTAMPS[5]))
00769 self.log.seek(index=10)
00770 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00771 self.assertEqual([], self.log.read())
00772 self.assert_(self.log.eof)
00773 if VERBOSITY:
00774 print >>sys.stderr, '===== ===== ====='
00775
00776 def test_seek_end_start_ind(self):
00777 if VERBOSITY:
00778 print >>sys.stderr, '===== seek_end_start_ind ====='
00779 for ii in range(9):
00780 self.log.read()
00781 self.assertEqual(self.log.pos, (9, TIMESTAMPS[9]))
00782 self.log.seek(index=0)
00783 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00784 ind, ts, d = self.log.read()[0]
00785 self.assertEqual(ind, 0)
00786 self.assertEqual(ts, TIMESTAMPS[0])
00787 self.assertEqual(d, DATA[0])
00788 self.assert_(not self.log.eof)
00789 if VERBOSITY:
00790 print >>sys.stderr, '===== ===== ====='
00791
00792 def test_seek_end_mid_ind(self):
00793 if VERBOSITY:
00794 print >>sys.stderr, '===== seek_end_mid_ind ====='
00795 for ii in range(9):
00796 self.log.read()
00797 self.assertEqual(self.log.pos, (9, TIMESTAMPS[9]))
00798 self.log.seek(index=2)
00799 self.assertEqual(self.log.pos, (2, TIMESTAMPS[2]))
00800 ind, ts, d = self.log.read()[0]
00801 self.assertEqual(ind, 2)
00802 self.assertEqual(ts, TIMESTAMPS[2])
00803 self.assertEqual(d, DATA[2])
00804 self.assert_(not self.log.eof)
00805 if VERBOSITY:
00806 print >>sys.stderr, '===== ===== ====='
00807
00808 def test_seek_end_end_ind(self):
00809 if VERBOSITY:
00810 print >>sys.stderr, '===== seek_end_end_ind ====='
00811 for ii in range(9):
00812 self.log.read()
00813 self.assertEqual(self.log.pos, (9, TIMESTAMPS[9]))
00814 self.log.seek(index=9)
00815 self.assertEqual(self.log.pos, (9, TIMESTAMPS[9]))
00816 self.assert_(not self.log.eof)
00817 ind, ts, d = self.log.read()[0]
00818 self.assertEqual(ind, 9)
00819 self.assertEqual(ts, TIMESTAMPS[9])
00820 self.assertEqual(d, DATA[9])
00821 self.assert_(self.log.eof)
00822 if VERBOSITY:
00823 print >>sys.stderr, '===== ===== ====='
00824
00825 def test_seek_end_eof_ind(self):
00826 if VERBOSITY:
00827 print >>sys.stderr, '===== seek_end_eof_ind ====='
00828 for ii in range(9):
00829 self.log.read()
00830 self.assertEqual(self.log.pos, (9, TIMESTAMPS[9]))
00831 self.log.seek(index=10)
00832 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00833 self.assertEqual([], self.log.read())
00834 self.assert_(self.log.eof)
00835 if VERBOSITY:
00836 print >>sys.stderr, '===== ===== ====='
00837
00838 def test_seek_eof_start_ind(self):
00839 if VERBOSITY:
00840 print >>sys.stderr, '===== seek_eof_start_ind ====='
00841 for ii in range(10):
00842 self.log.read()
00843 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00844 self.assert_(self.log.eof)
00845 self.log.seek(index=0)
00846 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00847 ind, ts, d = self.log.read()[0]
00848 self.assertEqual(ind, 0)
00849 self.assertEqual(ts, TIMESTAMPS[0])
00850 self.assertEqual(d, DATA[0])
00851 self.assert_(not self.log.eof)
00852 if VERBOSITY:
00853 print >>sys.stderr, '===== ===== ====='
00854
00855 def test_seek_eof_mid_ind(self):
00856 if VERBOSITY:
00857 print >>sys.stderr, '===== seek_eof_mid_ind ====='
00858 for ii in range(10):
00859 self.log.read()
00860 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00861 self.assert_(self.log.eof)
00862 self.log.seek(index=2)
00863 self.assertEqual(self.log.pos, (2, TIMESTAMPS[2]))
00864 ind, ts, d = self.log.read()[0]
00865 self.assertEqual(ind, 2)
00866 self.assertEqual(ts, TIMESTAMPS[2])
00867 self.assertEqual(d, DATA[2])
00868 self.assert_(not self.log.eof)
00869 if VERBOSITY:
00870 print >>sys.stderr, '===== ===== ====='
00871
00872 def test_seek_eof_end_ind(self):
00873 if VERBOSITY:
00874 print >>sys.stderr, '===== seek_eof_end_ind ====='
00875 for ii in range(10):
00876 self.log.read()
00877 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00878 self.assert_(self.log.eof)
00879 self.log.seek(index=9)
00880 self.assertEqual(self.log.pos, (9, TIMESTAMPS[9]))
00881 self.assert_(not self.log.eof)
00882 ind, ts, d = self.log.read()[0]
00883 self.assertEqual(ind, 9)
00884 self.assertEqual(ts, TIMESTAMPS[9])
00885 self.assertEqual(d, DATA[9])
00886 self.assert_(self.log.eof)
00887 if VERBOSITY:
00888 print >>sys.stderr, '===== ===== ====='
00889
00890 def test_seek_eof_eof_ind(self):
00891 if VERBOSITY:
00892 print >>sys.stderr, '===== seek_eof_eof_ind ====='
00893 for ii in range(10):
00894 self.log.read()
00895 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00896 self.assert_(self.log.eof)
00897 self.log.seek(index=10)
00898 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00899 self.assertEqual([], self.log.read())
00900 self.assert_(self.log.eof)
00901 if VERBOSITY:
00902 print >>sys.stderr, '===== ===== ====='
00903
00904 def test_seek_start_before_start_ts(self):
00905 if VERBOSITY:
00906 print >>sys.stderr, '===== seek_start_before_start_ts ====='
00907 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00908 self.log.seek(timestamp=TIMESTAMPS[0] - 1)
00909 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00910 ind, ts, d = self.log.read()[0]
00911 self.assertEqual(ind, 0)
00912 self.assertEqual(ts, TIMESTAMPS[0])
00913 self.assertEqual(d, DATA[0])
00914 self.assert_(not self.log.eof)
00915 if VERBOSITY:
00916 print >>sys.stderr, '===== ===== ====='
00917
00918 def test_seek_start_start_ts(self):
00919 if VERBOSITY:
00920 print >>sys.stderr, '===== seek_start_start_ts ====='
00921 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00922 self.log.seek(timestamp=TIMESTAMPS[0])
00923 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00924 ind, ts, d = self.log.read()[0]
00925 self.assertEqual(ind, 0)
00926 self.assertEqual(ts, TIMESTAMPS[0])
00927 self.assertEqual(d, DATA[0])
00928 self.assert_(not self.log.eof)
00929 if VERBOSITY:
00930 print >>sys.stderr, '===== ===== ====='
00931
00932 def test_seek_start_before_mid_ts(self):
00933 if VERBOSITY:
00934 print >>sys.stderr, '===== seek_start_before_mid_ts ====='
00935 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00936 self.log.seek(timestamp=TIMESTAMPS[2] - \
00937 (TIMESTAMPS[2] - TIMESTAMPS[1]) * 0.6)
00938 self.assertEqual(self.log.pos, (2, TIMESTAMPS[2]))
00939 ind, ts, d = self.log.read()[0]
00940 self.assertEqual(ind, 2)
00941 self.assertEqual(ts, TIMESTAMPS[2])
00942 self.assertEqual(d, DATA[2])
00943 self.assert_(not self.log.eof)
00944 if VERBOSITY:
00945 print >>sys.stderr, '===== ===== ====='
00946
00947 def test_seek_start_mid_ts(self):
00948 if VERBOSITY:
00949 print >>sys.stderr, '===== seek_start_mid_ts ====='
00950 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00951 self.log.seek(timestamp=TIMESTAMPS[2])
00952 self.assertEqual(self.log.pos, (2, TIMESTAMPS[2]))
00953 ind, ts, d = self.log.read()[0]
00954 self.assertEqual(ind, 2)
00955 self.assertEqual(ts, TIMESTAMPS[2])
00956 self.assertEqual(d, DATA[2])
00957 self.assert_(not self.log.eof)
00958 if VERBOSITY:
00959 print >>sys.stderr, '===== ===== ====='
00960
00961 def test_seek_start_end_ts(self):
00962 if VERBOSITY:
00963 print >>sys.stderr, '===== seek_start_end_ts ====='
00964 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00965 self.log.seek(timestamp=TIMESTAMPS[9])
00966 self.assertEqual(self.log.pos, (9, TIMESTAMPS[9]))
00967 ind, ts, d = self.log.read()[0]
00968 self.assertEqual(ind, 9)
00969 self.assertEqual(ts, TIMESTAMPS[9])
00970 self.assertEqual(d, DATA[9])
00971 self.assert_(self.log.eof)
00972 if VERBOSITY:
00973 print >>sys.stderr, '===== ===== ====='
00974
00975 def test_seek_start_eof_ts(self):
00976 if VERBOSITY:
00977 print >>sys.stderr, '===== seek_start_eof_ts ====='
00978 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00979 self.log.seek(timestamp=TIMESTAMPS[9] + 1)
00980 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
00981 self.assertEqual([], self.log.read())
00982 self.assert_(self.log.eof)
00983 if VERBOSITY:
00984 print >>sys.stderr, '===== ===== ====='
00985
00986 def test_seek_mid_before_start_ts(self):
00987 if VERBOSITY:
00988 print >>sys.stderr, '===== seek_mid_before_start_ts ====='
00989 for ii in range(5):
00990 self.log.read()
00991 self.assertEqual(self.log.pos, (5, TIMESTAMPS[5]))
00992 self.log.seek(timestamp=TIMESTAMPS[0] - 1)
00993 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
00994 ind, ts, d = self.log.read()[0]
00995 self.assertEqual(ind, 0)
00996 self.assertEqual(ts, TIMESTAMPS[0])
00997 self.assertEqual(d, DATA[0])
00998 self.assert_(not self.log.eof)
00999 if VERBOSITY:
01000 print >>sys.stderr, '===== ===== ====='
01001
01002 def test_seek_mid_start_ts(self):
01003 if VERBOSITY:
01004 print >>sys.stderr, '===== seek_mid_start_ts ====='
01005 for ii in range(5):
01006 self.log.read()
01007 self.assertEqual(self.log.pos, (5, TIMESTAMPS[5]))
01008 self.log.seek(timestamp=TIMESTAMPS[0])
01009 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
01010 ind, ts, d = self.log.read()[0]
01011 self.assertEqual(ind, 0)
01012 self.assertEqual(ts, TIMESTAMPS[0])
01013 self.assertEqual(d, DATA[0])
01014 self.assert_(not self.log.eof)
01015 if VERBOSITY:
01016 print >>sys.stderr, '===== ===== ====='
01017
01018 def test_seek_mid_rewind_ts(self):
01019 if VERBOSITY:
01020 print >>sys.stderr, '===== seek_mid_rewind_ts ====='
01021 for ii in range(5):
01022 self.log.read()
01023 self.assertEqual(self.log.pos, (5, TIMESTAMPS[5]))
01024 self.log.seek(timestamp=TIMESTAMPS[2])
01025 self.assertEqual(self.log.pos, (2, TIMESTAMPS[2]))
01026 ind, ts, d = self.log.read()[0]
01027 self.assertEqual(ind, 2)
01028 self.assertEqual(ts, TIMESTAMPS[2])
01029 self.assertEqual(d, DATA[2])
01030 self.assert_(not self.log.eof)
01031 if VERBOSITY:
01032 print >>sys.stderr, '===== ===== ====='
01033
01034 def test_seek_mid_before_mid_ts(self):
01035 if VERBOSITY:
01036 print >>sys.stderr, '===== seek_mid_before_mid_ts ====='
01037 for ii in range(5):
01038 self.log.read()
01039 self.assertEqual(self.log.pos, (5, TIMESTAMPS[5]))
01040 self.log.seek(timestamp=TIMESTAMPS[2] - \
01041 (TIMESTAMPS[2] - TIMESTAMPS[1]) * 0.6)
01042 self.assertEqual(self.log.pos, (2, TIMESTAMPS[2]))
01043 ind, ts, d = self.log.read()[0]
01044 self.assertEqual(ind, 2)
01045 self.assertEqual(ts, TIMESTAMPS[2])
01046 self.assertEqual(d, DATA[2])
01047 self.assert_(not self.log.eof)
01048 if VERBOSITY:
01049 print >>sys.stderr, '===== ===== ====='
01050
01051 def test_seek_mid_mid_ts(self):
01052 if VERBOSITY:
01053 print >>sys.stderr, '===== seek_mid_mid_ts ====='
01054 for ii in range(5):
01055 self.log.read()
01056 self.assertEqual(self.log.pos, (5, TIMESTAMPS[5]))
01057 self.log.seek(timestamp=TIMESTAMPS[5])
01058 self.assertEqual(self.log.pos, (5, TIMESTAMPS[5]))
01059 ind, ts, d = self.log.read()[0]
01060 self.assertEqual(ind, 5)
01061 self.assertEqual(ts, TIMESTAMPS[5])
01062 self.assertEqual(d, DATA[5])
01063 self.assert_(not self.log.eof)
01064 if VERBOSITY:
01065 print >>sys.stderr, '===== ===== ====='
01066
01067 def test_seek_mid_after_mid_ts(self):
01068 if VERBOSITY:
01069 print >>sys.stderr, '===== seek_mid_after_mid_ts ====='
01070 for ii in range(5):
01071 self.log.read()
01072 self.assertEqual(self.log.pos, (5, TIMESTAMPS[5]))
01073 self.log.seek(timestamp=TIMESTAMPS[7] - \
01074 (TIMESTAMPS[7] - TIMESTAMPS[6]) * 0.6)
01075 self.assertEqual(self.log.pos, (7, TIMESTAMPS[7]))
01076 ind, ts, d = self.log.read()[0]
01077 self.assertEqual(ind, 7)
01078 self.assertEqual(ts, TIMESTAMPS[7])
01079 self.assertEqual(d, DATA[7])
01080 self.assert_(not self.log.eof)
01081 if VERBOSITY:
01082 print >>sys.stderr, '===== ===== ====='
01083
01084 def test_seek_mid_ff_ts(self):
01085 if VERBOSITY:
01086 print >>sys.stderr, '===== seek_mid_ff_ts ====='
01087 for ii in range(5):
01088 self.log.read()
01089 self.assertEqual(self.log.pos, (5, TIMESTAMPS[5]))
01090 self.log.seek(timestamp=TIMESTAMPS[7])
01091 self.assertEqual(self.log.pos, (7, TIMESTAMPS[7]))
01092 ind, ts, d = self.log.read()[0]
01093 self.assertEqual(ind, 7)
01094 self.assertEqual(ts, TIMESTAMPS[7])
01095 self.assertEqual(d, DATA[7])
01096 self.assert_(not self.log.eof)
01097 if VERBOSITY:
01098 print >>sys.stderr, '===== ===== ====='
01099
01100 def test_seek_mid_end_ts(self):
01101 if VERBOSITY:
01102 print >>sys.stderr, '===== seek_mid_end_ts ====='
01103 for ii in range(5):
01104 self.log.read()
01105 self.assertEqual(self.log.pos, (5, TIMESTAMPS[5]))
01106 self.log.seek(timestamp=TIMESTAMPS[9])
01107 self.assertEqual(self.log.pos, (9, TIMESTAMPS[9]))
01108 ind, ts, d = self.log.read()[0]
01109 self.assertEqual(ind, 9)
01110 self.assertEqual(ts, TIMESTAMPS[9])
01111 self.assertEqual(d, DATA[9])
01112 self.assert_(self.log.eof)
01113 if VERBOSITY:
01114 print >>sys.stderr, '===== ===== ====='
01115
01116 def test_seek_mid_eof_ts(self):
01117 if VERBOSITY:
01118 print >>sys.stderr, '===== seek_mid_eof_ts ====='
01119 for ii in range(5):
01120 self.log.read()
01121 self.assertEqual(self.log.pos, (5, TIMESTAMPS[5]))
01122 self.log.seek(timestamp=TIMESTAMPS[9] + 1)
01123 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
01124 self.assertEqual([], self.log.read())
01125 self.assert_(self.log.eof)
01126 if VERBOSITY:
01127 print >>sys.stderr, '===== ===== ====='
01128
01129 def test_seek_end_start_ts(self):
01130 if VERBOSITY:
01131 print >>sys.stderr, '===== seek_end_start_ts ====='
01132 for ii in range(9):
01133 self.log.read()
01134 self.assertEqual(self.log.pos, (9, TIMESTAMPS[9]))
01135 self.log.seek(timestamp=TIMESTAMPS[0])
01136 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
01137 ind, ts, d = self.log.read()[0]
01138 self.assertEqual(ind, 0)
01139 self.assertEqual(ts, TIMESTAMPS[0])
01140 self.assertEqual(d, DATA[0])
01141 self.assert_(not self.log.eof)
01142 if VERBOSITY:
01143 print >>sys.stderr, '===== ===== ====='
01144
01145 def test_seek_end_before_mid_ts(self):
01146 if VERBOSITY:
01147 print >>sys.stderr, '===== seek_end_before_mid_ts ====='
01148 for ii in range(9):
01149 self.log.read()
01150 self.assertEqual(self.log.pos, (9, TIMESTAMPS[9]))
01151 self.log.seek(timestamp=TIMESTAMPS[2] - \
01152 (TIMESTAMPS[2] - TIMESTAMPS[1]) * 0.6)
01153 self.assertEqual(self.log.pos, (2, TIMESTAMPS[2]))
01154 ind, ts, d = self.log.read()[0]
01155 self.assertEqual(ind, 2)
01156 self.assertEqual(ts, TIMESTAMPS[2])
01157 self.assertEqual(d, DATA[2])
01158 self.assert_(not self.log.eof)
01159 if VERBOSITY:
01160 print >>sys.stderr, '===== ===== ====='
01161
01162 def test_seek_end_mid_ts(self):
01163 if VERBOSITY:
01164 print >>sys.stderr, '===== seek_end_mid_ts ====='
01165 for ii in range(9):
01166 self.log.read()
01167 self.assertEqual(self.log.pos, (9, TIMESTAMPS[9]))
01168 self.log.seek(timestamp=TIMESTAMPS[2])
01169 self.assertEqual(self.log.pos, (2, TIMESTAMPS[2]))
01170 ind, ts, d = self.log.read()[0]
01171 self.assertEqual(ind, 2)
01172 self.assertEqual(ts, TIMESTAMPS[2])
01173 self.assertEqual(d, DATA[2])
01174 self.assert_(not self.log.eof)
01175 if VERBOSITY:
01176 print >>sys.stderr, '===== ===== ====='
01177
01178 def test_seek_end_end_ts(self):
01179 if VERBOSITY:
01180 print >>sys.stderr, '===== seek_end_end_ts ====='
01181 for ii in range(9):
01182 self.log.read()
01183 self.assertEqual(self.log.pos, (9, TIMESTAMPS[9]))
01184 self.log.seek(timestamp=TIMESTAMPS[9])
01185 self.assertEqual(self.log.pos, (9, TIMESTAMPS[9]))
01186 self.assert_(not self.log.eof)
01187 ind, ts, d = self.log.read()[0]
01188 self.assertEqual(ind, 9)
01189 self.assertEqual(ts, TIMESTAMPS[9])
01190 self.assertEqual(d, DATA[9])
01191 self.assert_(self.log.eof)
01192 if VERBOSITY:
01193 print >>sys.stderr, '===== ===== ====='
01194
01195 def test_seek_end_eof_ts(self):
01196 if VERBOSITY:
01197 print >>sys.stderr, '===== seek_end_eof_ts ====='
01198 for ii in range(9):
01199 self.log.read()
01200 self.assertEqual(self.log.pos, (9, TIMESTAMPS[9]))
01201 self.log.seek(timestamp=TIMESTAMPS[9] + 1)
01202 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
01203 self.assertEqual([], self.log.read())
01204 self.assert_(self.log.eof)
01205 if VERBOSITY:
01206 print >>sys.stderr, '===== ===== ====='
01207
01208 def test_seek_eof_start_ts(self):
01209 if VERBOSITY:
01210 print >>sys.stderr, '===== seek_eof_start_ts ====='
01211 for ii in range(10):
01212 self.log.read()
01213 self.assertEqual(self.log.pos, (10, TIMESTAMPS[9]))
01214 self.assert_(self.log.eof)
01215 self.log.seek(timestamp=TIMESTAMPS[0])
01216 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
01217 ind, ts, d = self.log.read()[0]
01218 self.assertEqual(ind, 0)
01219 self.assertEqual(ts, TIMESTAMPS[0])
01220 self.assertEqual(d, DATA[0])
01221 self.assert_(not self.log.eof)
01222 if VERBOSITY:
01223 print >>sys.stderr, '===== ===== ====='
01224
01225 def test_seek_eof_before_mid_ts(self):
01226 if VERBOSITY:
01227 print >>sys.stderr, '===== seek_eof_before_mid_ts ====='
01228 for ii in range(10):
01229 self.log.read()
01230 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
01231 self.assert_(self.log.eof)
01232 self.log.seek(timestamp=TIMESTAMPS[2] - \
01233 (TIMESTAMPS[2] - TIMESTAMPS[1]) * 0.6)
01234 self.assertEqual(self.log.pos, (2, TIMESTAMPS[2]))
01235 ind, ts, d = self.log.read()[0]
01236 self.assertEqual(ind, 2)
01237 self.assertEqual(ts, TIMESTAMPS[2])
01238 self.assertEqual(d, DATA[2])
01239 self.assert_(not self.log.eof)
01240 if VERBOSITY:
01241 print >>sys.stderr, '===== ===== ====='
01242
01243 def test_seek_eof_mid_ts(self):
01244 if VERBOSITY:
01245 print >>sys.stderr, '===== seek_eof_mid_ts ====='
01246 for ii in range(10):
01247 self.log.read()
01248 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
01249 self.assert_(self.log.eof)
01250 self.log.seek(timestamp=TIMESTAMPS[2])
01251 self.assertEqual(self.log.pos, (2, TIMESTAMPS[2]))
01252 ind, ts, d = self.log.read()[0]
01253 self.assertEqual(ind, 2)
01254 self.assertEqual(ts, TIMESTAMPS[2])
01255 self.assertEqual(d, DATA[2])
01256 self.assert_(not self.log.eof)
01257 if VERBOSITY:
01258 print >>sys.stderr, '===== ===== ====='
01259
01260 def test_seek_eof_end_ts(self):
01261 if VERBOSITY:
01262 print >>sys.stderr, '===== seek_eof_end_ts ====='
01263 for ii in range(10):
01264 self.log.read()
01265 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
01266 self.assert_(self.log.eof)
01267 self.log.seek(timestamp=TIMESTAMPS[9])
01268 self.assertEqual(self.log.pos, (9, TIMESTAMPS[9]))
01269 self.assert_(not self.log.eof)
01270 ind, ts, d = self.log.read()[0]
01271 self.assertEqual(ind, 9)
01272 self.assertEqual(ts, TIMESTAMPS[9])
01273 self.assertEqual(d, DATA[9])
01274 self.assert_(self.log.eof)
01275 if VERBOSITY:
01276 print >>sys.stderr, '===== ===== ====='
01277
01278 def test_seek_eof_eof_ts(self):
01279 if VERBOSITY:
01280 print >>sys.stderr, '===== seek_eof_eof_ts ====='
01281 for ii in range(10):
01282 self.log.read()
01283 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
01284 self.assert_(self.log.eof)
01285 self.log.seek(timestamp=TIMESTAMPS[9] + 1)
01286 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
01287 self.assertEqual([], self.log.read())
01288 self.assert_(self.log.eof)
01289 if VERBOSITY:
01290 print >>sys.stderr, '===== ===== ====='
01291
01292 def test_get_cur_pos(self):
01293 if VERBOSITY:
01294 print >>sys.stderr, '===== get_cur_pos ====='
01295 self.assertEqual(self.log.pos, (0, TIMESTAMPS[0]))
01296 for ii in range(4):
01297 self.log.read()
01298 self.assertEqual(self.log.pos, (4, TIMESTAMPS[4]))
01299 for ii in range(6):
01300 self.log.read()
01301 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
01302 self.assert_(self.log.eof)
01303 self.log.read()
01304 self.assertEqual(self.log.pos, (10, TIMESTAMPS[-1]))
01305 self.assert_(self.log.eof)
01306 if VERBOSITY:
01307 print >>sys.stderr, '===== ===== ====='
01308
01309
01310
01311 class OtherTests(unittest.TestCase):
01312 def setUp(self):
01313 self.write_test_log()
01314
01315 def tearDown(self):
01316 if os.path.isfile(os.path.join(os.getcwd(), 'test.log')):
01317 os.remove(os.path.join(os.getcwd(), 'test.log'))
01318
01319 def write_test_log(self):
01320 log = rtshell.simpkl_log.SimplePickleLog(filename='test.log', mode='w',
01321 meta=METADATA, verbose=VERBOSITY)
01322 for t, d in zip(TIMESTAMPS, DATA):
01323 log.write(t, d)
01324 log.close()
01325
01326 def test_with(self):
01327 if VERBOSITY:
01328 print >>sys.stderr, '===== with ====='
01329 with rtshell.simpkl_log.SimplePickleLog(filename='test.log',
01330 mode='r', meta=METADATA, verbose=VERBOSITY) as log:
01331 for ii in range(10):
01332 entry = log.read()
01333 if not entry:
01334
01335 self.assertEqual(log.pos, (10, TIMESTAMPS[-1]))
01336 else:
01337 ind, ts, d = entry[0]
01338 self.assertEqual(ind, ii)
01339 self.assertEqual(ts, TIMESTAMPS[ii])
01340 self.assertEqual(d, DATA[ii])
01341 if not log.eof:
01342 self.assertEqual(log.pos, (ii + 1, TIMESTAMPS[ii + 1]))
01343 else:
01344 self.assertEqual(log.pos, (ii + 1, TIMESTAMPS[-1]))
01345 if VERBOSITY:
01346 print >>sys.stderr, '===== ===== ====='
01347
01348 def test_iterator(self):
01349 if VERBOSITY:
01350 print >>sys.stderr, '===== iterator ====='
01351 log = rtshell.simpkl_log.SimplePickleLog(filename='test.log',
01352 mode='r', meta=METADATA, verbose=VERBOSITY)
01353 for (ii, entry) in enumerate(log):
01354 if not entry:
01355
01356 self.assertEqual(lf.pos, (10, TIMESTAMPS[-1]))
01357 else:
01358 ind, ts, d = entry
01359 self.assertEqual(ind, ii)
01360 self.assertEqual(ts, TIMESTAMPS[ii])
01361 self.assertEqual(d, DATA[ii])
01362 if not log.eof:
01363 self.assertEqual(log.pos, (ii + 1, TIMESTAMPS[ii + 1]))
01364 else:
01365 self.assertEqual(log.pos, (ii + 1, TIMESTAMPS[-1]))
01366 log.close()
01367 if VERBOSITY:
01368 print >>sys.stderr, '===== ===== ====='
01369
01370
01371 class TimestampTests(unittest.TestCase):
01372 def test_lt(self):
01373
01374 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) < \
01375 rtshell.ilog.EntryTS(sec=2, nsec=2), True)
01376 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) < \
01377 rtshell.ilog.EntryTS(sec=2, nsec=1), True)
01378 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) < \
01379 rtshell.ilog.EntryTS(sec=1, nsec=2), True)
01380 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) < \
01381 rtshell.ilog.EntryTS(sec=1, nsec=1), False)
01382 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=2) < \
01383 rtshell.ilog.EntryTS(sec=1, nsec=1), False)
01384 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=1) < \
01385 rtshell.ilog.EntryTS(sec=1, nsec=1), False)
01386 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=2) < \
01387 rtshell.ilog.EntryTS(sec=1, nsec=1), False)
01388
01389 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) < 2.000000002,
01390 True)
01391 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) < 2.000000001,
01392 True)
01393 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) < 1.000000002,
01394 True)
01395 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) < 1.000000001,
01396 False)
01397 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=2) < 1.000000001,
01398 False)
01399 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=1) < 1.000000001,
01400 False)
01401 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=2) < 1.000000001,
01402 False)
01403
01404 def test_le(self):
01405
01406 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) <= \
01407 rtshell.ilog.EntryTS(sec=2, nsec=2), True)
01408 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) <= \
01409 rtshell.ilog.EntryTS(sec=2, nsec=1), True)
01410 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) <= \
01411 rtshell.ilog.EntryTS(sec=1, nsec=2), True)
01412 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) <= \
01413 rtshell.ilog.EntryTS(sec=1, nsec=1), True)
01414 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=2) <= \
01415 rtshell.ilog.EntryTS(sec=1, nsec=1), False)
01416 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=1) <= \
01417 rtshell.ilog.EntryTS(sec=1, nsec=1), False)
01418 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=2) <= \
01419 rtshell.ilog.EntryTS(sec=1, nsec=1), False)
01420
01421 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) <= 2.000000002,
01422 True)
01423 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) <= 2.000000001,
01424 True)
01425 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) <= 1.000000002,
01426 True)
01427 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) <= 1.000000001,
01428 True)
01429 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=2) <= 1.000000001,
01430 False)
01431 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=1) <= 1.000000001,
01432 False)
01433 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=2) <= 1.000000001,
01434 False)
01435
01436 def test_eq(self):
01437
01438 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) == \
01439 rtshell.ilog.EntryTS(sec=2, nsec=2), False)
01440 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) == \
01441 rtshell.ilog.EntryTS(sec=2, nsec=1), False)
01442 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) == \
01443 rtshell.ilog.EntryTS(sec=1, nsec=2), False)
01444 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) == \
01445 rtshell.ilog.EntryTS(sec=1, nsec=1), True)
01446 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=2) == \
01447 rtshell.ilog.EntryTS(sec=1, nsec=1), False)
01448 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=1) == \
01449 rtshell.ilog.EntryTS(sec=1, nsec=1), False)
01450 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=2) == \
01451 rtshell.ilog.EntryTS(sec=1, nsec=1), False)
01452
01453 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) == 2.000000002,
01454 False)
01455 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) == 2.000000001,
01456 False)
01457 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) == 1.000000002,
01458 False)
01459 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) == 1.000000001,
01460 True)
01461 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=2) == 1.000000001,
01462 False)
01463 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=1) == 1.000000001,
01464 False)
01465 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=2) == 1.000000001,
01466 False)
01467
01468 def test_ne(self):
01469
01470 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) != \
01471 rtshell.ilog.EntryTS(sec=2, nsec=2), True)
01472 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) != \
01473 rtshell.ilog.EntryTS(sec=2, nsec=1), True)
01474 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) != \
01475 rtshell.ilog.EntryTS(sec=1, nsec=2), True)
01476 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) != \
01477 rtshell.ilog.EntryTS(sec=1, nsec=1), False)
01478 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=2) != \
01479 rtshell.ilog.EntryTS(sec=1, nsec=1), True)
01480 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=1) != \
01481 rtshell.ilog.EntryTS(sec=1, nsec=1), True)
01482 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=2) != \
01483 rtshell.ilog.EntryTS(sec=1, nsec=1), True)
01484
01485 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) != 2.000000002,
01486 True)
01487 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) != 2.000000001,
01488 True)
01489 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) != 1.000000002,
01490 True)
01491 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) != 1.000000001,
01492 False)
01493 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=2) != 1.000000001,
01494 True)
01495 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=1) != 1.000000001,
01496 True)
01497 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=2) != 1.000000001, True)
01498
01499 def test_gt(self):
01500
01501 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) > \
01502 rtshell.ilog.EntryTS(sec=2, nsec=2), False)
01503 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) > \
01504 rtshell.ilog.EntryTS(sec=2, nsec=1), False)
01505 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) > \
01506 rtshell.ilog.EntryTS(sec=1, nsec=2), False)
01507 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) > \
01508 rtshell.ilog.EntryTS(sec=1, nsec=1), False)
01509 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=2) > \
01510 rtshell.ilog.EntryTS(sec=1, nsec=1), True)
01511 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=1) > \
01512 rtshell.ilog.EntryTS(sec=1, nsec=1), True)
01513 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=2) > \
01514 rtshell.ilog.EntryTS(sec=1, nsec=1), True)
01515
01516 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) > 2.000000002,
01517 False)
01518 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) > 2.000000001,
01519 False)
01520 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) > 1.000000002,
01521 False)
01522 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) > 1.000000001,
01523 False)
01524 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=2) > 1.000000001,
01525 True)
01526 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=1) > 1.000000001,
01527 True)
01528 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=2) > 1.000000001,
01529 True)
01530
01531 def test_gt(self):
01532
01533 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) >= \
01534 rtshell.ilog.EntryTS(sec=2, nsec=2), False)
01535 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) >= \
01536 rtshell.ilog.EntryTS(sec=2, nsec=1), False)
01537 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) >= \
01538 rtshell.ilog.EntryTS(sec=1, nsec=2), False)
01539 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) >= \
01540 rtshell.ilog.EntryTS(sec=1, nsec=1), True)
01541 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=2) >= \
01542 rtshell.ilog.EntryTS(sec=1, nsec=1), True)
01543 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=1) >= \
01544 rtshell.ilog.EntryTS(sec=1, nsec=1), True)
01545 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=2) >= \
01546 rtshell.ilog.EntryTS(sec=1, nsec=1), True)
01547
01548 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) >= 2.000000002,
01549 False)
01550 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) >= 2.000000001,
01551 False)
01552 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) >= 1.000000002,
01553 False)
01554 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=1) >= 1.000000001,
01555 True)
01556 self.assertEqual(rtshell.ilog.EntryTS(sec=1, nsec=2) >= 1.000000001,
01557 True)
01558 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=1) >= 1.000000001,
01559 True)
01560 self.assertEqual(rtshell.ilog.EntryTS(sec=2, nsec=2) >= 1.000000001,
01561 True)
01562
01563 def test_construction(self):
01564 ts = rtshell.ilog.EntryTS(sec=1, nsec=2)
01565 self.assertEqual(ts.sec, 1)
01566 self.assertEqual(ts.nsec, 2)
01567 ts = rtshell.ilog.EntryTS(time=1.000000002)
01568 self.assertEqual(ts.sec, 1)
01569 self.assertEqual(ts.nsec, 2)
01570
01571 def test_to_float(self):
01572 ts = rtshell.ilog.EntryTS(sec=1, nsec=0)
01573 self.assertEqual(ts.float, 1.0)
01574 ts = rtshell.ilog.EntryTS(sec=1, nsec=2)
01575 self.assertEqual(ts.float, 1.000000002)
01576 ts = rtshell.ilog.EntryTS(sec=0, nsec=200)
01577 self.assertEqual(ts.float, 0.0000002)
01578
01579
01580 def write_suite():
01581 return unittest.TestLoader().loadTestsFromTestCase(WriteTests)
01582
01583
01584 def read_suite():
01585 return unittest.TestLoader().loadTestsFromTestCase(ReadTests)
01586
01587
01588 def other_suite():
01589 return unittest.TestLoader().loadTestsFromTestCase(OtherTests)
01590
01591
01592 def suite():
01593 return unittest.TestSuite([write_suite(), read_suite(), other_suite()])
01594
01595
01596 if __name__ == '__main__':
01597 unittest.main()
01598