Browse Source

Merge upstream version 0.4.26

Christoph Biedl 1 year ago
parent
commit
9a9628627b
18 changed files with 68 additions and 90 deletions
  1. 1 0
      .dockerignore
  2. 1 1
      .gitignore
  3. 4 0
      CHANGELOG
  4. 0 0
      __init__.py
  5. 1 1
      setup.py
  6. 4 8
      test/README
  7. 5 2
      test/docker/alpine
  8. 6 5
      test/docker/bionic
  9. 6 2
      test/docker/centos7
  10. 5 3
      test/docker/centos8
  11. 6 5
      test/docker/focal
  12. 6 5
      test/docker/xenial
  13. 5 1
      test/libmagic_test.py
  14. 1 1
      test/test.py
  15. 0 35
      test/run.py
  16. 13 0
      test/run_all_docker_test.sh
  17. 0 18
      test_docker.sh
  18. 4 3
      tox.ini

+ 1 - 0
.dockerignore

@@ -0,0 +1 @@
+.gitignore

+ 1 - 1
.gitignore

@@ -4,7 +4,7 @@ bin/
 deb_dist
 deb_dist
 htmlcov/
 htmlcov/
 lib/
 lib/
-__pycache__/
+**/__pycache__
 python_magic.egg-info
 python_magic.egg-info
 pip-selfcheck.json
 pip-selfcheck.json
 pyvenv.cfg
 pyvenv.cfg

+ 4 - 0
CHANGELOG

@@ -1,3 +1,7 @@
+Changes to 0.4.26:
+  - Use tox for all multi-version testing
+  - Fix use of pytest, use it via tox
+
 Changes to 0.4.25:
 Changes to 0.4.25:
   - Support os.PathLike values in Magic.from_file and magic.from_file
   - Support os.PathLike values in Magic.from_file and magic.from_file
   - Handle some versions of libmagic that return mime string without charset
   - Handle some versions of libmagic that return mime string without charset

+ 0 - 0
__init__.py


+ 1 - 1
setup.py

