python-python-magic/magic-new-file.patch
Tomáš Chvátal 070d16a1c8 - Version update to 0.4.15:
* Few test tweaks
- Enable tests
- Add patch to fix gzip detection in tests:
  * magic-tests.patch
- Add patch to fix working with new file:
  * magic-new-file.patch
- Add patch to work with new mimedb:
  * magic-new-mime.patch
- Add patch magic-pep8.patch to have other patches apply cleanly

OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-python-magic?expand=0&rev=9
2018-08-21 10:50:28 +00:00

66 lines
2.7 KiB
Diff

From 93492a12aa8ae55e62bce0472e92800eac4b6269 Mon Sep 17 00:00:00 2001
From: Louis Sautier <sautier.louis@gmail.com>
Date: Tue, 14 Aug 2018 11:14:19 +0200
Subject: [PATCH] Tests: allow differences when reading a buffer or a file,
fixes #173
Also remove the loop in order to avoid analyzing files or buffers for each
expected value, replace it with a call to assertIn().
---
test/test.py | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
Index: python-magic-0.4.15/test/test.py
===================================================================
--- python-magic-0.4.15.orig/test/test.py
+++ python-magic-0.4.15/test/test.py
@@ -11,7 +11,7 @@ import magic
class MagicTest(unittest.TestCase):
TESTDATA_DIR = os.path.join(os.path.dirname(__file__), 'testdata')
- def assert_values(self, m, expected_values):
+ def assert_values(self, m, expected_values, buf_equals_file=True):
for filename, expected_value in expected_values.items():
try:
filename = os.path.join(self.TESTDATA_DIR, filename)
@@ -22,15 +22,16 @@ class MagicTest(unittest.TestCase):
if type(expected_value) is not tuple:
expected_value = (expected_value,)
- for i in expected_value:
- with open(filename, 'rb') as f:
- buf_value = m.from_buffer(f.read())
-
- file_value = m.from_file(filename)
- if buf_value == i and file_value == i:
- break
- else:
- self.assertTrue(False, "no match for " + repr(expected_value))
+ with open(filename, 'rb') as f:
+ buf_value = m.from_buffer(f.read())
+
+ file_value = m.from_file(filename)
+
+ if buf_equals_file:
+ self.assertEqual(buf_value, file_value)
+
+ for value in (buf_value, file_value):
+ self.assertIn(value, expected_value)
def test_from_buffer_str_and_bytes(self):
m = magic.Magic(mime=True)
@@ -67,9 +68,11 @@ class MagicTest(unittest.TestCase):
('gzip compressed data, was "test", from Unix, last '
'modified: Sun Jun 29 01:32:52 2008',
'gzip compressed data, was "test", last modified'
- ': Sun Jun 29 01:32:52 2008, from Unix'),
+ ': Sun Jun 29 01:32:52 2008, from Unix',
+ 'gzip compressed data, was "test", last modified'
+ ': Sun Jun 29 01:32:52 2008, from Unix, original size 15'),
'text.txt': 'ASCII text',
- })
+ }, buf_equals_file=False)
finally:
del os.environ['TZ']