1
0
mirror of https://github.com/scrapy/scrapy.git synced 2025-02-23 04:23:47 +00:00
scrapy/tests/test_utils_gz.py
2014-07-30 19:45:08 -03:00

29 lines
941 B
Python

import unittest
from os.path import join
from tests import tests_datadir
from scrapy.utils.gz import gunzip
SAMPLEDIR = join(tests_datadir, 'compressed')
class GzTest(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())
assert text.endswith('</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())
def test_gunzip_truncated_short(self):
with open(join(SAMPLEDIR, 'truncated-crc-error-short.gz'), 'rb') as f:
text = gunzip(f.read())
assert text.endswith('</html>')