@@ -18,7 +18,7 @@ setuptools.setup(
     author='Adam Hupp',
     author='Adam Hupp',
     author_email='adam@hupp.org',
     author_email='adam@hupp.org',
     url="http://github.com/ahupp/python-magic",
     url="http://github.com/ahupp/python-magic",
-    version='0.4.25',
+    version='0.4.26',
     long_description=read('README.md'),
     long_description=read('README.md'),
     long_description_content_type='text/markdown',
     long_description_content_type='text/markdown',
     packages=['magic'],
     packages=['magic'],

+ 4 - 8
test/README

@@ -1,10 +1,6 @@
-To run the tests across a selection of Ubuntu LTS versions:
+There are a few ways to run the python-magic tests
 
 
-docker build -t "python_magic/xenial:latest" -f test/Dockerfile_xenial .
-docker build -t "python_magic/bionic:latest" -f test/Dockerfile_bionic .
-docker build -t "python_magic/focal:latest" -f test/Dockerfile_focal .
-
-docker run python_magic/xenial:latest
-docker run python_magic/bionic:latest
-docker run python_magic/focal:latest
+ 1. `pytest` will run the test suite against your default version of python
+ 2. `./test/run_all_versions.py` will run the tests against all installed versions of python.
+ 3. `./test/run_all_docker_test.sh` will run against a variety of different Linux distributions, using docker.
 
 

+ 5 - 2
test/docker/alpine

@@ -1,4 +1,7 @@
 FROM python:3.8-alpine3.12
 FROM python:3.8-alpine3.12
 RUN apk add python3 python2 libmagic
 RUN apk add python3 python2 libmagic
-COPY . /python-magic
-CMD cd /python-magic/test && python3 ./run.py
+WORKDIR /python-magic
+COPY . .
+RUN python3 -m pip install tox
+CMD python3 -m tox
+

+ 6 - 5
test/docker/bionic

@@ -1,8 +1,9 @@
 FROM ubuntu:bionic
 FROM ubuntu:bionic
+WORKDIR /python-magic
+COPY . .
 RUN apt-get update
 RUN apt-get update
-RUN apt-get -y install python
-RUN apt-get -y install python3
-RUN apt-get -y install locales
+RUN apt-get -y install python python3 locales python3-pip libmagic1
 RUN locale-gen en_US.UTF-8
 RUN locale-gen en_US.UTF-8
-COPY . /python-magic
-CMD cd /python-magic/test && python3 ./run.py
+RUN python3 -m pip install tox
+CMD python3 -m tox
+

+ 6 - 2
test/docker/centos7

@@ -1,5 +1,9 @@
 FROM centos:7
 FROM centos:7
 RUN yum -y update
 RUN yum -y update
 RUN yum -y install file-devel python3 python2 which
 RUN yum -y install file-devel python3 python2 which
-COPY . /python-magic
-CMD cd /python-magic/test && SKIP_FROM_DESCRIPTOR=1 python3 ./run.py
+WORKDIR /python-magic
+COPY . .
+RUN python3 -m pip install tox
+ENV SKIP_FROM_DESCRIPTOR=1 
+CMD python3 -m tox
+

+ 5 - 3
test/docker/centos8

@@ -4,6 +4,8 @@ RUN yum -y install file-libs python3 python2 which glibc-locale-source
 RUN yum reinstall glibc-common -y && \
 RUN yum reinstall glibc-common -y && \
   localedef -i en_US -f UTF-8 en_US.UTF-8 && \
   localedef -i en_US -f UTF-8 en_US.UTF-8 && \
   echo "LANG=en_US.UTF-8" > /etc/locale.conf
   echo "LANG=en_US.UTF-8" > /etc/locale.conf
-ENV LANG en_US.UTF-8
-COPY . /python-magic
-CMD cd /python-magic/test && python3 ./run.py
+WORKDIR /python-magic
+COPY . .
+RUN python3 -m pip install tox
+CMD python3 -m tox
+

+ 6 - 5
test/docker/focal

@@ -1,8 +1,9 @@
 FROM ubuntu:focal
 FROM ubuntu:focal
+WORKDIR /python-magic
+COPY . .
 RUN apt-get update
 RUN apt-get update
-RUN apt-get -y install python2
-RUN apt-get -y install python3
-RUN apt-get -y install locales
+RUN apt-get -y install python python3 locales python3-pip libmagic1
 RUN locale-gen en_US.UTF-8
 RUN locale-gen en_US.UTF-8
-COPY . /python-magic
-CMD cd /python-magic/test && python3 ./run.py
+RUN python3 -m pip install tox
+CMD python3 -m tox
+

+ 6 - 5
test/docker/xenial

@@ -1,8 +1,9 @@
 FROM ubuntu:xenial
 FROM ubuntu:xenial
+WORKDIR /python-magic
+COPY . .
 RUN apt-get update
 RUN apt-get update
-RUN apt-get -y install python
-RUN apt-get -y install python3
-RUN apt-get -y install locales
+RUN apt-get -y install python python3 locales python3-pip libmagic1
 RUN locale-gen en_US.UTF-8
 RUN locale-gen en_US.UTF-8
-COPY . /python-magic
-CMD cd /python-magic/test && python3 ./run.py
+RUN python3 -m pip install tox
+CMD python3 -m tox
+

+ 5 - 1
test/libmagic_test.py

@@ -3,12 +3,16 @@
 import unittest
 import unittest
 import os
 import os
 import magic
 import magic
+import os.path
 
 
 # magic_descriptor is broken (?) in centos 7, so don't run those tests
 # magic_descriptor is broken (?) in centos 7, so don't run those tests
 SKIP_FROM_DESCRIPTOR = bool(os.environ.get('SKIP_FROM_DESCRIPTOR'))
 SKIP_FROM_DESCRIPTOR = bool(os.environ.get('SKIP_FROM_DESCRIPTOR'))
 
 
+TESTDATA_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), 'testdata'))
+
+
 class MagicTestCase(unittest.TestCase):
 class MagicTestCase(unittest.TestCase):
