mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Modified utils_tests for unittest2 discovery.
This commit is contained in:
parent
3810dc3070
commit
612ef3e5c9
28 changed files with 27 additions and 27 deletions
72
tests/utils_tests/test_archive.py
Normal file
72
tests/utils_tests/test_archive.py
Normal file
|
@ -0,0 +1,72 @@
|
|||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from django.utils import unittest
|
||||
|
||||
from django.utils.archive import Archive, extract
|
||||
from django.utils._os import upath
|
||||
|
||||
|
||||
TEST_DIR = os.path.join(os.path.dirname(upath(__file__)), 'archives')
|
||||
|
||||
|
||||
class ArchiveTester(object):
|
||||
archive = None
|
||||
|
||||
def setUp(self):
|
||||
"""
|
||||
Create temporary directory for testing extraction.
|
||||
"""
|
||||
self.old_cwd = os.getcwd()
|
||||
self.tmpdir = tempfile.mkdtemp()
|
||||
self.addCleanup(shutil.rmtree, self.tmpdir)
|
||||
self.archive_path = os.path.join(TEST_DIR, self.archive)
|
||||
# Always start off in TEST_DIR.
|
||||
os.chdir(TEST_DIR)
|
||||
|
||||
def tearDown(self):
|
||||
os.chdir(self.old_cwd)
|
||||
|
||||
def test_extract_method(self):
|
||||
with Archive(self.archive) as archive:
|
||||
archive.extract(self.tmpdir)
|
||||
self.check_files(self.tmpdir)
|
||||
|
||||
def test_extract_method_no_to_path(self):
|
||||
os.chdir(self.tmpdir)
|
||||
with Archive(self.archive_path) as archive:
|
||||
archive.extract()
|
||||
self.check_files(self.tmpdir)
|
||||
|
||||
def test_extract_function(self):
|
||||
extract(self.archive_path, self.tmpdir)
|
||||
self.check_files(self.tmpdir)
|
||||
|
||||
def test_extract_function_no_to_path(self):
|
||||
os.chdir(self.tmpdir)
|
||||
extract(self.archive_path)
|
||||
self.check_files(self.tmpdir)
|
||||
|
||||
def check_files(self, tmpdir):
|
||||
self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, '1')))
|
||||
self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, '2')))
|
||||
self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, 'foo', '1')))
|
||||
self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, 'foo', '2')))
|
||||
self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, 'foo', 'bar', '1')))
|
||||
self.assertTrue(os.path.isfile(os.path.join(self.tmpdir, 'foo', 'bar', '2')))
|
||||
|
||||
|
||||
class TestZip(ArchiveTester, unittest.TestCase):
|
||||
archive = 'foobar.zip'
|
||||
|
||||
|
||||
class TestTar(ArchiveTester, unittest.TestCase):
|
||||
archive = 'foobar.tar'
|
||||
|
||||
|
||||
class TestGzipTar(ArchiveTester, unittest.TestCase):
|
||||
archive = 'foobar.tar.gz'
|
||||
|
||||
|
||||
class TestBzip2Tar(ArchiveTester, unittest.TestCase):
|
||||
archive = 'foobar.tar.bz2'
|
Loading…
Add table
Add a link
Reference in a new issue