Skip to content

Commit 027c610

Browse files
committed
Switch from nose (unmaintained) to nose2, use parametrized tests, fix flake8 nits
1 parent 81f55d3 commit 027c610

File tree

5 files changed

+18
-16
lines changed

5 files changed

+18
-16
lines changed

.github/workflows/test_and_release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ jobs:
5252
run: |
5353
python -m pip install --upgrade pip
5454
if [ -f requirements-test.txt ]; then pip install -r requirements-test.txt; fi
55+
sudo apt update
5556
sudo apt install -qq openjdk-11-jre # JDK is needed to run tests
5657
- name: Test
5758
run: |
58-
python setup.py test
59+
python setup.py build
60+
nose2 -v --pretty-assert
5961
6062
# https://github.com/actions/starter-workflows/blob/main/ci/python-publish.yml
6163
release:

requirements-test.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
nose>=1.0
1+
nose2>=0.10
22

33
pillow>=3.0,<6.0; python_version < '3.5'
44
pillow>=3.0,<8.0; python_version >= '3.5' and python_version < '3.6'

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def download_java_files(force=False):
6363
},
6464
install_requires=open('requirements.txt').readlines(),
6565
tests_require=open('requirements-test.txt').readlines(),
66-
test_suite='nose.collector',
66+
test_suite='nose2.collector.collector',
6767
license='LGPL v3 or later',
6868
classifiers=[
6969
'Development Status :: 4 - Beta',

test/test_all.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from PIL import Image
66

7-
from nose import with_setup
8-
from nose.tools import raises
7+
from nose2.tools.decorators import with_setup
8+
from nose2.tools.such import helper
99

1010
import zxing
1111

@@ -119,27 +119,27 @@ def test_wrong_formats():
119119
for filename, expected_format, expected_raw in test_barcodes)
120120

121121

122-
@raises(zxing.BarCodeReaderException)
123122
def test_bad_java():
124123
test_reader = zxing.BarCodeReader(java=os.devnull)
125-
test_reader.decode(test_barcodes[0][0])
124+
with helper.assertRaises(zxing.BarCodeReaderException):
125+
test_reader.decode(test_barcodes[0][0])
126126

127127

128-
@raises(zxing.BarCodeReaderException)
129128
def test_bad_classpath():
130129
test_reader = zxing.BarCodeReader(classpath=mkdtemp())
131-
test_reader.decode(test_barcodes[0][0])
130+
with helper.assertRaises(zxing.BarCodeReaderException):
131+
test_reader.decode(test_barcodes[0][0])
132132

133133

134-
@raises(zxing.BarCodeReaderException)
135134
@with_setup(setup_reader)
136135
def test_nonexistent_file_error():
137136
global test_reader
138-
test_reader.decode(os.path.join(test_barcode_dir, 'nonexistent.png'))
137+
with helper.assertRaises(zxing.BarCodeReaderException):
138+
test_reader.decode(os.path.join(test_barcode_dir, 'nonexistent.png'))
139139

140140

141-
@raises(zxing.BarCodeReaderException)
142141
@with_setup(setup_reader)
143142
def test_bad_file_format_error():
144143
global test_reader
145-
test_reader.decode(os.path.join(test_barcode_dir, 'bad_format.png'))
144+
with helper.assertRaises(zxing.BarCodeReaderException):
145+
test_reader.decode(os.path.join(test_barcode_dir, 'bad_format.png'))

zxing/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def file_uri_to_path(s):
3030
raise ValueError(uri)
3131
return urllib.parse.unquote_plus(uri.path)
3232

33-
3433
class BarCodeReaderException(Exception):
3534
def __init__(self, message, filename=None):
3635
self.message, self.filename = message, filename
@@ -104,9 +103,10 @@ def decode(self, filenames, try_harder=False, possible_formats=None, pure_barcod
104103
b'Exception in thread "main" java.lang.NoClassDefFoundError:')):
105104
raise BarCodeReaderException("Java JARs not found in classpath (%s)" % self.classpath, self.classpath)
106105
elif stdout.startswith((b'''Exception in thread "main" javax.imageio.IIOException: Can't get input stream from URL!''',
107-
b'''Exception in thread "main" java.util.concurrent.ExecutionException: javax.imageio.IIOException: Can't get input stream from URL!''')):
106+
b'''Exception in thread "main" java.util.concurrent.ExecutionException: javax.imageio.IIOException: Can't get input stream from URL!''')): # noqa: E501
108107
# Find the line that looks like: "Caused by: java.io.FileNotFoundException: $FILENAME ({No such file or directory,Permission denied,*)"
109-
fn, err = next((map(bytes.decode, l[42:].rsplit(b' (', 1)) for l in stdout.splitlines() if l.startswith(b"Caused by: java.io.FileNotFoundException: ")), ('', ''))
108+
fn, err = next((map(bytes.decode, l[42:].rsplit(b' (', 1)) for l in stdout.splitlines()
109+
if l.startswith(b"Caused by: java.io.FileNotFoundException: ")), ('', ''))
110110
if err == 'No such file or directory)':
111111
err = FileNotFoundError(fn)
112112
elif err == 'Permission denied)':

0 commit comments

Comments
 (0)