-
Notifications
You must be signed in to change notification settings - Fork 0
/
maillogcvt_test.py
51 lines (40 loc) · 1.66 KB
/
maillogcvt_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Tests for maillogcvt.py
#
# Copyright (C) 2023 Daniel Fandrich
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import io
import unittest
from unittest import mock
import maillogcvt
class TestMaillogCvt(unittest.TestCase):
def run_inout_test(self, infn, outfn):
outputfile = io.TextIOWrapper(io.BytesIO())
with open(infn, 'r') as inputfile, \
mock.patch('maillogcvt.sys.stdin', new=inputfile), \
mock.patch('maillogcvt.sys.stdout', new=outputfile):
maillogcvt.main()
with outputfile:
outputfile.seek(0)
actualdata = outputfile.read()
with open(outfn, 'r') as e:
expecteddata = e.read()
self.assertEqual(expecteddata, actualdata)
def test_message_1(self):
self.run_inout_test('testdata/maillog.input.1', 'testdata/maillog.expected.1')
def test_message_2(self):
self.run_inout_test('testdata/maillog.input.2', 'testdata/maillog.expected.2')
if __name__ == '__main__':
unittest.main()