Gustavo Picon avatar Gustavo Picon committed f43ea30

Now using pytest for the test suite, and distribute/setuptools instead of distutils

Comments (0)

Files changed (8)

+[run]
+branch = True
+source = numconv
+parallel = True
+
+[paths]
+source =
+    ./
+    */.tox/*/site-packages/
+    */__pyclasspath__/
 *.orig
 *.swp
 .coverage
+.coverage.*
 build
 dist
 _build
 .settings
 htmlcov
 taggable/fixtures/create_fixtures.py
+.tox
+*.xml
+*.class
+*.egg-info
+*.egg/*
+*.egg
-include LICENSE NOTICE README
-recursive-include docs *
-
+include LICENSE NOTICE README MANIFEST.in tox.ini .coveragerc *.py
+recursive-include docs Makefile *.py *.rst
+import os
+import sys
+
+sys.path.insert(0, os.path.dirname(__file__))
 Installation
 ------------
 
-``numconv`` has been tested in Python 2.4, 2.5, 2.6, 2.7, 3.0 and 3.1. Other
-versions may work but are not supported.
+``numconv`` has been tested in Python 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2,
+PyPy 1.4 and Jython 2.5. Other versions may work but are not supported.
 
 You have several ways to install ``numconv``. If you're not sure,
 `just use pip <http://guide.python-distribute.org/pip.html>`_
 #!/usr/bin/env python
 
 import os
-from distutils.core import setup
+from setuptools import setup
+from setuptools.command.test import test
 
-version = '2.1.1'
 
-classifiers = [
-    "Development Status :: 5 - Production/Stable",
-    "Intended Audience :: Developers",
-    "License :: OSI Approved :: Apache Software License",
-    "Programming Language :: Python",
-    "Programming Language :: Python :: 2.4",
-    "Programming Language :: Python :: 2.5",
-    "Programming Language :: Python :: 2.6",
-    "Programming Language :: Python :: 2.7",
-    "Programming Language :: Python :: 3",
-    "Programming Language :: Python :: 3.0",
-    "Programming Language :: Python :: 3.1",
-    "Operating System :: OS Independent",
-    "Topic :: Software Development :: Libraries",
-]
+def root_dir():
+    rd = os.path.dirname(__file__)
+    if rd:
+        return rd
+    return '.'
 
-root_dir = os.path.dirname(__file__)
-if not root_dir:
-    root_dir = '.'
-long_desc = open(root_dir + '/README').read()
 
-setup(
+class pytest_test(test):
+    def finalize_options(self):
+        test.finalize_options(self)
+        self.test_args = []
+        self.test_suite = True
+
+    def run_tests(self):
+        import pytest
+        pytest.main([])
+
+
+setup_args = dict(
     name='numconv',
-    version=version,
+    version='2.1.2-dev',
     url='https://tabo.pe/projects/numconv/',
     author='Gustavo Picon',
     author_email='tabo@tabo.pe',
     py_modules=['numconv'],
     description='Python library to convert strings to numbers '
                 'and numbers to strings.',
-    classifiers=classifiers,
-    long_description=long_desc,
-)
+    long_description=open(root_dir() + '/README').read(),
+    cmdclass={'test': pytest_test},
+    tests_require=['pytest'],
+    classifiers=[
+        'Development Status :: 5 - Production/Stable',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: Apache Software License',
+        'Programming Language :: Python',
+        'Programming Language :: Python :: 2.4',
+        'Programming Language :: Python :: 2.5',
+        'Programming Language :: Python :: 2.6',
+        'Programming Language :: Python :: 2.7',
+        'Programming Language :: Python :: 3',
+        'Programming Language :: Python :: 3.0',
+        'Programming Language :: Python :: 3.1',
+        'Programming Language :: Python :: 3.2',
+        'Operating System :: OS Independent',
+        'Topic :: Software Development :: Libraries'])
+
+if __name__ == '__main__':
+    setup(**setup_args)
 """Test numconv.py"""
 
 from numconv import NumConv, int2str, str2int, BASE85
-import unittest
+import pytest
 
 
-class BaseconvI2s(unittest.TestCase):
-    """tests for int2str()"""
+@pytest.mark.parametrize(("num", "radix", "expected"), [
+    (3735928559, 16, 'DEADBEEF'),
+    (238327, 62, 'zzz'),
+    (14776335, 62, 'zzzz'),
+    (466, 7, '1234'),
+    (151880, 2, '100101000101001000'),
+    (2693233728041137, 85, '~123AFz@'),
+    (543543, 40, '8JSN'),
+    (1949459, 61, '8ZtL'),
+    (19284, 2, '100101101010100')])
+def test_int2str(num, radix, expected):
+    assert int2str(num, radix) == expected
 
-    def test_i2s(self):
-        """testing int2str: expected values"""
-        self.assertEqual(int2str(3735928559, 16), 'DEADBEEF')
-        self.assertEqual(int2str(238327, 62), 'zzz')
-        self.assertEqual(int2str(14776335, 62), 'zzzz')
-        self.assertEqual(int2str(466, 7), '1234')
-        self.assertEqual(int2str(151880, 2), '100101000101001000')
-        self.assertEqual(int2str(2693233728041137, 85), '~123AFz@')
-        self.assertEqual(int2str(543543, 40), '8JSN')
-        self.assertEqual(int2str(1949459, 61), '8ZtL')
-        self.assertEqual(int2str(19284, 2), '100101101010100')
-        self.assertEqual(int2str(100, 10, 'abcdefghijklm'), 'baa')
-        self.assertEqual(int2str(37, 4, 'rofl'), 'foo')
 
-    def test_i2s_nonint_number(self):
-        """testing int2str: error on non-integer number"""
-        self.assertRaises(TypeError, int2str, 0.1, 8)
+def test_int2str_with_radix_and_alphabet():
+    assert int2str(37, 4, 'rofl') == 'foo'
 
-    def test_i2s_nonint_radix(self):
-        """testing int2str: error on non-integer radix"""
-        self.assertRaises(TypeError, int2str, 100, 0.1)
 
-    def test_i2s_invalid_radix(self):
-        """testing int2str: error on invalid radix"""
-        self.assertRaises(ValueError, int2str, 100, -10)
-        self.assertRaises(ValueError, int2str, 100, 10, 'abcde')
+def test_int2str_with_alphabet():
+    assert int2str(100, alphabet='abcdefghijklm') == 'baa'
 
-    def test_i2s_negative_number(self):
-        """testing int2str: error on negative number"""
-        self.assertRaises(ValueError, int2str, -100, 10)
 
+def test_int2str_nonint_number():
+    pytest.raises(TypeError, int2str, 0.1, 8)
 
-class BaseconvS2i(unittest.TestCase):
-    """tests for str2int()"""
 
-    def test_s2i(self):
-        """testing str2int: expected values"""
-        self.assertEqual(str2int('DEADBEEF', 16), 3735928559)
-        self.assertEqual(str2int('zzz', 62), 238327)
-        self.assertEqual(str2int('zzzz', 62), 14776335)
-        self.assertEqual(str2int('1234', 7), 466)
-        self.assertEqual(str2int('100101000101001000', 2), 151880)
-        self.assertEqual(str2int('~123AFz@', 85), 2693233728041137)
-        self.assertEqual(str2int('8JSN', 40), 543543)
-        self.assertEqual(str2int('8ZtL', 61), 1949459)
-        self.assertEqual(str2int('100101101010100', 2), 19284)
-        self.assertEqual(str2int('baa', 10, 'abcdefghijklm'), 100)
-        self.assertEqual(str2int('foo', 4, 'rofl'), 37)
+def test_int2str_nonint_radix():
+    pytest.raises(TypeError, int2str, 100, 0.1)
 
-    def test_s2i_nonint_base(self):
-        """testing str2int: error on non-integer base"""
-        self.assertRaises(TypeError, str2int, '100', 0.1)
 
-    def test_s2i_bad_number(self):
-        """testing str2int: error on invalid number"""
-        # raised by python
-        self.assertRaises(ValueError, str2int, '1234z', 8)
-        # raised by numconv.py
-        self.assertRaises(ValueError, str2int, '1234z', 37)
+def test_int2str_negative_radix():
+    pytest.raises(ValueError, int2str, 100, -10)
 
-    def test_s2i_invalid_radix(self):
-        """testing str2int: error on invalid radix"""
-        self.assertRaises(ValueError, str2int, 'abcd', -10)
 
+def test_int2str_big_radix():
+    # the radix (10) is too big for a dictionary of 5 characters
+    pytest.raises(ValueError, int2str, 100, 10, "abcde")
 
-class BaseconvCmap(unittest.TestCase):
-    """tests for getcmap()"""
 
-    def test_get_cmap(self):
-        """testing get_cmap: expected values"""
-        self.assertEqual(NumConv(alphabet='0123456789').cached_map,
-            {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4,
-             '5': 5, '6': 6, '7': 7, '8': 8, '9': 9})
-        self.assertEqual(NumConv(radix=4, alphabet='abcd').cached_map,
-            {'a': 0, 'b': 1, 'c': 2, 'd': 3})
+def test_int2str_negative_number():
+    pytest.raises(ValueError, int2str, -100)
 
-    def test_getcmap_dupechars(self):
-        """testing getcmap: error on alphabet with duplicate chars"""
-        self.assertRaises(ValueError, NumConv, 6, 'abcdaf')
 
+@pytest.mark.parametrize(("num", "radix", "expected"), [
+    ('DEADBEEF', 16, 3735928559),
+    ('zzz', 62, 238327),
+    ('zzzz', 62, 14776335),
+    ('1234', 7, 466),
+    ('100101000101001000', 2, 151880),
+    ('~123AFz@', 85, 2693233728041137),
+    ('8JSN', 40, 543543),
+    ('8ZtL', 61, 1949459),
+    ('100101101010100', 2, 19284)])
+def test_str2int(num, radix, expected):
+    assert str2int(num, radix) == expected
 
-class BaseconvSanity(unittest.TestCase):
-    """sanity checks"""
 
-    def test_sanity(self):
-        """sanity check: testing a large interval and lots of radixes"""
-        for radix in range(2, len(BASE85)):
-            ncobj = NumConv(radix)
-            for num in list(range(1000)) + [10 ** x for x in range(5, 15)]:
-                self.assertEqual(num, ncobj.str2int(ncobj.int2str(num)))
+def test_str2int_with_radix_and_alphabet():
+    assert str2int('foo', 4, 'rofl') == 37
 
-if __name__ == "__main__":
-    unittest.main()
+
+def test_str2int_with_alphabet():
+    assert str2int('baa', alphabet='abcdefghijklm') == 100
+
+
+def test_str2int_nonint_base():
+    pytest.raises(TypeError, str2int, '100', 0.1)
+
+
+def test_str2int_bad_number_raised_by_python():
+    pytest.raises(ValueError, str2int, '1234z', 8)
+
+
+def test_str2int_bad_number_raised_by_numconv():
+    pytest.raises(ValueError, str2int, '1234z', 37)
+
+
+def test_str2int_negative_radix():
+    pytest.raises(ValueError, str2int, 'abcd', -10)
+
+
+def test_cached_map_alphabet_with_numbers():
+    expected = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4,
+                '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
+    assert NumConv(alphabet='0123456789').cached_map == expected
+
+
+def test_cached_map_alphabet_with_letters():
+    expected = {'a': 0, 'b': 1, 'c': 2, 'd': 3}
+    assert NumConv(radix=4, alphabet='abcd').cached_map == expected
+
+
+def test_cached_map_alphabet_with_duplicate_characters():
+    pytest.raises(ValueError, NumConv, 6, 'abcdaf')
+
+
+def test_sanity():
+    """sanity check: testing a large interval and lots of radixes"""
+    for radix in range(2, len(BASE85)):
+        ncobj = NumConv(radix)
+        for num in list(range(100)) + [10 ** x for x in range(3, 15)]:
+            assert num == ncobj.str2int(ncobj.int2str(num))
+[tox]
+envlist = py24, py25, py26, py27, py31, py32, pypy, jython
+
+[testenv]
+deps = pytest
+       coverage
+commands =
+    {envbindir}/coverage run \
+        {envbindir}/py.test \
+            --junitxml junit-{envname}.xml \
+            {posargs}
+
+[testenv:jython]
+commands =
+    {envbindir}/coverage run \
+        {envbindir}/py.test-jython \
+            --junitxml junit-{envname}.xml \
+            {posargs}
+
+[testenv:docs]
+changedir = docs
+deps = sphinx
+commands =
+    make clean
+    make html
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.