diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bfa80d0..a54d7654 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/extract_msg_tests/__init__.py b/extract_msg_tests/__init__.py index 117e5f63..a31b4cc0 100644 --- a/extract_msg_tests/__init__.py +++ b/extract_msg_tests/__init__.py @@ -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 diff --git a/extract_msg_tests/cmd_line_tests.py b/extract_msg_tests/cmd_line_tests.py new file mode 100644 index 00000000..a2f95375 --- /dev/null +++ b/extract_msg_tests/cmd_line_tests.py @@ -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) \ No newline at end of file diff --git a/extract_msg_tests/ole_writer_tests.py b/extract_msg_tests/ole_writer_tests.py index 55c2a2ec..610c2aa7 100644 --- a/extract_msg_tests/ole_writer_tests.py +++ b/extract_msg_tests/ole_writer_tests.py @@ -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.')