diff options
author | 2015-07-09 19:08:08 -0400 | |
---|---|---|
committer | 2015-07-09 19:08:08 -0400 | |
commit | a83efe19256bf9d63a5039e7448155531cf56ee3 (patch) | |
tree | 76af8d90d19b2db051d2e2dca655dbaac97a68eb /tests | |
parent | grs/__init__.py: import Rotator. (diff) | |
download | grss-a83efe19256bf9d63a5039e7448155531cf56ee3.tar.gz grss-a83efe19256bf9d63a5039e7448155531cf56ee3.tar.bz2 grss-a83efe19256bf9d63a5039e7448155531cf56ee3.zip |
grs/Rotator.py: document and improve.
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test-log.py | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/tests/test-log.py b/tests/test-log.py index f132ca0..b419fbb 100755 --- a/tests/test-log.py +++ b/tests/test-log.py @@ -10,16 +10,10 @@ from grs import Log logdir = '/tmp/test-log' -def doit(stamped = False): - if os.path.isdir(logdir): - shutil.rmtree(logdir) - os.makedirs(logdir) - logfile = os.path.join(logdir, 'test.log') - - lo = Log(logfile) +def doit(lo, stamped = False): + # Create a log with knowing contents and rotate 3 times. for i in range(10): lo.log('first %d' % i, stamped) - lo.rotate_logs() lo.rotate_logs() lo.rotate_logs() @@ -28,6 +22,7 @@ def doit(stamped = False): def hashtest(expect_pass = True): + # Hash up our log and three rotations. Do we get what we expected? m = hashlib.md5() for i in [ '', '.0', '.1', '.2']: log = os.path.join(logdir, 'test.log%s' % i) @@ -39,7 +34,23 @@ def hashtest(expect_pass = True): assert(m.hexdigest() != '485b8bf3a9e08bd5ccfdff7e1a8fe4e1') if __name__ == "__main__": - doit(stamped=False) + if os.path.isdir(logdir): + shutil.rmtree(logdir) + os.makedirs(logdir) + logfile = os.path.join(logdir, 'test.log') + lo = Log(logfile) + + doit(lo, stamped=False) hashtest(expect_pass=True) - doit(stamped=True) + doit(lo, stamped=True) hashtest(expect_pass=False) + + # Make sure we're dropping past the upper limit. + lo.rotate_logs(upper_limit=2) + assert(os.path.isfile(logfile)) + assert(os.path.isfile(logfile+'.0')) + assert(os.path.isfile(logfile+'.1')) + assert(os.path.isfile(logfile+'.2')) + assert(not os.path.isfile(logfile+'.3')) + assert(not os.path.isfile(logfile+'.4')) + assert(not os.path.isfile(logfile+'.5')) |