-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Python 2/3 compatibility from imread (#48)
* Refactor `_pycompat` from `imread.__init__` Pulls out some Python 2/3 support content from `imread.__init__` into `_pycompat`. Cleans up the `imread` function a bit as a result. * Test Python 2/3 compatibility functions Provide some basic tests of the Python 2/3 compatibility functions for `imread` to make sure they work as expected on both Python versions.
- Loading branch information
Showing
3 changed files
with
38 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
try: | ||
irange = xrange | ||
except NameError: | ||
irange = range | ||
|
||
try: | ||
from itertools import izip | ||
except ImportError: | ||
izip = zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
|
||
from __future__ import absolute_import | ||
|
||
import dask_image.imread._pycompat | ||
|
||
|
||
def test_irange(): | ||
r = dask_image.imread._pycompat.irange(5) | ||
|
||
assert not isinstance(r, list) | ||
|
||
assert list(r) == [0, 1, 2, 3, 4] | ||
|
||
|
||
def test_izip(): | ||
r = dask_image.imread._pycompat.izip([1, 2], [3, 4, 5]) | ||
|
||
assert not isinstance(r, list) | ||
|
||
assert list(r) == [(1, 3), (2, 4)] |