4 from tempfile
import mkdtemp
5 from shutil
import rmtree
7 from string
import hexdigits
9 import pm3_eml2mfd
, pm3_mfd2eml
11 class TestEmlMfd(unittest
.TestCase
):
13 self
.tmpdir
= mkdtemp()
20 ("41424344\r\n45464748\n494A4B4C\n", "ABCDEFGHIJKL")
22 def test_eml2mfd(self
):
23 self
.three_argument_test(pm3_eml2mfd
.main
, self
.EML2MFD_TESTCASES
)
25 def test_mfd2eml(self
):
26 self
.three_argument_test(pm3_mfd2eml
.main
,
27 map(reversed, self
.EML2MFD_TESTCASES
), c14n
=hex_c14n
)
29 def three_argument_test(self
, operation
, cases
, c14n
=str):
30 for case_input
, case_output
in cases
:
32 inp_name
= os
.path
.join(self
.tmpdir
, 'input')
33 out_name
= os
.path
.join(self
.tmpdir
, 'output')
34 with
open(inp_name
, 'w') as in_file
:
35 in_file
.write(case_input
)
36 operation(['', inp_name
, out_name
])
37 with
open(out_name
, 'r') as out_file
:
38 self
.assertEqual(c14n(case_output
), c14n(out_file
.read()))
40 for file_name
in inp_name
, out_name
:
41 if os
.path
.exists(file_name
):
47 Canonicalizes the input string by removing non-hexadecimal
48 characters and making everything uppercase
50 return ''.join(c
.upper() for c
in inp
if c
in hexdigits
)
52 if __name__
== '__main__':