Skip to content

Commit

Permalink
Test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
TheElementalOfDestruction committed Mar 8, 2024
1 parent 7764e75 commit bf6feaf
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Added an option (`-s`, `--stdin`) to the command line to take an MSG file from stdin. This allows the user to pipe the msg data from another program directly instead of having to write a middleman that uses the extract-msg library directly or having to write the file to the disk first.
* Changed main function to allow for manual argument list to be passed to it.
* Added attributes at attachment base for creation and modification time. These can be accessed through `createdAt` ir `creationTime` and `lastModificationTime` or `modifiedAt`.
* Changed OleWriter tests to output the name of the test file being done if an error occurs.
* Added tests for some command line stuff.

**v0.48.0**
* Adjusted error handling for named properties to handle critical streams being missing and to allow suppression of those errors.
Expand Down
4 changes: 3 additions & 1 deletion extract_msg_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
__all__ = [
'AttachmentTests',
'CommandLineTests',
'OleWriterEditingTests',
'OleWriterExportTests',
'PropTests',
'ValidationTests',
]

from .validation_tests import ValidationTests
from .attachment_tests import AttachmentTests
from .cmd_line_tests import CommandLineTests
from .ole_writer_tests import OleWriterEditingTests, OleWriterExportTests
from .prop_tests import PropTests
from .validation_tests import ValidationTests
34 changes: 34 additions & 0 deletions extract_msg_tests/cmd_line_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
__all__ = [
'CommandLineTests',
]


import pathlib
import subprocess
import sys
import unittest

from .constants import TEST_FILE_DIR, USER_TEST_DIR


class CommandLineTests(unittest.TestCase):
def testStdin(self, testFileDir = TEST_FILE_DIR):
for path in testFileDir.glob('*.msg'):
# First, let's do the file on the disk.
process = subprocess.Popen([sys.executable, '-m', 'extract_msg', '--dump-stdout', str(path)], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
# Wait for the process to return data.
stdout1, stderr1 = process.communicate()

# Now, do the same thing with stdin.
process = subprocess.Popen([sys.executable, '-m', 'extract_msg', '-s', '--dump-stdout'], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
with open(path, 'rb') as f:
stdout2, stderr2 = process.communicate(f.read())

# Now, compare the two.
with self.subTest(path):
self.assertEqual(stdout1, stdout2)
self.assertEqual(stderr1, stderr2)

@unittest.skipIf(USER_TEST_DIR is None, 'User test files not defined.')
def testUserStdin(self):
self.testStdin(USER_TEST_DIR)
8 changes: 5 additions & 3 deletions extract_msg_tests/ole_writer_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,11 @@ def testExportExamples(self, testFileDir = TEST_FILE_DIR):
with open(exportResultFile, 'rb') as f:
exportResult = f.read()

# We use two assertions to give better error messages.
self.assertCountEqual(exportResult, exportedBytes, 'Exported data is wrong size.')
self.assertEqual(exportedBytes, exportResult, 'Exported data is incorrect.')
# Use a subtest to print the file name.
with self.subTest(str(testFileDir / exportResultFile.name)):
# We use two assertions to give better error messages.
self.assertCountEqual(exportResult, exportedBytes, 'Exported data is wrong size.')
self.assertEqual(exportedBytes, exportResult, 'Exported data is incorrect.')

@unittest.skipIf(USER_TEST_DIR is None, 'User test files not defined.')
@unittest.skipIf(USER_TEST_DIR is not None and not (USER_TEST_DIR / 'export-results').exists(), 'User export tests not defined.')
Expand Down

0 comments on commit bf6feaf

Please sign in to comment.