Commit e54c0a0c authored by Alex Gaynor's avatar Alex Gaynor
Browse files

Move the Python 2.5 specific tests out of their own special files now that 2.5...

Move the Python 2.5 specific tests out of their own special files now that 2.5 is the default.  Also add __futre__ import where necessary.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15935 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent b4f0c1a7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ called, a commit is made.
Managed transactions don't do those commits, but will need some kind of manual
or implicit commits or rollbacks.
"""
from __future__ import with_statement

import sys
from functools import wraps
+3 −8
Original line number Diff line number Diff line
from __future__ import with_statement

import re
import sys
from functools import wraps
@@ -531,15 +533,8 @@ class TransactionTestCase(ut2.TestCase):
            return context

        # Basically emulate the `with` statement here.

        context.__enter__()
        try:
        with context:
            func(*args, **kwargs)
        except:
            context.__exit__(*sys.exc_info())
            raise
        else:
            context.__exit__(*sys.exc_info())

def connections_support_transactions():
    """
+0 −3
Original line number Diff line number Diff line
@@ -16,9 +16,6 @@ from django.core.files.storage import FileSystemStorage
temp_storage_location = tempfile.mkdtemp()
temp_storage = FileSystemStorage(location=temp_storage_location)

# Write out a file to be used as default content
temp_storage.save('tests/default.txt', ContentFile('default content'))

class Storage(models.Model):
    def custom_upload_to(self, filename):
        return 'foo'
+14 −2
Original line number Diff line number Diff line
from __future__ import with_statement

import shutil
import sys
import tempfile

from django.core.cache import cache
from django.core.files import File
from django.core.files.base import ContentFile
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase

from models import Storage, temp_storage, temp_storage_location
if sys.version_info >= (2, 5):
    from tests_25 import FileObjTests


class FileTests(TestCase):
@@ -16,6 +18,7 @@ class FileTests(TestCase):
        shutil.rmtree(temp_storage_location)

    def test_files(self):
        temp_storage.save('tests/default.txt', ContentFile('default content'))
        # Attempting to access a FileField from the class raises a descriptive
        # error
        self.assertRaises(AttributeError, lambda: Storage.normal)
@@ -103,3 +106,12 @@ class FileTests(TestCase):
        obj2.normal.delete()
        obj3.default.delete()
        obj4.random.delete()

    def test_context_manager(self):
        orig_file = tempfile.TemporaryFile()
        base_file = File(orig_file)
        with base_file as f:
            self.assertIs(base_file, f)
            self.assertFalse(f.closed)
        self.assertTrue(f.closed)
        self.assertTrue(orig_file.closed)
+0 −17
Original line number Diff line number Diff line
from __future__ import with_statement

import tempfile

from django.core.files import File
from django.utils.unittest import TestCase


class FileObjTests(TestCase):
    def test_context_manager(self):
        orig_file = tempfile.TemporaryFile()
        base_file = File(orig_file)
        with base_file as f:
            self.assertIs(base_file, f)
            self.assertFalse(f.closed)
        self.assertTrue(f.closed)
        self.assertTrue(orig_file.closed)
Loading