1
0
mirror of synced 2024-11-22 17:24:23 +01:00
mat2/tests/test_policy.py

33 lines
1.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2018-09-05 17:22:17 +02:00
import unittest
import shutil
import os
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)
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)
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):
p.unknown_member_policy = UnknownMemberPolicy('unknown_policy_name_totally_invalid')
2019-10-12 22:32:04 +02:00
os.remove(p.filename)