diff options
| -rwxr-xr-x | mat2 | 2 | ||||
| -rw-r--r-- | tests/test_climat2.py | 28 |
2 files changed, 30 insertions, 0 deletions
| @@ -1,6 +1,7 @@ | |||
| 1 | #!/usr/bin/env python3 | 1 | #!/usr/bin/env python3 |
| 2 | 2 | ||
| 3 | import os | 3 | import os |
| 4 | import shutil | ||
| 4 | from typing import Tuple, List, Union, Set | 5 | from typing import Tuple, List, Union, Set |
| 5 | import sys | 6 | import sys |
| 6 | import mimetypes | 7 | import mimetypes |
| @@ -136,6 +137,7 @@ def clean_meta(filename: str, is_lightweight: bool, inplace: bool, sandbox: bool | |||
| 136 | try: | 137 | try: |
| 137 | logging.debug('Cleaning %s…', filename) | 138 | logging.debug('Cleaning %s…', filename) |
| 138 | ret = p.remove_all() | 139 | ret = p.remove_all() |
| 140 | shutil.copymode(filename, p.output_filename) | ||
| 139 | if inplace is True: | 141 | if inplace is True: |
| 140 | os.rename(p.output_filename, filename) | 142 | os.rename(p.output_filename, filename) |
| 141 | return ret | 143 | return ret |
diff --git a/tests/test_climat2.py b/tests/test_climat2.py index 9d816b1..17fce82 100644 --- a/tests/test_climat2.py +++ b/tests/test_climat2.py | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | import random | 1 | import random |
| 2 | import os | 2 | import os |
| 3 | import shutil | 3 | import shutil |
| 4 | import stat | ||
| 4 | import subprocess | 5 | import subprocess |
| 5 | import unittest | 6 | import unittest |
| 6 | import glob | 7 | import glob |
| @@ -132,6 +133,33 @@ class TestCleanMeta(unittest.TestCase): | |||
| 132 | self.assertNotIn(b'Comment: Created with GIMP', stdout) | 133 | self.assertNotIn(b'Comment: Created with GIMP', stdout) |
| 133 | 134 | ||
| 134 | os.remove('./tests/data/clean.jpg') | 135 | os.remove('./tests/data/clean.jpg') |
| 136 | os.remove('./tests/data/clean.cleaned.jpg') | ||
| 137 | |||
| 138 | |||
| 139 | class TestCopyPermissions(unittest.TestCase): | ||
| 140 | def test_jpg_777(self): | ||
| 141 | shutil.copy('./tests/data/dirty.jpg', './tests/data/clean.jpg') | ||
| 142 | os.chmod('./tests/data/clean.jpg', 0o777) | ||
| 143 | |||
| 144 | proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/clean.jpg'], | ||
| 145 | stdout=subprocess.PIPE) | ||
| 146 | stdout, _ = proc.communicate() | ||
| 147 | self.assertIn(b'Comment: Created with GIMP', stdout) | ||
| 148 | |||
| 149 | proc = subprocess.Popen(mat2_binary + ['./tests/data/clean.jpg'], | ||
| 150 | stdout=subprocess.PIPE) | ||
| 151 | stdout, _ = proc.communicate() | ||
| 152 | |||
| 153 | proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/clean.cleaned.jpg'], | ||
| 154 | stdout=subprocess.PIPE) | ||
| 155 | stdout, _ = proc.communicate() | ||
| 156 | self.assertNotIn(b'Comment: Created with GIMP', stdout) | ||
| 157 | |||
| 158 | permissions = os.stat('./tests/data/clean.cleaned.jpg')[stat.ST_MODE] | ||
| 159 | self.assertEqual(permissions, 0o100777) | ||
| 160 | |||
| 161 | os.remove('./tests/data/clean.jpg') | ||
| 162 | os.remove('./tests/data/clean.cleaned.jpg') | ||
| 135 | 163 | ||
| 136 | 164 | ||
| 137 | class TestIsSupported(unittest.TestCase): | 165 | class TestIsSupported(unittest.TestCase): |
