[Python-modules-commits] [binaryornot] 04/08: New upstream release.

Vincent Bernat bernat at moszumanska.debian.org
Mon Nov 13 22:51:46 UTC 2017


This is an automated email from the git hooks/post-receive script.

bernat pushed a commit to annotated tag debian/0.4.4+dfsg-1
in repository binaryornot.

commit 643d410be27a9b3ad34d0d7c65927c6bdf85be5d
Author: Vincent Bernat <bernat at debian.org>
Date:   Mon Nov 13 23:45:32 2017 +0100

    New upstream release.
---
 .gitignore                  |   3 +
 .pep8                       |   3 +
 .travis.yml                 |  22 ++++---
 AUTHORS.rst                 |   4 ++
 HISTORY.rst                 |  20 +++++-
 LICENSE                     |  25 ++++++--
 README.rst                  |  32 +++++++---
 binaryornot/__init__.py     |   2 +-
 binaryornot/check.py        |  10 ++-
 binaryornot/helpers.py      |  49 ++++++++-------
 setup.py                    |  46 +++++++-------
 tasks.py                    |  24 +++++---
 tests/files/empty.pyc       | Bin 0 -> 94 bytes
 tests/files/hello_world.py  |   1 +
 tests/files/hello_world.pyc | Bin 0 -> 122 bytes
 tests/files/troublesome.pyc | Bin 0 -> 146 bytes
 tests/test_check.py         | 144 ++++++++++++++++++++++++++++----------------
 tox.ini                     |   5 +-
 18 files changed, 260 insertions(+), 130 deletions(-)

diff --git a/.gitignore b/.gitignore
index 540b759..6bd4426 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,7 @@
 *.py[cod]
+!hello_world.pyc
+!empty.pyc
+!troublesome.pyc
 
 # C extensions
 *.so
diff --git a/.pep8 b/.pep8
new file mode 100644
index 0000000..f6195b6
--- /dev/null
+++ b/.pep8
@@ -0,0 +1,3 @@
+[pep8]
+max-line-length = 120
+exclude=docs/, .tox/, .hypothesis/
diff --git a/.travis.yml b/.travis.yml
index 3b7d14f..1581d07 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,13 +2,21 @@
 
 sudo: false
 language: python
-python: 2.7
-env:
-    - TOX_ENV=py26
-    - TOX_ENV=py27
-    - TOX_ENV=py33
-    - TOX_ENV=py34
-    - TOX_ENV=pypy
+
+matrix:
+    include:
+      - python: 2.7
+        env: TOX_ENV=py27
+      - python: 3.3
+        env: TOX_ENV=py33
+      - python: 3.4
+        env: TOX_ENV=py34
+      - python: 3.5
+        env: TOX_ENV=py35
+      - python: 3.6
+        env: TOX_ENV=py36
+      - python: pypy
+        env: TOX_ENV=pypy
 
 script: tox -e $TOX_ENV
 
diff --git a/AUTHORS.rst b/AUTHORS.rst
index 7eba27f..100aa83 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -18,6 +18,8 @@ Contributors
 * Aaron Meurer (`@asmeurer`_)
 * David R. MacIver (`@DRMacIver`_)
 * Raphael Pierzina (`@hackebrot`_)
+* Johannes (`@johtso`_)
+* Luke Hinds (`@lukehinds`_)
 
 .. _`@audreyr`: https://github.com/audreyr
 .. _`@ncoghlan`: https://github.com/ncoghlan
@@ -28,3 +30,5 @@ Contributors
 .. _`@asmeurer`: https://github.com/asmeurer
 .. _`@DRMacIver`: https://github.com/DRMacIver
 .. _`@hackebrot`: https://github.com/hackebrot
+.. _`@johtso`: https://github.com/johtso
+.. _`@lukehinds`: https://github.com/lukehinds
diff --git a/HISTORY.rst b/HISTORY.rst
index 9d6858f..14312f3 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -3,6 +3,24 @@
 History
 -------
 
