2018-09-11 15:54:53 +02:00
|
|
|
#!/usr/bin/env python3
|
2018-09-05 17:22:17 +02:00
|
|
|
|
|
|
|
import unittest
|
|
|
|
import shutil
|
|
|
|
import os
|
|
|
|
|
2018-09-06 00:49:35 +02:00
|
|
|
from libmat2 import office, UnknownMemberPolicy
|
2018-09-05 17:22:17 +02:00
|
|
|
|
|
|
|
class TestPolicy(unittest.TestCase):
|
2019-10-12 22:32:04 +02:00
|
|
|
target = './tests/data/clean.docx'
|
|
|
|
|
2018-09-05 17:22:17 +02:00
|
|
|
def test_policy_omit(self):
|
2019-10-12 22:32:04 +02:00
|
|
|
shutil.copy('./tests/data/embedded.docx', self.target)
|
|
|
|
p = office.MSOfficeParser(self.target)
|
2018-09-06 00:49:35 +02:00
|
|
|
p.unknown_member_policy = UnknownMemberPolicy.OMIT
|
2018-09-05 17:22:17 +02:00
|
|
|
self.assertTrue(p.remove_all())
|
2019-10-12 22:32:04 +02:00
|
|
|
os.remove(p.filename)
|
2018-09-05 17:22:17 +02:00
|
|
|
|
|
|
|
def test_policy_keep(self):
|
2019-10-12 22:32:04 +02:00
|
|
|
shutil.copy('./tests/data/embedded.docx', self.target)
|
|
|
|
p = office.MSOfficeParser(self.target)
|
2018-09-06 00:49:35 +02:00
|
|
|
p.unknown_member_policy = UnknownMemberPolicy.KEEP
|
2018-09-05 17:22:17 +02:00
|
|
|
self.assertTrue(p.remove_all())
|
2019-10-12 22:32:04 +02:00
|
|
|
os.remove(p.filename)
|
|
|
|
os.remove(p.output_filename)
|
2018-09-05 17:22:17 +02:00
|
|
|
|
|
|
|
def test_policy_unknown(self):
|
2019-10-12 22:32:04 +02:00
|
|
|
shutil.copy('./tests/data/embedded.docx', self.target)
|
|
|
|
p = office.MSOfficeParser(self.target)
|
2018-09-05 17:22:17 +02:00
|
|
|
with self.assertRaises(ValueError):
|
2018-09-06 00:49:35 +02:00
|
|
|
p.unknown_member_policy = UnknownMemberPolicy('unknown_policy_name_totally_invalid')
|
2019-10-12 22:32:04 +02:00
|
|
|
os.remove(p.filename)
|