|
20 | 20 | from nose.tools import (assert_true, assert_false, assert_equal,
|
21 | 21 | assert_not_equal, assert_raises)
|
22 | 22 | from ..testing import error_warnings
|
| 23 | +import mock |
23 | 24 |
|
24 | 25 |
|
25 | 26 | class Lunk(object):
|
@@ -95,6 +96,35 @@ def test_BinOpener():
|
95 | 96 | BinOpener, 'test.txt', 'r')
|
96 | 97 |
|
97 | 98 |
|
| 99 | +def test_Opener_gzip_type(): |
| 100 | + # Test that BufferedGzipFile or IndexedGzipFile are used as appropriate |
| 101 | + |
| 102 | + data = 'this is some test data' |
| 103 | + fname = 'test.gz' |
| 104 | + mockmod = mock.MagicMock() |
| 105 | + |
| 106 | + class MockClass(object): |
| 107 | + def __init__(self, *args, **kwargs): |
| 108 | + pass |
| 109 | + |
| 110 | + with InTemporaryDirectory(): |
| 111 | + |
| 112 | + # make some test data |
| 113 | + with GzipFile(fname, mode='wb') as f: |
| 114 | + f.write(data.encode()) |
| 115 | + |
| 116 | + # test with indexd_gzip not present |
| 117 | + with mock.patch.dict('sys.modules', {'indexed_gzip' : None}): |
| 118 | + assert isinstance(Opener(fname, mode='rb').fobj, GzipFile) |
| 119 | + assert isinstance(Opener(fname, mode='wb').fobj, GzipFile) |
| 120 | + |
| 121 | + # test with indexd_gzip present |
| 122 | + with mock.patch.dict('sys.modules', {'indexed_gzip' : mockmod}), \ |
| 123 | + mock.patch('indexed_gzip.SafeIndexedGzipFile', MockClass): |
| 124 | + assert isinstance(Opener(fname, mode='rb').fobj, MockClass) |
| 125 | + assert isinstance(Opener(fname, mode='wb').fobj, GzipFile) |
| 126 | + |
| 127 | + |
98 | 128 | class TestImageOpener:
|
99 | 129 |
|
100 | 130 | def setUp(self):
|
|
0 commit comments