1
# -*- coding: utf-8 -*-
3
MoinMoin - MoinMoin.logfile Tests
5
@copyright: 2011 MoinMoin:ThomasWaldmann
6
@license: GNU GPL, see COPYING for details.
11
from StringIO import StringIO
13
from MoinMoin.logfile import LogFile
16
class TestLogFile(object):
17
""" testing logfile reading/writing """
18
# mtime rev action pagename host hostname user_id extra comment
20
[u'1292630945000000', u'00000001', u'SAVENEW', u'foo', u'0.0.0.0', u'example.org', u'111.111.111', u'', u''],
21
[u'1292630957849084', u'99999999', u'ATTNEW', u'foo', u'0.0.0.0', u'example.org', u'222.222.222', u'file.txt', u''],
22
[u'1292680177309091', u'99999999', u'ATTDEL', u'foo', u'0.0.0.0', u'example.org', u'333.333.333', u'file.txt', u''],
23
[u'1292680233866579', u'99999999', u'ATTNEW', u'foo', u'0.0.0.0', u'example.org', u'444.444.444', u'new.tgz', u''],
24
[u'1303073723000000', u'00000002', u'SAVE', u'foo', u'0.0.0.0', u'example.org', u'555.555.555', u'', u''],
27
def make_line(self, linedata):
28
line = u'\t'.join(linedata) + u'\n'
29
return line.encode('utf-8')
31
def write_log(self, fname, data):
34
f.write(self.make_line(linedata))
37
def setup_method(self, method):
38
self.fname = tempfile.mktemp()
39
self.write_log(self.fname, self.LOG)
41
def teardown_method(self, method):
45
fname_log = tempfile.mktemp()
46
lf = LogFile(fname_log)
47
for linedata in self.LOG:
49
expected_contents = open(self.fname, 'rb').read()
50
real_contents = open(fname_log, 'rb').read()
51
print repr(expected_contents)
52
print repr(real_contents)
53
assert real_contents == expected_contents
55
def test_iter_forward(self):
56
lf = LogFile(self.fname)
57
for result, expected in zip(lf, self.LOG):
60
assert result == expected
62
def test_iter_reverse(self):
63
lf = LogFile(self.fname)
64
for result, expected in zip(lf.reverse(), self.LOG[::-1]):
67
assert result == expected
69
def test_position(self):
70
lf = LogFile(self.fname)
73
expected_pos += len(self.make_line(data))
74
real_pos = lf.position()
75
print expected_pos, real_pos
76
assert real_pos == expected_pos
79
lf = LogFile(self.fname)
82
# now we are at the current end, remember position
85
newdata = [u'1303333333000000', u'00000003', u'SAVE', u'foo', u'0.0.0.0', u'example.org', u'666.666.666', u'', u'comment']
87
# go to position before new data
89
assert lf.position() == pos
91
# reads the one new line we added
92
print 'new:', repr(data)
93
assert data == newdata
95
assert lf.position() == 0
96
assert list(lf) == self.LOG + [newdata]
98
coverage_modules = ['MoinMoin.logfile']