1
0
mirror of https://github.com/scrapy/scrapy.git synced 2025-02-25 03:04:06 +00:00
scrapy/tests/test_utils_gz.py

30 lines
948 B
Python
Raw Normal View History

import unittest
from os.path import join
from scrapy.utils.gz import gunzip
2014-08-01 02:25:33 -03:00
from tests import tests_datadir
SAMPLEDIR = join(tests_datadir, 'compressed')
2014-08-01 02:25:33 -03:00
2015-08-28 02:12:36 +05:00
class GunzipTest(unittest.TestCase):
def test_gunzip_basic(self):
with open(join(SAMPLEDIR, 'feed-sample1.xml.gz'), 'rb') as f:
text = gunzip(f.read())
self.assertEqual(len(text), 9950)
def test_gunzip_truncated(self):
with open(join(SAMPLEDIR, 'truncated-crc-error.gz'), 'rb') as f:
text = gunzip(f.read())
2014-08-01 02:25:33 -03:00
assert text.endswith(b'</html')
def test_gunzip_no_gzip_file_raises(self):
with open(join(SAMPLEDIR, 'feed-sample1.xml'), 'rb') as f:
self.assertRaises(IOError, gunzip, f.read())
2012-10-10 12:21:59 +03:00
def test_gunzip_truncated_short(self):
with open(join(SAMPLEDIR, 'truncated-crc-error-short.gz'), 'rb') as f:
text = gunzip(f.read())
2014-08-01 02:25:33 -03:00
assert text.endswith(b'</html>')