Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
b21473f9
Commit
b21473f9
authored
Feb 21, 2014
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make fake_ugettext et al more usable elsewhere.
parent
6bb0eee3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
10 deletions
+13
-10
common/djangoapps/util/tests/test_date_utils.py
+13
-10
No files found.
common/djangoapps/util/tests/test_date_utils.py
View file @
b21473f9
...
...
@@ -4,7 +4,6 @@ Tests for util.date_utils
"""
from
datetime
import
datetime
,
timedelta
,
tzinfo
from
functools
import
partial
import
unittest
import
ddt
...
...
@@ -118,18 +117,22 @@ def test_almost_same_datetime():
)
def
fake_ugettext
(
t
ext
,
t
ranslations
):
def
fake_ugettext
(
translations
):
"""
A
fake implementation of ugettext, for testing.
Create a
fake implementation of ugettext, for testing.
"""
return
translations
.
get
(
text
,
text
)
def
_ugettext
(
text
):
# pylint: disable=missing-docstring
return
translations
.
get
(
text
,
text
)
return
_ugettext
def
fake_pgettext
(
context
,
text
,
translations
):
def
fake_pgettext
(
translations
):
"""
A
fake implementation of pgettext, for testing.
Create a
fake implementation of pgettext, for testing.
"""
return
translations
.
get
((
context
,
text
),
text
)
def
_pgettext
(
context
,
text
):
# pylint: disable=missing-docstring
return
translations
.
get
((
context
,
text
),
text
)
return
_pgettext
@ddt.ddt
...
...
@@ -161,7 +164,7 @@ class StrftimeLocalizedTest(unittest.TestCase):
dtime
=
datetime
(
2013
,
02
,
14
,
16
,
41
,
17
)
self
.
assertEqual
(
expected
,
strftime_localized
(
dtime
,
fmt
))
@patch
(
'util.date_utils.pgettext'
,
partial
(
fake_pgettext
,
translations
=
{
@patch
(
'util.date_utils.pgettext'
,
fake_pgettext
(
translations
=
{
(
"abbreviated month name"
,
"Feb"
):
"XXfebXX"
,
(
"month name"
,
"February"
):
"XXfebruaryXX"
,
(
"abbreviated weekday name"
,
"Thu"
):
"XXthuXX"
,
...
...
@@ -179,7 +182,7 @@ class StrftimeLocalizedTest(unittest.TestCase):
dtime
=
datetime
(
2013
,
02
,
14
,
16
,
41
,
17
)
self
.
assertEqual
(
expected
,
strftime_localized
(
dtime
,
fmt
))
@patch
(
'util.date_utils.ugettext'
,
partial
(
fake_ugettext
,
translations
=
{
@patch
(
'util.date_utils.ugettext'
,
fake_ugettext
(
translations
=
{
"SHORT_DATE_FORMAT"
:
"date(
%
Y.
%
m.
%
d)"
,
"LONG_DATE_FORMAT"
:
"date(
%
A.
%
Y.
%
B.
%
d)"
,
"DATE_TIME_FORMAT"
:
"date(
%
Y.
%
m.
%
d@
%
H.
%
M)"
,
...
...
@@ -198,7 +201,7 @@ class StrftimeLocalizedTest(unittest.TestCase):
dtime
=
datetime
(
2013
,
02
,
14
,
16
,
41
,
17
)
self
.
assertEqual
(
expected
,
strftime_localized
(
dtime
,
fmt
))
@patch
(
'util.date_utils.ugettext'
,
partial
(
fake_ugettext
,
translations
=
{
@patch
(
'util.date_utils.ugettext'
,
fake_ugettext
(
translations
=
{
"SHORT_DATE_FORMAT"
:
"oops date(
%
Y.
%
x.
%
d)"
,
"TIME_FORMAT"
:
"oops
%
Hh.
%
Xm.
%
Ss"
,
}))
...
...
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