+0.4.4 (2017-04-13)
+~~~~~~~~~~~~~~~~~~
+
+* Notify users for file i/o issues. Thanks @lukehinds!
+
+
+0.4.3 (2017-04-13)
+~~~~~~~~~~~~~~~~~~
+
+* Restricted chardet to anything 3.0.2 or higher due to https://github.com/chardet/chardet/issues/113. Thanks @dan-blanchard for the quick fix!
+
+0.4.2 (2017-04-12)
+~~~~~~~~~~~~~~~~~~
+
+* Restricted chardet to anything under 3.0 due to https://github.com/chardet/chardet/issues/113
+* Added pyup badge
+* Added utilities for pushing new versions up
+
 0.4.0 (2015-08-21)
 ~~~~~~~~~~~~~~~~~~
 
@@ -13,7 +31,7 @@ History
 * Add very simple Hypothesis based tests. (#13) Thanks `@DRMacIver`_.
 * Use setup to determine requirements and remove redundant requirements.txt. (#14) Thanks `@hackebrot`_.
 * Add documentation status badge to README.rst. (#15) Thanks `@hackebrot`_.
-* Run tox in travis.yml. Add pypy and Python 3.4 to tox enviroments. (#16) Thanks `@hackebrot`_ `@pydanny`_.
+* Run tox in travis.yml. Add pypy and Python 3.4 to tox environments. (#16) Thanks `@hackebrot`_ `@pydanny`_.
 * Handle LookupError when detecting encoding. (#17) Thanks `@DRMacIver`_.
 
 
diff --git a/LICENSE b/LICENSE
index c5460c1..7013cb1 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,12 +1,27 @@
 Copyright (c) 2013, Audrey Roy
 All rights reserved.
 
-Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
 
-* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+* Redistributions of source code must retain the above copyright notice, this
+  list of conditions and the following disclaimer.
 
-* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+* Redistributions in binary form must reproduce the above copyright notice,
+  this list of conditions and the following disclaimer in the documentation
+  and/or other materials provided with the distribution.
 
-* Neither the name of BinaryOrNot nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+* Neither the name of BinaryOrNot nor the names of its contributors may be used
+  to endorse or promote products derived from this software without specific
+  prior written permission.
 
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROF [...]
\ No newline at end of file
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/README.rst b/README.rst
index b3afe2d..4411a3f 100644
--- a/README.rst
+++ b/README.rst
@@ -2,22 +2,23 @@
 BinaryOrNot
 =============================
 
-.. image:: https://badge.fury.io/py/binaryornot.png
-    :target: http://badge.fury.io/py/binaryornot
-    
-.. image:: https://travis-ci.org/audreyr/binaryornot.png?branch=master
-        :target: https://travis-ci.org/audreyr/binaryornot
+.. image:: https://img.shields.io/pypi/v/binaryornot.svg?style=flat
+      :target: https://pypi.python.org/pypi/binaryornot
 
 .. image:: https://readthedocs.org/projects/binaryornot/badge/?version=latest
-        :target: https://readthedocs.org/projects/binaryornot/?badge=latest
-        :alt: Documentation Status
+    :target: http://binaryornot.readthedocs.io/en/latest/?badge=latest
+    :alt: Documentation Status
+
 
+.. image:: https://pyup.io/repos/github/audreyr/binaryornot/shield.svg
+   :target: https://pyup.io/repos/github/audreyr/binaryornot/
+   :alt: Updates
 
 Ultra-lightweight pure Python package to guess whether a file is binary or text,
 using a heuristic similar to Perl's `pp_fttext` and its analysis by @eliben.
 
 * Free software: BSD license
-* Documentation: http://binaryornot.readthedocs.org
+* Documentation: https://binaryornot.readthedocs.io
 
 Status
 ------
@@ -46,7 +47,7 @@ Why?
 
 You may be thinking, "I can write this in 2 lines of code?!"
 
-It's actually not that easy. Here's a great article about how *perldoc*'s
+It's actually not that easy. Here's a great article about how Perl's
 heuristic to guess file types works: http://eli.thegreenplace.net/2011/10/19/perls-guess-if-file-is-text-or-binary-implemented-in-python/
 
 And that's just where we started. Over time, we've found more edge cases and
@@ -55,6 +56,19 @@ our heuristic has gotten more complex.
 Also, this package saves you from having to write and thoroughly test
 your code with all sorts of weird file types and encodings, cross-platform.
 
+Builds
+------
+
+Linux (Ubuntu 12.04 LTS Server Edition 64 bit):
+
+.. image:: https://img.shields.io/travis/audreyr/binaryornot/master.svg
+        :target: https://travis-ci.org/audreyr/binaryornot
+
+Windows (Windows Server 2012 R2 (x64)):
+
+.. image:: https://img.shields.io/appveyor/ci/audreyr/binaryornot/master.svg
+        :target: https://ci.appveyor.com/project/audreyr/binaryornot
+
 Credits
 -------
 
diff --git a/binaryornot/__init__.py b/binaryornot/__init__.py
index c3f85a4..df6f12b 100644
--- a/binaryornot/__init__.py
+++ b/binaryornot/__init__.py
@@ -1,3 +1,3 @@
 __author__ = 'Audrey Roy'
 __email__ = 'audreyr at gmail.com'
-__version__ = '0.4.0'
+__version__ = '0.4.3'
diff --git a/binaryornot/check.py b/binaryornot/check.py
index 77da12c..a784e3a 100644
--- a/binaryornot/check.py
+++ b/binaryornot/check.py
@@ -20,6 +20,14 @@ def is_binary(filename):
     :param filename: File to check.
     :returns: True if it's a binary file, otherwise False.
     """
-    logger.debug('is_binary: %(filename)r' % locals())
+    logger.debug('is_binary: %(filename)r', locals())
+
+    # Check if the file extension is in a list of known binary types
+    binary_extensions = ['.pyc', ]
+    for ext in binary_extensions:
+        if filename.endswith(ext):
+            return True
+
+    # Check if the starting chunk is a binary string
     chunk = get_starting_chunk(filename)
     return is_binary_string(chunk)
diff --git a/binaryornot/helpers.py b/binaryornot/helpers.py
index ee45c1e..3f034a6 100644
--- a/binaryornot/helpers.py
+++ b/binaryornot/helpers.py
@@ -29,9 +29,12 @@ def get_starting_chunk(filename, length=1024):
     :returns: Starting chunk of bytes.
     """
     # Ensure we open the file in binary mode
-    with open(filename, 'rb') as f:
-        chunk = f.read(length)
-        return chunk
+    try:
+        with open(filename, 'rb') as f:
+            chunk = f.read(length)
+            return chunk
+    except IOError as e:
+        print(e)
 
 
 _control_chars = b'\n\r\t\f\b'
@@ -47,16 +50,17 @@ else:
 
 def is_binary_string(bytes_to_check):
     """
+    Uses a simplified version of the Perl detection algorithm,
+    based roughly on Eli Bendersky's translation to Python:
+    http://eli.thegreenplace.net/2011/10/19/perls-guess-if-file-is-text-or-binary-implemented-in-python/
+
+    This is biased slightly more in favour of deeming files as text
+    files than the Perl algorithm, since all ASCII compatible character
+    sets are accepted as text, not just utf-8.
+
     :param bytes: A chunk of bytes to check.
     :returns: True if appears to be a binary, otherwise False.
     """
-    # Uses a simplified version of the Perl detection algorithm,
-    # based roughly on Eli Bendersky's translation to Python:
-    # http://eli.thegreenplace.net/2011/10/19/perls-guess-if-file-is-text-or-binary-implemented-in-python/
-
-    # This is biased slightly more in favour of deeming files as text
-    # files than the Perl algorithm, since all ASCII compatible character
-    # sets are accepted as text, not just utf-8
 
     # Empty files are considered text files
     if not bytes_to_check:
@@ -66,7 +70,7 @@ def is_binary_string(bytes_to_check):
     # Binary if control chars are > 30% of the string
     low_chars = bytes_to_check.translate(None, _printable_ascii)
     nontext_ratio1 = float(len(low_chars)) / float(len(bytes_to_check))
-    logger.debug('nontext_ratio1: %(nontext_ratio1)r' % locals())
+    logger.debug('nontext_ratio1: %(nontext_ratio1)r', locals())
 
     # and check for a low percentage of high ASCII characters:
     # Binary if high ASCII chars are < 5% of the string
@@ -78,41 +82,40 @@ def is_binary_string(bytes_to_check):
 
     high_chars = bytes_to_check.translate(None, _printable_high_ascii)
     nontext_ratio2 = float(len(high_chars)) / float(len(bytes_to_check))
-    logger.debug('nontext_ratio2: %(nontext_ratio2)r' % locals())
+    logger.debug('nontext_ratio2: %(nontext_ratio2)r', locals())
 
     is_likely_binary = (
-        (nontext_ratio1 > 0.3 and nontext_ratio2 < 0.05)
-        or
+        (nontext_ratio1 > 0.3 and nontext_ratio2 < 0.05) or
         (nontext_ratio1 > 0.8 and nontext_ratio2 > 0.8)
     )
-    logger.debug('is_likely_binary: %(is_likely_binary)r' % locals())
+    logger.debug('is_likely_binary: %(is_likely_binary)r', locals())
 
     # then check for binary for possible encoding detection with chardet
     detected_encoding = chardet.detect(bytes_to_check)
-    logger.debug('detected_encoding: %(detected_encoding)r' % locals())
+    logger.debug('detected_encoding: %(detected_encoding)r', locals())
 
     # finally use all the check to decide binary or text
     decodable_as_unicode = False
-    if (detected_encoding['confidence'] > 0.9
-        and detected_encoding['encoding'] != 'ascii'):
+    if (detected_encoding['confidence'] > 0.9 and
+            detected_encoding['encoding'] != 'ascii'):
         try:
             try:
                 bytes_to_check.decode(encoding=detected_encoding['encoding'])
             except TypeError:
                 # happens only on Python 2.6
-                unicode(bytes_to_check, encoding=detected_encoding['encoding'])
+                unicode(bytes_to_check, encoding=detected_encoding['encoding'])  # noqa
             decodable_as_unicode = True
             logger.debug('success: decodable_as_unicode: '
-                         '%(decodable_as_unicode)r' % locals())
+                         '%(decodable_as_unicode)r', locals())
         except LookupError:
-            logger.debug('failure: could not look up encoding %(encoding)s' %
+            logger.debug('failure: could not look up encoding %(encoding)s',
                          detected_encoding)
         except UnicodeDecodeError:
             logger.debug('failure: decodable_as_unicode: '
-                         '%(decodable_as_unicode)r' % locals())
+                         '%(decodable_as_unicode)r', locals())
 
     logger.debug('failure: decodable_as_unicode: '
-                 '%(decodable_as_unicode)r' % locals())
+                 '%(decodable_as_unicode)r', locals())
     if is_likely_binary:
         if decodable_as_unicode:
             return False
diff --git a/setup.py b/setup.py
index a0ee5e3..68a4f5b 100755
--- a/setup.py
+++ b/setup.py
@@ -1,33 +1,36 @@
 #!/usr/bin/env python
 
-import os
-import sys
-
-import binaryornot
+import sys, os
 
 try:
     from setuptools import setup
 except ImportError:
     from distutils.core import setup
 
+with open('README.rst') as readme_file:
+    readme = readme_file.read()
 
-# Python 2.6 does not have expectedFailre, unittest2 is a backport
-tests_require = ['hypothesis']
-try:
-    from unittest.case import expectedFailure
-except ImportError:
-    tests_require.append('unittest2')
+with open('HISTORY.rst') as history_file:
+    history = history_file.read().replace('.. :changelog:', '')
+
+version = '0.4.3'
 
-readme = open('README.rst').read()
-history = open('HISTORY.rst').read().replace('.. :changelog:', '')
+if sys.argv[-1] == 'publish':
+    os.system('python setup.py sdist bdist_wheel upload')
+    os.system("git tag -a %s -m 'version %s'" % (version, version))
+    os.system("git push --tags")
+    sys.exit()
 
 setup(
     name='binaryornot',
-    version='0.4.0',
-    description='Ultra-lightweight pure Python package to check if a file is binary or text.',
+    version=version,
+    description=(
+        'Ultra-lightweight pure Python package to check '
+        'if a file is binary or text.'
+    ),
     long_description=readme + '\n\n' + history,
-    author='Audrey Roy',
-    author_email='audreyr at gmail.com',
+    author='Audrey Roy Greenfeld',
+    author_email='aroy at alum.mit.edu',
     url='https://github.com/audreyr/binaryornot',
     packages=[
         'binaryornot',
@@ -35,22 +38,23 @@ setup(
     package_dir={'binaryornot': 'binaryornot'},
     include_package_data=True,
     install_requires=[
-        'chardet>=2.0.0',
+        'chardet>=3.0.2',
     ],
-    tests_require = tests_require,
     license="BSD",
     zip_safe=False,
     keywords='binaryornot',
     classifiers=[
-        'Development Status :: 4 - Beta',
+        'Development Status :: 5 - Production/Stable',
         'Intended Audience :: Developers',
         'License :: OSI Approved :: BSD License',
         'Natural Language :: English',
-        "Programming Language :: Python :: 2",
-        'Programming Language :: Python :: 2.6',
+        'Programming Language :: Python :: 2',
         'Programming Language :: Python :: 2.7',
         'Programming Language :: Python :: 3',
         'Programming Language :: Python :: 3.3',
+        'Programming Language :: Python :: 3.4',
+        'Programming Language :: Python :: 3.5',
+        'Programming Language :: Python :: 3.6',
     ],
     test_suite='tests',
 )
diff --git a/tasks.py b/tasks.py
index 508071e..4b336ba 100644
--- a/tasks.py
+++ b/tasks.py
@@ -1,42 +1,50 @@
 from invoke import task, run
 
+
 @task
 def clean_docs():
     run("rm -rf docs/_build")
     run("rm -rf docs/binaryornot.rst")
     run("rm -rf docs/modules.rst")
 
+
 @task('clean_docs')
 def docs():
     run("sphinx-apidoc -o docs/ binaryornot/")
     run("sphinx-build docs docs/_build")
     run("open docs/_build/index.html")
 
+
 @task
 def flake8():
     run("flake8 binaryornot tests")
 
+
 @task
 def autopep8():
     run("autopep8 --in-place --aggressive -r binaryornot")
     run("autopep8 --in-place --aggressive -r tests")
 
+
 @task
 def test():
     run("python setup.py test")
 
+
 @task
 def coverage():
-	run("coverage run --source binaryornot setup.py test")
-	run("coverage report -m")
-	run("coverage html")
-	run("open htmlcov/index.html")
+    run("coverage run --source binaryornot setup.py test")
+    run("coverage report -m")
+    run("coverage html")
+    run("open htmlcov/index.html")
+
 
 @task
 def clean_build():
-	run("rm -fr build/")
-	run("rm -fr dist/")
-	run("rm -fr *.egg-info")
+    run("rm -fr build/")
+    run("rm -fr dist/")
+    run("rm -fr *.egg-info")
+
 
 @task
 def clean_pyc():
@@ -44,11 +52,13 @@ def clean_pyc():
     run("find . -name '*.pyo' -exec rm -f {} +")
     run("find . -name '*~' -exec rm -f {} +")
 
+
 @task('clean_build', 'clean_pyc')
 def sdist():
     run("python setup.py sdist")
     run("ls -l dist")
 
+
 @task('sdist')
 def release():
     run("python setup.py upload")
diff --git a/tests/files/empty.pyc b/tests/files/empty.pyc
new file mode 100644
index 0000000..efbc959
Binary files /dev/null and b/tests/files/empty.pyc differ
diff --git a/tests/files/hello_world.py b/tests/files/hello_world.py
new file mode 100644
index 0000000..75d9766
--- /dev/null
+++ b/tests/files/hello_world.py
@@ -0,0 +1 @@
+print('hello world')
diff --git a/tests/files/hello_world.pyc b/tests/files/hello_world.pyc
new file mode 100644
index 0000000..d53535d
Binary files /dev/null and b/tests/files/hello_world.pyc differ
diff --git a/tests/files/troublesome.pyc b/tests/files/troublesome.pyc
new file mode 100644
index 0000000..3ff6ad9
Binary files /dev/null and b/tests/files/troublesome.pyc differ
diff --git a/tests/test_check.py b/tests/test_check.py
index 338119e..1ea31a4 100755
--- a/tests/test_check.py
+++ b/tests/test_check.py
@@ -30,39 +30,39 @@ logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
 
 
 class TestIsBinary(unittest.TestCase):
+    """Test is_binary() with various files."""
 
     def test_empty(self):
         self.assertFalse(is_binary('tests/files/empty.txt'))
 
-    def test_css(self):
-        self.assertFalse(is_binary('tests/files/bootstrap-glyphicons.css'))
-
-    def test_json(self):
-        self.assertFalse(is_binary('tests/files/cookiecutter.json'))
-
     def test_triggers_decoding_error(self):
         self.assertTrue(is_binary('tests/files/decoding-error'))
 
     def test_triggers_lookup_error(self):
         self.assertTrue(is_binary('tests/files/lookup-error'))
 
-    def test_png(self):
-        self.assertTrue(is_binary('tests/files/logo.png'))
+    def test_ds_store(self):
+        self.assertTrue(is_binary('tests/files/.DS_Store'))
 
-    def test_gif(self):
-        self.assertTrue(is_binary('tests/files/lena.gif'))
+    def test_txt(self):
+        self.assertFalse(is_binary('tests/files/robots.txt'))
 
-    def test_jpg(self):
-        self.assertTrue(is_binary('tests/files/lena.jpg'))
+    def test_txt_unicode(self):
+        self.assertFalse(is_binary('tests/files/unicode.txt'))
 
-    def test_tiff(self):
-        self.assertTrue(is_binary('tests/files/palette-1c-8b.tiff'))
+    @expectedFailure
+    def test_binary_pdf2(self):
+        self.assertTrue(is_binary('tests/isBinaryFile/pdf.pdf'))
 
-    def test_bmp(self):
-        self.assertTrue(is_binary('tests/files/rgb-3c-8b.bmp'))
+    def test_text_russian2(self):
+        self.assertFalse(is_binary('tests/isBinaryFile/russian_file.rst'))
 
-    def test_ds_store(self):
-        self.assertTrue(is_binary('tests/files/.DS_Store'))
+    def test_binary_exe2(self):
+        self.assertTrue(is_binary('tests/isBinaryFile/grep'))
+
+
+class TestFontFiles(unittest.TestCase):
+    """Test is_binary() with various font file types."""
 
     def test_eot(self):
         self.assertTrue(
@@ -72,10 +72,6 @@ class TestIsBinary(unittest.TestCase):
         self.assertTrue(
             is_binary('tests/files/glyphiconshalflings-regular.otf'))
 
-    def test_svg(self):
-        self.assertFalse(
-            is_binary('tests/files/glyphiconshalflings-regular.svg'))
-
     def test_ttf(self):
         self.assertTrue(
             is_binary('tests/files/glyphiconshalflings-regular.ttf'))
@@ -84,14 +80,27 @@ class TestIsBinary(unittest.TestCase):
         self.assertTrue(
             is_binary('tests/files/glyphiconshalflings-regular.woff'))
 
-    def test_txt(self):
-        self.assertFalse(is_binary('tests/files/robots.txt'))
 
-    def test_txt_unicode(self):
-        self.assertFalse(is_binary('tests/files/unicode.txt'))
+class TestImageFiles(unittest.TestCase):
+    """Test is_binary() with various image file types."""
 
-    def test_text_js(self):
-        self.assertFalse(is_binary('tests/isBinaryFile/index.js'))
+    def test_png(self):
+        self.assertTrue(is_binary('tests/files/logo.png'))
+
+    def test_gif(self):
+        self.assertTrue(is_binary('tests/files/lena.gif'))
+
+    def test_jpg(self):
+        self.assertTrue(is_binary('tests/files/lena.jpg'))
+
+    def test_tiff(self):
+        self.assertTrue(is_binary('tests/files/palette-1c-8b.tiff'))
+
+    def test_bmp(self):
+        self.assertTrue(is_binary('tests/files/rgb-3c-8b.bmp'))
+
+    def test_binary_rgb_stream(self):
+        self.assertTrue(is_binary('tests/files/pixelstream.rgb'))
 
     def test_binary_gif2(self):
         self.assertFalse(is_binary('tests/isBinaryFile/null_file.gif'))
@@ -99,45 +108,43 @@ class TestIsBinary(unittest.TestCase):
     def test_binary_gif3(self):
         self.assertTrue(is_binary('tests/isBinaryFile/trunks.gif'))
 
-    def test_text_lua(self):
-        self.assertFalse(is_binary('tests/isBinaryFile/no.lua'))
-
-    @expectedFailure
-    def test_binary_pdf2(self):
-        self.assertTrue(is_binary('tests/isBinaryFile/pdf.pdf'))
-
-    def test_text_perl2(self):
-        self.assertFalse(is_binary('tests/isBinaryFile/perl_script'))
+    def test_svg(self):
+        self.assertFalse(
+            is_binary('tests/files/glyphiconshalflings-regular.svg'))
 
-    def test_text_russian2(self):
-        self.assertFalse(is_binary('tests/isBinaryFile/russian_file.rst'))
 
-    def test_binary_exe2(self):
-        self.assertTrue(is_binary('tests/isBinaryFile/grep'))
+class TestEncodings(unittest.TestCase):
+    """Test is_binary() with files containing various encodings."""
 
     def test_text_utf16(self):
-        self.assertFalse(is_binary('tests/isBinaryFile/encodings/bom_utf-16.txt'))
+        self.assertFalse(
+            is_binary('tests/isBinaryFile/encodings/bom_utf-16.txt'))
 
     def test_text_utf16le(self):
-        self.assertFalse(is_binary('tests/isBinaryFile/encodings/bom_utf-16le.txt'))
+        self.assertFalse(
+            is_binary('tests/isBinaryFile/encodings/bom_utf-16le.txt'))
 
     def test_text_utf16be(self):
-        self.assertFalse(is_binary('tests/isBinaryFile/encodings/test-utf16be.txt'))
+        self.assertFalse(
+            is_binary('tests/isBinaryFile/encodings/test-utf16be.txt'))
 
     def test_text_utf32le(self):
-        self.assertFalse(is_binary('tests/isBinaryFile/encodings/bom_utf-32le.txt'))
+        self.assertFalse(
+            is_binary('tests/isBinaryFile/encodings/bom_utf-32le.txt'))
 
     def test_text_utf82(self):
         self.assertFalse(is_binary('tests/isBinaryFile/encodings/utf_8.txt'))
 
     def test_text_gb2(self):
-        self.assertFalse(is_binary('tests/isBinaryFile/encodings/test-gb2.txt'))
+        self.assertFalse(
+            is_binary('tests/isBinaryFile/encodings/test-gb2.txt'))
 
     def test_text_kr(self):
         self.assertFalse(is_binary('tests/isBinaryFile/encodings/test-kr.txt'))
 
     def test_text_latin(self):
-        self.assertFalse(is_binary('tests/isBinaryFile/encodings/test-latin.txt'))
+        self.assertFalse(
+            is_binary('tests/isBinaryFile/encodings/test-latin.txt'))
 
     def test_text_big5(self):
         self.assertFalse(is_binary('tests/isBinaryFile/encodings/big5.txt'))
@@ -146,22 +153,55 @@ class TestIsBinary(unittest.TestCase):
         self.assertFalse(is_binary('tests/isBinaryFile/encodings/test-gb.txt'))
 
     def test_text_utf32(self):
-        self.assertFalse(is_binary('tests/isBinaryFile/encodings/bom_utf-32.txt'))
+        self.assertFalse(
+            is_binary('tests/isBinaryFile/encodings/bom_utf-32.txt'))
 
     def test_text_utf8(self):
-        self.assertFalse(is_binary('tests/isBinaryFile/encodings/bom_utf-8.txt'))
+        self.assertFalse(
+            is_binary('tests/isBinaryFile/encodings/bom_utf-8.txt'))
 
     def test_text_big5b(self):
         self.assertFalse(is_binary('tests/isBinaryFile/encodings/big5_B.txt'))
 
     def test_text_shishi(self):
-        self.assertFalse(is_binary('tests/isBinaryFile/encodings/test-shishi.txt'))
+        self.assertFalse(
+            is_binary('tests/isBinaryFile/encodings/test-shishi.txt'))
 
     def test_text_utfcn(self):
         self.assertFalse(is_binary('tests/isBinaryFile/encodings/utf8cn.txt'))
 
-    def test_binary_rgb_stream(self):
-        self.assertTrue(is_binary('tests/files/pixelstream.rgb'))
+
+class TestCodeFiles(unittest.TestCase):
+    """Test is_binary() with various code file types."""
+
+    def test_css(self):
+        self.assertFalse(is_binary('tests/files/bootstrap-glyphicons.css'))
+
+    def test_json(self):
+        self.assertFalse(is_binary('tests/files/cookiecutter.json'))
+
+    def test_text_perl2(self):
+        self.assertFalse(is_binary('tests/isBinaryFile/perl_script'))
+
+    def test_text_js(self):
+        self.assertFalse(is_binary('tests/isBinaryFile/index.js'))
+
+    def test_text_lua(self):
+        self.assertFalse(is_binary('tests/isBinaryFile/no.lua'))
+
+
+class TestProgrammingArtifacts(unittest.TestCase):
+    """Test is_binary() with various leftover byproducts from running or
+    building programs."""
+
+    def test_binary_pyc(self):
+        self.assertTrue(is_binary('tests/files/hello_world.pyc'))
+
+    def test_binary_empty_pyc(self):
+        self.assertTrue(is_binary('tests/files/empty.pyc'))
+
+    def test_binary_troublesome_pyc(self):
+        self.assertTrue(is_binary('tests/files/troublesome.pyc'))
 
 
 @contextmanager
diff --git a/tox.ini b/tox.ini
index 5c8318a..8f71f95 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,7 +1,6 @@
 [tox]
-envlist = py26, py27, py33, py34, pypy
+envlist = py27, py33, py34, py35, py36, pypy
 
 [testenv]
-setenv =
-    PYTHONPATH = {toxinidir}:{toxinidir}/binaryornot
 commands = python setup.py test
+deps = hypothesis

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/binaryornot.git



More information about the Python-modules-commits mailing list