[arch-commits] Commit in python-mocket/repos (3 files)

Felix Yan felixonmars at archlinux.org
Mon Jul 27 12:30:44 UTC 2020


    Date: Monday, July 27, 2020 @ 12:30:43
  Author: felixonmars
Revision: 665444

archrelease: copy trunk to community-any

Added:
  python-mocket/repos/community-any/
  python-mocket/repos/community-any/PKGBUILD
    (from rev 665443, python-mocket/trunk/PKGBUILD)
  python-mocket/repos/community-any/file-magic.patch
    (from rev 665443, python-mocket/trunk/file-magic.patch)

------------------+
 PKGBUILD         |   42 ++++++++++++++++++++++++++++++++++++++++++
 file-magic.patch |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+)

Copied: python-mocket/repos/community-any/PKGBUILD (from rev 665443, python-mocket/trunk/PKGBUILD)
===================================================================
--- community-any/PKGBUILD	                        (rev 0)
+++ community-any/PKGBUILD	2020-07-27 12:30:43 UTC (rev 665444)
@@ -0,0 +1,42 @@
+# Maintainer: Felix Yan <felixonmars at archlinux.org>
+
+pkgname=python-mocket
+pkgver=3.8.6
+pkgrel=1
+pkgdesc="Socket Mock Framework - for all kinds of socket animals, web-clients included - with gevent/asyncio/SSL support"
+url="https://github.com/mindflayer/python-mocket"
+license=('BSD')
+arch=('any')
+depends=('python-decorator' 'python-magic' 'python-urllib3' 'python-six')
+makedepends=('python-pipenv-to-requirements' 'python-pytest-cov' 'python-setuptools')
+checkdepends=('pifpaf' 'python-aiohttp' 'python-gevent' 'python-mock' 'python-pook' 'python-redis'
+              'python-sure' 'redis')
+source=("https://github.com/mindflayer/python-mocket/archive/$pkgver/$pkgname-$pkgver.tar.gz"
+        file-magic.patch)
+sha512sums=('76e98927b4c8c3912309fe9341519d9e986538010e5a8fcf3efe95e04793d4da27f9d6472ce54db4199bb0535dd959d1d9f957c4be8ab8edbf4194845e194b16'
+            '03abc1d8bb73988c573dec87ce10b8aae52924117732372764b7118040645270d89c7daa5c415cd6d7efd9a0ba1e24478c29419d4a777d9d27a882bf7b6836e7')
+
+prepare() {
+  cd python-mocket-$pkgver
+  pipenv_to_requirements
+
+  patch -p1 -i ../file-magic.patch
+}
+
+build() {
+  cd python-mocket-$pkgver
+  python setup.py build
+}
+
+check() {
+  cd python-mocket-$pkgver
+  # https://github.com/mindflayer/python-mocket/issues/119
+  pifpaf run redis -- pytest --deselect tests/main/test_http_with_xxhash.py::HttpEntryTestCase::test_truesendall_with_dump_from_recording
+}
+
+package() {
+  cd python-mocket-$pkgver
+  python setup.py install --root="$pkgdir" --optimize=1
+
+  install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
+}

Copied: python-mocket/repos/community-any/file-magic.patch (from rev 665443, python-mocket/trunk/file-magic.patch)
===================================================================
--- community-any/file-magic.patch	                        (rev 0)
+++ community-any/file-magic.patch	2020-07-27 12:30:43 UTC (rev 665444)
@@ -0,0 +1,49 @@
+commit 7afc43a4bdd6eefd6637e17d3f84f70bdcee28f2
+Author: Felix Yan <felixonmars at archlinux.org>
+Date:   Mon Jul 27 20:19:24 2020 +0800
+
+    Add support for file's builtin magic module
+    
+    file's builtin magic module has a somewhat different API, and it's not
+    co-installable with pypi:python-magic as both has the same name. Adding
+    a fallback logic here makes mocket work with either one.
+    
+    All related tests are passing here.
+
+diff --git a/mocket/mockhttp.py b/mocket/mockhttp.py
+index 7f9a484..70da11c 100644
+--- a/mocket/mockhttp.py
++++ b/mocket/mockhttp.py
+@@ -87,9 +87,16 @@ class Response(object):
+         if not self.is_file_object:
+             self.headers["Content-Type"] = "text/plain; charset=utf-8"
+         elif self.magic:
+-            self.headers["Content-Type"] = decode_from_bytes(
+-                magic.from_buffer(self.body, mime=True)
+-            )
++            if hasattr(self.magic, "from_buffer"):
++                # PyPI python-magic
++                self.headers["Content-Type"] = decode_from_bytes(
++                    magic.from_buffer(self.body, mime=True)
++                )
++            else:
++                # file's builtin python wrapper
++                _magic = magic.open(magic.MAGIC_MIME)
++                _magic.load()
++                self.headers["Content-Type"] = _magic.buffer(self.body)
+ 
+     def set_extra_headers(self, headers):
+         for k, v in headers.items():
+diff --git a/tests/main/test_http.py b/tests/main/test_http.py
+index 2244a4c..9ef33c8 100644
+--- a/tests/main/test_http.py
++++ b/tests/main/test_http.py
+@@ -235,7 +235,7 @@ class HttpEntryTestCase(HttpTestCase):
+         self.assertEqual(remote_content, local_content)
+         self.assertEqual(len(remote_content), len(local_content))
+         self.assertEqual(int(r.headers["Content-Length"]), len(local_content))
+-        self.assertEqual(r.headers["Content-Type"], "image/png")
++        self.assertIn(r.headers["Content-Type"], ("image/png", "image/png; charset=binary"))
+ 
+     @mocketize
+     def test_file_object_with_no_lib_magic(self):



More information about the arch-commits mailing list