mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
Fixed #32316 -- Deferred accessing __file__.
Deferred accessing the module-global variable __file__ because the Python import API does not guarantee it always exists—in particular, it does not exist in certain "frozen" environments. The following changes advanced this goal. Thanks to Carlton Gibson, Tom Forbes, Mariusz Felisiak, and Shreyas Ravi for review and feedback.
This commit is contained in:
committed by
Mariusz Felisiak
parent
cfe47b7686
commit
9ee693bd6c
@@ -1,17 +1,37 @@
|
||||
from unittest import skipUnless
|
||||
|
||||
import django.utils.version
|
||||
from django import get_version
|
||||
from django.test import SimpleTestCase
|
||||
from django.utils.version import get_complete_version, get_version_tuple
|
||||
from django.utils.version import (
|
||||
get_complete_version, get_git_changeset, get_version_tuple,
|
||||
)
|
||||
|
||||
|
||||
class VersionTests(SimpleTestCase):
|
||||
|
||||
def test_development(self):
|
||||
get_git_changeset.cache_clear()
|
||||
ver_tuple = (1, 4, 0, 'alpha', 0)
|
||||
# This will return a different result when it's run within or outside
|
||||
# of a git clone: 1.4.devYYYYMMDDHHMMSS or 1.4.
|
||||
ver_string = get_version(ver_tuple)
|
||||
self.assertRegex(ver_string, r'1\.4(\.dev[0-9]+)?')
|
||||
|
||||
@skipUnless(
|
||||
hasattr(django.utils.version, '__file__'),
|
||||
'test_development() checks the same when __file__ is already missing, '
|
||||
'e.g. in a frozen environments'
|
||||
)
|
||||
def test_development_no_file(self):
|
||||
get_git_changeset.cache_clear()
|
||||
version_file = django.utils.version.__file__
|
||||
try:
|
||||
del django.utils.version.__file__
|
||||
self.test_development()
|
||||
finally:
|
||||
django.utils.version.__file__ = version_file
|
||||
|
||||
def test_releases(self):
|
||||
tuples_to_strings = (
|
||||
((1, 4, 0, 'alpha', 1), '1.4a1'),
|
||||
|
||||
Reference in New Issue
Block a user