2018-09-05 17:22:17 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
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):
|
|
|
|
def test_policy_omit(self):
|
|
|
|
shutil.copy('./tests/data/embedded.docx', './tests/data/clean.docx')
|
|
|
|
p = office.MSOfficeParser('./tests/data/clean.docx')
|
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())
|
|
|
|
os.remove('./tests/data/clean.docx')
|
2018-09-06 00:49:35 +02:00
|
|
|
os.remove('./tests/data/clean.cleaned.docx')
|
2018-09-05 17:22:17 +02:00
|
|
|
|
|
|
|
def test_policy_keep(self):
|
|
|
|
shutil.copy('./tests/data/embedded.docx', './tests/data/clean.docx')
|
|
|
|
p = office.MSOfficeParser('./tests/data/clean.docx')
|
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())
|
|
|
|
os.remove('./tests/data/clean.docx')
|
2018-09-06 00:49:35 +02:00
|
|
|
os.remove('./tests/data/clean.cleaned.docx')
|
2018-09-05 17:22:17 +02:00
|
|
|
|
|
|
|
def test_policy_unknown(self):
|
|
|
|
shutil.copy('./tests/data/embedded.docx', './tests/data/clean.docx')
|
|
|
|
p = office.MSOfficeParser('./tests/data/clean.docx')
|
|
|
|
with self.assertRaises(ValueError):
|
2018-09-06 00:49:35 +02:00
|
|
|
p.unknown_member_policy = UnknownMemberPolicy('unknown_policy_name_totally_invalid')
|
2018-09-05 17:22:17 +02:00
|
|
|
os.remove('./tests/data/clean.docx')
|
|
|
|
|