Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
e80636b6
Kaydet (Commit)
e80636b6
authored
May 19, 2013
tarafından
Łukasz Langa
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added TransRealMixin to fix i18n global state pollution in the test suite
üst
413735b2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
13 deletions
+39
-13
__init__.py
tests/i18n/__init__.py
+17
-0
tests.py
tests/i18n/contenttypes/tests.py
+3
-1
tests.py
tests/i18n/tests.py
+19
-12
No files found.
tests/i18n/__init__.py
Dosyayı görüntüle @
e80636b6
from
threading
import
local
class
TransRealMixin
(
object
):
"""This is the only way to reset the translation machinery. Otherwise
the test suite occasionally fails because of global state pollution
between tests."""
def
flush_caches
(
self
):
from
django.utils.translation
import
trans_real
trans_real
.
_translations
=
{}
trans_real
.
_active
=
local
()
trans_real
.
_default
=
None
trans_real
.
_accepted
=
{}
def
tearDown
(
self
):
self
.
flush_caches
()
super
(
TransRealMixin
,
self
)
.
tearDown
()
tests/i18n/contenttypes/tests.py
Dosyayı görüntüle @
e80636b6
...
...
@@ -10,6 +10,8 @@ from django.utils._os import upath
from
django.utils
import
six
from
django.utils
import
translation
from
i18n
import
TransRealMixin
@override_settings
(
USE_I18N
=
True
,
...
...
@@ -22,7 +24,7 @@ from django.utils import translation
(
'fr'
,
'French'
),
),
)
class
ContentTypeTests
(
TestCase
):
class
ContentTypeTests
(
T
ransRealMixin
,
T
estCase
):
def
test_verbose_name
(
self
):
company_type
=
ContentType
.
objects
.
get
(
app_label
=
'i18n'
,
model
=
'company'
)
with
translation
.
override
(
'en'
):
...
...
tests/i18n/tests.py
Dosyayı görüntüle @
e80636b6
...
...
@@ -44,6 +44,7 @@ if can_run_compilation_tests:
from
.commands.compilation
import
(
PoFileTests
,
PoFileContentsTests
,
PercentRenderingTests
,
MultipleLocaleCompilationTests
,
CompilationErrorHandling
)
from
.
import
TransRealMixin
from
.forms
import
I18nForm
,
SelectDateForm
,
SelectDateWidget
,
CompanyForm
from
.models
import
Company
,
TestModel
...
...
@@ -53,7 +54,8 @@ extended_locale_paths = settings.LOCALE_PATHS + (
os
.
path
.
join
(
here
,
'other'
,
'locale'
),
)
class
TranslationTests
(
TestCase
):
class
TranslationTests
(
TransRealMixin
,
TestCase
):
def
test_override
(
self
):
activate
(
'de'
)
...
...
@@ -335,6 +337,8 @@ class TranslationTests(TestCase):
class
TranslationThreadSafetyTests
(
TestCase
):
"""Specifically not using TransRealMixin here to test threading."""
def
setUp
(
self
):
self
.
_old_language
=
get_language
()
self
.
_translations
=
trans_real
.
_translations
...
...
@@ -365,9 +369,10 @@ class TranslationThreadSafetyTests(TestCase):
@override_settings
(
USE_L10N
=
True
)
class
FormattingTests
(
TestCase
):
class
FormattingTests
(
T
ransRealMixin
,
T
estCase
):
def
setUp
(
self
):
super
(
FormattingTests
,
self
)
.
setUp
()
self
.
n
=
decimal
.
Decimal
(
'66666.666'
)
self
.
f
=
99999.999
self
.
d
=
datetime
.
date
(
2009
,
12
,
31
)
...
...
@@ -769,9 +774,10 @@ class FormattingTests(TestCase):
self
.
assertEqual
(
template2
.
render
(
context
),
output2
)
self
.
assertEqual
(
template3
.
render
(
context
),
output3
)
class
MiscTests
(
TestCase
):
class
MiscTests
(
T
ransRealMixin
,
T
estCase
):
def
setUp
(
self
):
super
(
MiscTests
,
self
)
.
setUp
()
self
.
rf
=
RequestFactory
()
def
test_parse_spec_http_header
(
self
):
...
...
@@ -915,17 +921,15 @@ class MiscTests(TestCase):
self
.
assertEqual
(
t_plur
.
render
(
Context
({
'percent'
:
42
,
'num'
:
4
})),
'
%(percent)
s
%
represents 4 objects'
)
class
ResolutionOrderI18NTests
(
TestCase
):
class
ResolutionOrderI18NTests
(
T
ransRealMixin
,
T
estCase
):
def
setUp
(
self
):
# Okay, this is brutal, but we have no other choice to fully reset
# the translation framework
trans_real
.
_active
=
local
()
trans_real
.
_translations
=
{}
super
(
ResolutionOrderI18NTests
,
self
)
.
setUp
()
activate
(
'de'
)
def
tearDown
(
self
):
deactivate
()
super
(
ResolutionOrderI18NTests
,
self
)
.
tearDown
()
def
assertUgettext
(
self
,
msgid
,
msgstr
):
result
=
ugettext
(
msgid
)
...
...
@@ -998,15 +1002,17 @@ class TestLanguageInfo(TestCase):
six
.
assertRaisesRegex
(
self
,
KeyError
,
r"Unknown language code xx-xx and xx\."
,
get_language_info
,
'xx-xx'
)
class
MultipleLocaleActivationTests
(
TestCase
):
class
MultipleLocaleActivationTests
(
T
ransRealMixin
,
T
estCase
):
"""
Tests for template rendering behavior when multiple locales are activated
during the lifetime of the same process.
"""
def
setUp
(
self
):
super
(
MultipleLocaleActivationTests
,
self
)
.
setUp
()
self
.
_old_language
=
get_language
()
def
tearDown
(
self
):
super
(
MultipleLocaleActivationTests
,
self
)
.
tearDown
()
activate
(
self
.
_old_language
)
def
test_single_locale_activation
(
self
):
...
...
@@ -1135,7 +1141,7 @@ class MultipleLocaleActivationTests(TestCase):
'django.middleware.common.CommonMiddleware'
,
),
)
class
LocaleMiddlewareTests
(
TestCase
):
class
LocaleMiddlewareTests
(
T
ransRealMixin
,
T
estCase
):
urls
=
'i18n.urls'
...
...
@@ -1157,12 +1163,12 @@ class LocaleMiddlewareTests(TestCase):
'django.middleware.common.CommonMiddleware'
,
),
)
class
CountrySpecificLanguageTests
(
TestCase
):
class
CountrySpecificLanguageTests
(
T
ransRealMixin
,
T
estCase
):
urls
=
'i18n.urls'
def
setUp
(
self
):
trans_real
.
_accepted
=
{}
super
(
CountrySpecificLanguageTests
,
self
)
.
setUp
()
self
.
rf
=
RequestFactory
()
def
test_check_for_language
(
self
):
...
...
@@ -1172,6 +1178,7 @@ class CountrySpecificLanguageTests(TestCase):
def
test_get_language_from_request
(
self
):
# issue 19919
r
=
self
.
rf
.
get
(
'/'
)
r
.
COOKIES
=
{}
r
.
META
=
{
'HTTP_ACCEPT_LANGUAGE'
:
'en-US,en;q=0.8,bg;q=0.6,ru;q=0.4'
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment