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
d8df97aa
Commit
d8df97aa
authored
Dec 28, 2013
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use ddt to separate test cases into tests.
parent
209f8cc3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
41 deletions
+58
-41
i18n/tests/test_converter.py
+39
-27
i18n/tests/test_dummy.py
+19
-14
No files found.
i18n/tests/test_converter.py
View file @
d8df97aa
"""Tests of i18n/converter.py"""
import
os
import
os
from
unittest
import
TestCase
from
unittest
import
TestCase
import
ddt
import
converter
import
converter
...
@@ -11,39 +14,48 @@ class UpcaseConverter(converter.Converter):
...
@@ -11,39 +14,48 @@ class UpcaseConverter(converter.Converter):
return
string
.
upper
()
return
string
.
upper
()
@ddt.ddt
class
TestConverter
(
TestCase
):
class
TestConverter
(
TestCase
):
"""
"""
Tests functionality of i18n/converter.py
Tests functionality of i18n/converter.py
"""
"""
def
test_converter
(
self
):
@ddt.data
(
# no tags
(
'big bad wolf'
,
'BIG BAD WOLF'
),
# one html tag
(
'big <strong>bad</strong> wolf'
,
'BIG <strong>BAD</strong> WOLF'
),
# two html tags
(
'big <b>bad</b> gray <i>wolf</i>'
,
'BIG <b>BAD</b> GRAY <i>WOLF</i>'
),
# html tags with attributes
(
'<a href="foo">bar</a> baz'
,
'<a href="foo">BAR</a> BAZ'
),
(
"<a href='foo'>bar</a> baz"
,
"<a href='foo'>BAR</a> BAZ"
),
# one python tag
(
'big
%(adjective)
s wolf'
,
'BIG
%(adjective)
s WOLF'
),
# two python tags
(
'big
%(adjective)
s gray
%(noun)
s'
,
'BIG
%(adjective)
s GRAY
%(noun)
s'
),
# both kinds of tags
(
'<strong>big</strong>
%(adjective)
s
%(noun)
s'
,
'<strong>BIG</strong>
%(adjective)
s
%(noun)
s'
),
# .format-style tags
(
'The {0} barn is {1!r}.'
,
'THE {0} BARN IS {1!r}.'
),
# HTML entities
(
'<b>© 2013 edX,  </b>'
,
'<b>© 2013 EDX,  </b>'
),
)
def
test_converter
(
self
,
data
):
"""
"""
Tests with a simple converter (converts strings to uppercase).
Tests with a simple converter (converts strings to uppercase).
Assert that embedded HTML and python tags are not converted.
Assert that embedded HTML and python tags are not converted.
"""
"""
c
=
UpcaseConverter
()
source
,
expected
=
data
test_cases
=
[
result
=
UpcaseConverter
()
.
convert
(
source
)
# no tags
self
.
assertEquals
(
result
,
expected
)
(
'big bad wolf'
,
'BIG BAD WOLF'
),
# one html tag
(
'big <strong>bad</strong> wolf'
,
'BIG <strong>BAD</strong> WOLF'
),
# two html tags
(
'big <b>bad</b> <i>wolf</i>'
,
'BIG <b>BAD</b> <i>WOLF</i>'
),
# html tags with attributes
(
'<a href="foo">bar</a> baz'
,
'<a href="foo">BAR</a> BAZ'
),
(
"<a href='foo'>bar</a> baz"
,
"<a href='foo'>BAR</a> BAZ"
),
# one python tag
(
'big
%(adjective)
s wolf'
,
'BIG
%(adjective)
s WOLF'
),
# two python tags
(
'big
%(adjective)
s
%(noun)
s'
,
'BIG
%(adjective)
s
%(noun)
s'
),
# both kinds of tags
(
'<strong>big</strong>
%(adjective)
s
%(noun)
s'
,
'<strong>BIG</strong>
%(adjective)
s
%(noun)
s'
),
# .format-style tags
(
'The {0} barn is {1!r}.'
,
'THE {0} BARN IS {1!r}.'
),
# HTML entities
(
'<b>© 2013 edX,  </b>'
,
'<b>© 2013 EDX,  </b>'
),
]
for
source
,
expected
in
test_cases
:
result
=
c
.
convert
(
source
)
self
.
assertEquals
(
result
,
expected
)
i18n/tests/test_dummy.py
View file @
d8df97aa
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
"""Tests of i18n/dummy.py"""
import
os
,
string
,
random
import
os
,
string
,
random
from
unittest
import
TestCase
from
unittest
import
TestCase
import
ddt
from
polib
import
POEntry
from
polib
import
POEntry
import
dummy
import
dummy
@ddt.ddt
class
TestDummy
(
TestCase
):
class
TestDummy
(
TestCase
):
"""
"""
Tests functionality of i18n/dummy.py
Tests functionality of i18n/dummy.py
...
@@ -27,24 +32,24 @@ class TestDummy(TestCase):
...
@@ -27,24 +32,24 @@ class TestDummy(TestCase):
"Mismatch:
%
r !=
%
r"
%
(
str1
,
str2
),
"Mismatch:
%
r !=
%
r"
%
(
str1
,
str2
),
)
)
def
test_dummy
(
self
):
@ddt.data
(
(
u"hello my name is Bond, James Bond"
,
u"héllø mý nämé ïs Bønd, Jämés Bønd Ⱡσяєм ι#"
),
(
u"don't convert <a href='href'>tag ids</a>"
,
u"døn't çønvért <a href='href'>täg ïds</a> Ⱡσяєм ιρѕυ#"
),
(
u"don't convert
%(name)
s tags on
%(date)
s"
,
u"døn't çønvért
%(name)
s tägs øn
%(date)
s Ⱡσяєм ιρѕ#"
),
)
def
test_dummy
(
self
,
data
):
"""
"""
Tests with a dummy converter (adds spurious accents to strings).
Tests with a dummy converter (adds spurious accents to strings).
Assert that embedded HTML and python tags are not converted.
Assert that embedded HTML and python tags are not converted.
"""
"""
test_cases
=
[
source
,
expected
=
data
(
u"hello my name is Bond, James Bond"
,
result
=
self
.
converter
.
convert
(
source
)
u"héllø mý nämé ïs Bønd, Jämés Bønd Ⱡσяєм ι#"
),
self
.
assertUnicodeEquals
(
result
,
expected
)
(
u"don't convert <a href='href'>tag ids</a>"
,
u"døn't çønvért <a href='href'>täg ïds</a> Ⱡσяєм ιρѕυ#"
),
(
u"don't convert
%(name)
s tags on
%(date)
s"
,
u"døn't çønvért
%(name)
s tägs øn
%(date)
s Ⱡσяєм ιρѕ#"
),
]
for
source
,
expected
in
test_cases
:
result
=
self
.
converter
.
convert
(
source
)
self
.
assertUnicodeEquals
(
result
,
expected
)
def
test_singular
(
self
):
def
test_singular
(
self
):
entry
=
POEntry
()
entry
=
POEntry
()
...
...
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