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
834c2c47
Commit
834c2c47
authored
Jun 10, 2014
by
Dave St.Germain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved test_generate from i18n-tools
parent
e6ec664a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
99 additions
and
61 deletions
+99
-61
common/lib/test_generate.py
+98
-0
pavelib/tests.py
+1
-15
pavelib/utils/test/suites/__init__.py
+0
-1
pavelib/utils/test/suites/i18n_suite.py
+0
-42
rakelib/tests_deprecated.rake
+0
-3
No files found.
common/lib/test_generate.py
0 → 100644
View file @
834c2c47
from
datetime
import
datetime
,
timedelta
import
os
import
sys
import
string
import
random
import
re
from
unittest
import
TestCase
from
mock
import
patch
from
polib
import
pofile
from
pytz
import
UTC
from
i18n
import
config
from
i18n
import
extract
from
i18n
import
generate
from
i18n
import
dummy
class
TestGenerate
(
TestCase
):
"""
Tests functionality of i18n/generate.py
"""
generated_files
=
(
'django-partial.po'
,
'djangojs-partial.po'
,
'mako.po'
)
@classmethod
def
setUpClass
(
cls
):
cfg
=
os
.
path
.
join
(
'conf'
,
'locale'
,
'config.yaml'
)
config
.
CONFIGURATION
=
config
.
Configuration
(
cfg
)
sys
.
stderr
.
write
(
"
\n
Extracting i18n strings and generating dummy translations; "
"this may take a few minutes
\n
"
)
sys
.
stderr
.
flush
()
extract
.
main
(
verbosity
=
0
,
config
=
cfg
)
dummy
.
main
(
verbosity
=
0
,
config
=
cfg
)
def
setUp
(
self
):
# Subtract 1 second to help comparisons with file-modify time succeed,
# since os.path.getmtime() is not millisecond-accurate
self
.
start_time
=
datetime
.
now
(
UTC
)
-
timedelta
(
seconds
=
1
)
def
test_merge
(
self
):
"""
Tests merge script on English source files.
"""
filename
=
os
.
path
.
join
(
config
.
CONFIGURATION
.
source_messages_dir
,
random_name
())
generate
.
merge
(
config
.
CONFIGURATION
.
source_locale
,
target
=
filename
)
self
.
assertTrue
(
os
.
path
.
exists
(
filename
))
os
.
remove
(
filename
)
# Patch dummy_locales to not have esperanto present
@patch.object
(
config
.
CONFIGURATION
,
'dummy_locales'
,
[
'fake2'
])
def
test_main
(
self
):
"""
Runs generate.main() which should merge source files,
then compile all sources in all configured languages.
Validates output by checking all .mo files in all configured languages.
.mo files should exist, and be recently created (modified
after start of test suite)
"""
generate
.
main
(
verbosity
=
0
,
strict
=
False
)
for
locale
in
config
.
CONFIGURATION
.
translated_locales
:
for
filename
in
(
'django'
,
'djangojs'
):
mofile
=
filename
+
'.mo'
path
=
os
.
path
.
join
(
config
.
CONFIGURATION
.
get_messages_dir
(
locale
),
mofile
)
exists
=
os
.
path
.
exists
(
path
)
self
.
assertTrue
(
exists
,
msg
=
'Missing file in locale
%
s:
%
s'
%
(
locale
,
mofile
))
self
.
assertTrue
(
datetime
.
fromtimestamp
(
os
.
path
.
getmtime
(
path
),
UTC
)
>=
self
.
start_time
,
msg
=
'File not recently modified:
%
s'
%
path
)
# Segmenting means that the merge headers don't work they way they
# used to, so don't make this check for now. I'm not sure if we'll
# get the merge header back eventually, or delete this code eventually.
# self.assert_merge_headers(locale)
def
assert_merge_headers
(
self
,
locale
):
"""
This is invoked by test_main to ensure that it runs after
calling generate.main().
There should be exactly three merge comment headers
in our merged .po file. This counts them to be sure.
A merge comment looks like this:
# #-#-#-#-# django-partial.po (0.1a) #-#-#-#-#
"""
path
=
os
.
path
.
join
(
config
.
CONFIGURATION
.
get_messages_dir
(
locale
),
'django.po'
)
po
=
pofile
(
path
)
pattern
=
re
.
compile
(
'^#-#-#-#-#'
,
re
.
M
)
match
=
pattern
.
findall
(
po
.
header
)
self
.
assertEqual
(
len
(
match
),
3
,
msg
=
"Found
%
s (should be 3) merge comments in the header for
%
s"
%
\
(
len
(
match
),
path
))
def
random_name
(
size
=
6
):
"""Returns random filename as string, like test-4BZ81W"""
chars
=
string
.
ascii_uppercase
+
string
.
digits
return
'test-'
+
''
.
join
(
random
.
choice
(
chars
)
for
x
in
range
(
size
))
pavelib/tests.py
View file @
834c2c47
...
...
@@ -127,19 +127,6 @@ def test_python(options):
@task
@needs
(
'pavelib.prereqs.install_python_prereqs'
,
'pavelib.utils.test.utils.clean_reports_dir'
,
)
def
test_i18n
():
"""
Run all i18n tests
"""
i18n_suite
=
suites
.
I18nTestSuite
(
'i18n'
)
i18n_suite
.
run
()
@task
@needs
(
'pavelib.prereqs.install_prereqs'
,
'pavelib.utils.test.utils.clean_reports_dir'
,
)
...
...
@@ -157,11 +144,10 @@ def test(options):
}
# Subsuites to be added to the main suite
python_suite
=
suites
.
PythonTestSuite
(
'Python Tests'
,
**
opts
)
i18n_suite
=
suites
.
I18nTestSuite
(
'i18n'
,
**
opts
)
js_suite
=
suites
.
JsTestSuite
(
'JS Tests'
,
mode
=
'run'
,
with_coverage
=
True
)
# Main suite to be run
all_unittests_suite
=
suites
.
TestSuite
(
'All Tests'
,
subsuites
=
[
i18n_suite
,
js_suite
,
python_suite
])
all_unittests_suite
=
suites
.
TestSuite
(
'All Tests'
,
subsuites
=
[
js_suite
,
python_suite
])
all_unittests_suite
.
run
()
...
...
pavelib/utils/test/suites/__init__.py
View file @
834c2c47
...
...
@@ -5,4 +5,3 @@ from .suite import TestSuite
from
.nose_suite
import
NoseTestSuite
,
SystemTestSuite
,
LibTestSuite
from
.python_suite
import
PythonTestSuite
from
.js_suite
import
JsTestSuite
from
.i18n_suite
import
I18nTestSuite
pavelib/utils/test/suites/i18n_suite.py
deleted
100644 → 0
View file @
e6ec664a
"""
Classes used for defining and running i18n test suites
"""
from
pavelib.utils.test.suites
import
TestSuite
from
pavelib.utils.envs
import
Env
__test__
=
False
# do not collect
class
I18nTestSuite
(
TestSuite
):
"""
Run tests for the internationalization library
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
I18nTestSuite
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
report_dir
=
Env
.
I18N_REPORT_DIR
self
.
xunit_report
=
self
.
report_dir
/
'nosetests.xml'
def
__enter__
(
self
):
super
(
I18nTestSuite
,
self
)
.
__enter__
()
self
.
report_dir
.
makedirs_p
()
@property
def
cmd
(
self
):
pythonpath_prefix
=
(
"PYTHONPATH={repo_root}/i18n:$PYTHONPATH"
.
format
(
repo_root
=
Env
.
REPO_ROOT
)
)
cmd
=
(
"{pythonpath_prefix} nosetests {repo_root}/i18n/tests "
"--with-xunit --xunit-file={xunit_report} "
"--verbosity={verbosity}"
.
format
(
pythonpath_prefix
=
pythonpath_prefix
,
repo_root
=
Env
.
REPO_ROOT
,
xunit_report
=
self
.
xunit_report
,
verbosity
=
self
.
verbosity
,
)
)
return
cmd
rakelib/tests_deprecated.rake
View file @
834c2c47
...
...
@@ -37,9 +37,6 @@ end
deprecated
(
"coverage"
,
"paver coverage"
,
false
)
# deprecates i18n:test from i18n.rake
deprecated
(
"i18n:test"
,
'paver test_i18n'
,
false
)
deprecated
(
"clean_reports_dir"
,
"paver clean_reports_dir"
,
false
)
deprecated
(
"clean_test_files"
,
"paver clean_test_files"
,
false
)
deprecated
(
"test:clean_mongo"
,
"paver clean_mongo"
,
false
)
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