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
e6e5a8d8
Commit
e6e5a8d8
authored
Mar 22, 2015
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert some try/finally to addCleanup
parent
cb0624bf
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
36 deletions
+22
-36
common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py
+17
-25
lms/djangoapps/courseware/management/commands/tests/test_dump_course.py
+4
-6
openedx/core/djangoapps/user_api/management/tests/test_email_opt_in_list.py
+1
-5
No files found.
common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py
View file @
e6e5a8d8
...
...
@@ -571,12 +571,10 @@ class TestMongoModuleStore(TestMongoModuleStoreBase):
self
.
content_store
.
find
(
location
)
root_dir
=
path
(
mkdtemp
())
try
:
export_course_to_xml
(
self
.
draft_store
,
self
.
content_store
,
course_key
,
root_dir
,
'test_export'
)
assert_true
(
path
(
root_dir
/
'test_export/static/images/course_image.jpg'
)
.
isfile
())
assert_true
(
path
(
root_dir
/
'test_export/static/images_course_image.jpg'
)
.
isfile
())
finally
:
shutil
.
rmtree
(
root_dir
)
self
.
addCleanup
(
shutil
.
rmtree
,
root_dir
)
export_course_to_xml
(
self
.
draft_store
,
self
.
content_store
,
course_key
,
root_dir
,
'test_export'
)
self
.
assertTrue
(
path
(
root_dir
/
'test_export/static/images/course_image.jpg'
)
.
isfile
())
self
.
assertTrue
(
path
(
root_dir
/
'test_export/static/images_course_image.jpg'
)
.
isfile
())
@patch
(
'xmodule.tabs.CourseTab.from_json'
,
side_effect
=
mock_tab_from_json
)
def
test_export_course_image_nondefault
(
self
,
_from_json
):
...
...
@@ -588,12 +586,10 @@ class TestMongoModuleStore(TestMongoModuleStoreBase):
assert_true
(
course
.
course_image
,
'just_a_test.jpg'
)
root_dir
=
path
(
mkdtemp
())
try
:
export_course_to_xml
(
self
.
draft_store
,
self
.
content_store
,
course
.
id
,
root_dir
,
'test_export'
)
assert_true
(
path
(
root_dir
/
'test_export/static/just_a_test.jpg'
)
.
isfile
())
assert_false
(
path
(
root_dir
/
'test_export/static/images/course_image.jpg'
)
.
isfile
())
finally
:
shutil
.
rmtree
(
root_dir
)
self
.
addCleanup
(
shutil
.
rmtree
,
root_dir
)
export_course_to_xml
(
self
.
draft_store
,
self
.
content_store
,
course
.
id
,
root_dir
,
'test_export'
)
self
.
assertTrue
(
path
(
root_dir
/
'test_export/static/just_a_test.jpg'
)
.
isfile
())
self
.
assertFalse
(
path
(
root_dir
/
'test_export/static/images/course_image.jpg'
)
.
isfile
())
def
test_course_without_image
(
self
):
"""
...
...
@@ -602,12 +598,10 @@ class TestMongoModuleStore(TestMongoModuleStoreBase):
"""
course
=
self
.
draft_store
.
get_course
(
SlashSeparatedCourseKey
(
'edX'
,
'simple_with_draft'
,
'2012_Fall'
))
root_dir
=
path
(
mkdtemp
())
try
:
export_course_to_xml
(
self
.
draft_store
,
self
.
content_store
,
course
.
id
,
root_dir
,
'test_export'
)
assert_false
(
path
(
root_dir
/
'test_export/static/images/course_image.jpg'
)
.
isfile
())
assert_false
(
path
(
root_dir
/
'test_export/static/images_course_image.jpg'
)
.
isfile
())
finally
:
shutil
.
rmtree
(
root_dir
)
self
.
addCleanup
(
shutil
.
rmtree
,
root_dir
)
export_course_to_xml
(
self
.
draft_store
,
self
.
content_store
,
course
.
id
,
root_dir
,
'test_export'
)
self
.
assertFalse
(
path
(
root_dir
/
'test_export/static/images/course_image.jpg'
)
.
isfile
())
self
.
assertFalse
(
path
(
root_dir
/
'test_export/static/images_course_image.jpg'
)
.
isfile
())
def
_create_test_tree
(
self
,
name
,
user_id
=
None
):
"""
...
...
@@ -728,15 +722,13 @@ class TestMongoModuleStore(TestMongoModuleStoreBase):
self
.
assertEqual
(
unicode
(
component
.
link_to_location
),
unicode
(
problem_location
))
root_dir
=
path
(
mkdtemp
())
self
.
addCleanup
(
shutil
.
rmtree
,
root_dir
)
# export_course_to_xml should work.
try
:
export_course_to_xml
(
self
.
draft_store
,
self
.
content_store
,
interface_location
.
course_key
,
root_dir
,
'test_export'
)
finally
:
shutil
.
rmtree
(
root_dir
)
export_course_to_xml
(
self
.
draft_store
,
self
.
content_store
,
interface_location
.
course_key
,
root_dir
,
'test_export'
)
def
test_draft_modulestore_create_child_with_position
(
self
):
"""
...
...
lms/djangoapps/courseware/management/commands/tests/test_dump_course.py
View file @
e6e5a8d8
...
...
@@ -175,14 +175,12 @@ class CommandsTestBase(ModuleStoreTestCase):
def
test_export_course
(
self
):
tmp_dir
=
path
(
mkdtemp
())
self
.
addCleanup
(
shutil
.
rmtree
,
tmp_dir
)
filename
=
tmp_dir
/
'test.tar.gz'
try
:
self
.
run_export_course
(
filename
)
with
tarfile
.
open
(
filename
)
as
tar_file
:
self
.
check_export_file
(
tar_file
)
finally
:
shutil
.
rmtree
(
tmp_dir
)
self
.
run_export_course
(
filename
)
with
tarfile
.
open
(
filename
)
as
tar_file
:
self
.
check_export_file
(
tar_file
)
def
test_export_course_stdout
(
self
):
output
=
self
.
run_export_course
(
'-'
)
...
...
openedx/core/djangoapps/user_api/management/tests/test_email_opt_in_list.py
View file @
e6e5a8d8
...
...
@@ -331,11 +331,7 @@ class EmailOptInListTest(ModuleStoreTestCase):
# Create a temporary directory for the output
# Delete it when we're finished
temp_dir_path
=
tempfile
.
mkdtemp
()
def
_cleanup
():
# pylint: disable=missing-docstring
shutil
.
rmtree
(
temp_dir_path
)
self
.
addCleanup
(
_cleanup
)
self
.
addCleanup
(
shutil
.
rmtree
,
temp_dir_path
)
# Sanitize the arguments
if
other_names
is
None
:
...
...
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