-    filename = 'testdata/test.pdf'
+    filename = os.path.join(TESTDATA_DIR, 'test.pdf')
     expected_mime_type = 'application/pdf'
     expected_mime_type = 'application/pdf'
     expected_encoding = 'us-ascii'
     expected_encoding = 'us-ascii'
     expected_name = ('PDF document, version 1.2', 'PDF document, version 1.2, 2 pages')
     expected_name = ('PDF document, version 1.2', 'PDF document, version 1.2, 2 pages')

+ 1 - 1
test/test.py

@@ -19,7 +19,7 @@ import sys
 SKIP_FROM_DESCRIPTOR = bool(os.environ.get('SKIP_FROM_DESCRIPTOR'))
 SKIP_FROM_DESCRIPTOR = bool(os.environ.get('SKIP_FROM_DESCRIPTOR'))
 
 
 class MagicTest(unittest.TestCase):
 class MagicTest(unittest.TestCase):
-    TESTDATA_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'testdata')
+    TESTDATA_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), 'testdata'))
 
 
     def test_version(self):
     def test_version(self):
         try:
         try:

+ 0 - 35
test/run.py

@@ -1,35 +0,0 @@
-import subprocess
-import os.path
-import sys
-
-this_dir = os.path.dirname(sys.argv[0])
-
-new_env = dict(os.environ)
-new_env.update({
-    'LC_ALL': 'en_US.UTF-8',
-    'PYTHONPATH': os.path.join(this_dir, ".."),
-})
-
-
-def has_py(version):
-    ret = subprocess.run("which %s" % version, shell=True, stdout=subprocess.DEVNULL)
-    return ret.returncode == 0
-
-
-def run_test(versions):
-    found = False
-    for i in versions:
-        if not has_py(i):
-            # if this version doesn't exist in path, skip
-            continue
-        found = True
-        print("Testing %s" % i)
-        subprocess.run([i, os.path.join(this_dir, "test.py")], env=new_env, check=True)
-        subprocess.run([i, os.path.join(this_dir, "libmagic_test.py")], env=new_env, check=True)
-
-    if not found:
-        sys.exit("No versions found: " + str(versions))
-
-run_test(["python2", "python2.7"])
-run_test(["python3.5", "python3.6", "python3.7", "python3.8", "python3.9"])
-

+ 13 - 0
test/run_all_docker_test.sh

@@ -0,0 +1,13 @@
+#!/bin/sh
+
+set -e
+set -x
+
+ROOT=$(dirname $0)/..
+cd $ROOT
+
+for f in test/docker/*; do 
+    H=$(docker build -q -f ${f} .)
+    docker run --rm $H
+done
+

+ 0 - 18
test_docker.sh

@@ -1,18 +0,0 @@
-#!/bin/bash
-
-# Test with various versions of ubuntu.  This more or less re-creates the
-# Travis CI test environment
-
-set -e
-
-DEFAULT_TARGETS="xenial bionic focal centos7 centos8 archlinux alpine"
-
-TARGETS=${1:-${DEFAULT_TARGETS}}
-
-HERE=`dirname $0`
-
-for i in $TARGETS; do
-    TAG="python_magic/${i}:latest"
-    docker build -t $TAG -f ${HERE}/test/docker/$i .
-    docker run $TAG
-done

+ 4 - 3
tox.ini

@@ -12,15 +12,15 @@ envlist =
 
 
 [testenv]
 [testenv]
 commands =
 commands =
-    coverage run --source=magic ./test/test.py
+    coverage run -m pytest 
 
 
 setenv =
 setenv =
   COVERAGE_FILE=.coverage.{envname}
   COVERAGE_FILE=.coverage.{envname}
   LC_ALL=en_US.UTF-8   
   LC_ALL=en_US.UTF-8   
 deps =
 deps =
     .[test]
     .[test]
-    zope.testrunner    
     coverage
     coverage
+    pytest
 
 
 [testenv:coverage-clean]
 [testenv:coverage-clean]
 deps = coverage
 deps = coverage
@@ -44,4 +44,5 @@ commands =
 deps = mypy
 deps = mypy
 skip_install = true
 skip_install = true
 commands =
 commands =
-    mypy magic.pyi
+    mypy -p magic
+