This commit is contained in:
Andy McKay 2011-10-06 17:11:41 -07:00
Родитель 44a2e7497f
Коммит 214977c783
3 изменённых файлов: 12 добавлений и 6 удалений

Просмотреть файл

@ -2,7 +2,6 @@
import os
import mimetypes
import shutil
import tempfile
import zipfile
from django.conf import settings
@ -81,7 +80,7 @@ class TestFileHelper(amo.tests.TestCase):
m, encoding = mimetypes.guess_type(f)
assert binary(m, f), '%s should be binary' % f
filename = tempfile.mktemp()
filename = os.path.join(settings.TMP_PATH, 'test_isbinary')
for txt in ['#!/usr/bin/python', '#python', u'\0x2']:
open(filename, 'w').write(txt)
m, encoding = mimetypes.guess_type(filename)
@ -91,6 +90,7 @@ class TestFileHelper(amo.tests.TestCase):
open(filename, 'w').write(txt)
m, encoding = mimetypes.guess_type(filename)
assert binary(m, filename), '%s should be binary' % txt
os.remove(filename)
def test_truncate(self):
truncate = self.viewer.truncate
@ -131,11 +131,12 @@ class TestFileHelper(amo.tests.TestCase):
eq_(files['dictionaries/license.txt']['depth'], 1)
def test_bom(self):
dest = tempfile.mkstemp()[1]
dest = os.path.join(settings.TMP_PATH, 'test_bom')
open(dest, 'w').write('foo'.encode('utf-16'))
self.viewer.select('foo')
self.viewer.selected = {'full': dest, 'size': 1}
eq_(self.viewer.read_file(), u'foo')
os.remove(dest)
def test_syntax(self):
for filename, syntax in [('foo.rdf', 'xml'),

Просмотреть файл

@ -84,7 +84,8 @@ class TestRepackageJetpack(amo.tests.TestCase):
self.uuid = uuid.uuid4().hex
def create_temp_file(self):
tmp_file = tempfile.NamedTemporaryFile(delete=False)
tmp_file = tempfile.NamedTemporaryFile(delete=False,
dir=settings.TMP_PATH)
tmp_file.write(open(self.xpi_path, 'rb').read())
tmp_file.flush()
return tmp_file

Просмотреть файл

@ -313,8 +313,12 @@ def extract_zip(source, remove=False, fatal=True):
tempdir = tempfile.mkdtemp()
zip = SafeUnzip(source)
if zip.is_valid(fatal):
zip.extract_to_dest(tempdir)
try:
if zip.is_valid(fatal):
zip.extract_to_dest(tempdir)
except:
shutil.rmtree(tempdir)
raise
if remove:
os.remove(source)