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
c3b571bf
Commit
c3b571bf
authored
Feb 21, 2013
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure temp directories are properly cleaned up so running tests doesn't leave them behind.
parent
8b1579e4
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
40 additions
and
25 deletions
+40
-25
cms/djangoapps/contentstore/tests/test_contentstore.py
+2
-2
cms/djangoapps/contentstore/tests/tests.py
+0
-1
cms/envs/common.py
+2
-2
common/djangoapps/mitxmako/makoloader.py
+2
-1
common/djangoapps/mitxmako/middleware.py
+2
-2
common/djangoapps/student/management/commands/tests/test_pearson.py
+8
-12
common/lib/tempdir.py
+17
-0
common/lib/xmodule/xmodule/tests/test_export.py
+5
-3
lms/envs/common.py
+2
-2
No files found.
cms/djangoapps/contentstore/tests/test_contentstore.py
View file @
c3b571bf
...
...
@@ -5,7 +5,7 @@ from django.test.utils import override_settings
from
django.conf
import
settings
from
django.core.urlresolvers
import
reverse
from
path
import
path
from
temp
file
import
mkdtemp
from
temp
dir
import
mkdtemp_clean
import
json
from
fs.osfs
import
OSFS
import
copy
...
...
@@ -194,7 +194,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
import_from_xml
(
ms
,
'common/test/data/'
,
[
'full'
])
location
=
CourseDescriptor
.
id_to_location
(
'edX/full/6.002_Spring_2012'
)
root_dir
=
path
(
mkdtemp
())
root_dir
=
path
(
mkdtemp
_clean
())
print
'Exporting to tempdir = {0}'
.
format
(
root_dir
)
...
...
cms/djangoapps/contentstore/tests/tests.py
View file @
c3b571bf
...
...
@@ -4,7 +4,6 @@ from django.test.client import Client
from
django.conf
import
settings
from
django.core.urlresolvers
import
reverse
from
path
import
path
from
tempfile
import
mkdtemp
import
json
from
fs.osfs
import
OSFS
import
copy
...
...
cms/envs/common.py
View file @
c3b571bf
...
...
@@ -20,7 +20,6 @@ Longer TODO:
"""
import
sys
import
tempfile
import
os.path
import
os
import
lms.envs.common
...
...
@@ -59,7 +58,8 @@ sys.path.append(COMMON_ROOT / 'lib')
############################# WEB CONFIGURATION #############################
# This is where we stick our compiled template files.
MAKO_MODULE_DIR
=
tempfile
.
mkdtemp
(
'mako'
)
from
tempdir
import
mkdtemp_clean
MAKO_MODULE_DIR
=
mkdtemp_clean
(
'mako'
)
MAKO_TEMPLATES
=
{}
MAKO_TEMPLATES
[
'main'
]
=
[
PROJECT_ROOT
/
'templates'
,
...
...
common/djangoapps/mitxmako/makoloader.py
View file @
c3b571bf
...
...
@@ -9,6 +9,7 @@ from django.template.loaders.app_directories import Loader as AppDirectoriesLoad
from
mitxmako.template
import
Template
import
mitxmako.middleware
import
tempdir
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -30,7 +31,7 @@ class MakoLoader(object):
if
module_directory
is
None
:
log
.
warning
(
"For more caching of mako templates, set the MAKO_MODULE_DIR in settings!"
)
module_directory
=
temp
file
.
mkdtemp
()
module_directory
=
temp
dir
.
mkdtemp_clean
()
self
.
module_directory
=
module_directory
...
...
common/djangoapps/mitxmako/middleware.py
View file @
c3b571bf
...
...
@@ -13,7 +13,7 @@
# limitations under the License.
from
mako.lookup
import
TemplateLookup
import
temp
file
import
temp
dir
from
django.template
import
RequestContext
from
django.conf
import
settings
...
...
@@ -29,7 +29,7 @@ class MakoMiddleware(object):
module_directory
=
getattr
(
settings
,
'MAKO_MODULE_DIR'
,
None
)
if
module_directory
is
None
:
module_directory
=
temp
file
.
mkdtemp
()
module_directory
=
temp
dir
.
mkdtemp_clean
()
for
location
in
template_locations
:
lookup
[
location
]
=
TemplateLookup
(
directories
=
template_locations
[
location
],
...
...
common/djangoapps/student/management/commands/tests/test_pearson.py
View file @
c3b571bf
...
...
@@ -7,6 +7,7 @@ import logging
import
os
from
tempfile
import
mkdtemp
import
cStringIO
import
shutil
import
sys
from
django.test
import
TestCase
...
...
@@ -143,23 +144,18 @@ class PearsonTestCase(TestCase):
'''
Base class for tests running Pearson-related commands
'''
import_dir
=
mkdtemp
(
prefix
=
"import"
)
export_dir
=
mkdtemp
(
prefix
=
"export"
)
def
assertErrorContains
(
self
,
error_message
,
expected
):
self
.
assertTrue
(
error_message
.
find
(
expected
)
>=
0
,
'error message "{}" did not contain "{}"'
.
format
(
error_message
,
expected
))
def
tearDown
(
self
):
def
delete_temp_dir
(
dirname
):
if
os
.
path
.
exists
(
dirname
):
for
filename
in
os
.
listdir
(
dirname
):
os
.
remove
(
os
.
path
.
join
(
dirname
,
filename
))
os
.
rmdir
(
dirname
)
# clean up after any test data was dumped to temp directory
delete_temp_dir
(
self
.
import_dir
)
delete_temp_dir
(
self
.
export_dir
)
def
setUp
(
self
):
self
.
import_dir
=
mkdtemp
(
prefix
=
"import"
)
self
.
addCleanup
(
shutil
.
rmtree
,
self
.
import_dir
)
self
.
export_dir
=
mkdtemp
(
prefix
=
"export"
)
self
.
addCleanup
(
shutil
.
rmtree
,
self
.
export_dir
)
def
tearDown
(
self
):
pass
# and clean up the database:
# TestCenterUser.objects.all().delete()
# TestCenterRegistration.objects.all().delete()
...
...
common/lib/tempdir.py
0 → 100644
View file @
c3b571bf
"""Make temporary directories nicely."""
import
atexit
import
os.path
import
shutil
import
tempfile
def
mkdtemp_clean
(
suffix
=
""
,
prefix
=
"tmp"
,
dir
=
None
):
"""Just like mkdtemp, but the directory will be deleted when the process ends."""
the_dir
=
tempfile
.
mkdtemp
(
suffix
=
suffix
,
prefix
=
prefix
,
dir
=
dir
)
atexit
.
register
(
cleanup_tempdir
,
the_dir
)
return
the_dir
def
cleanup_tempdir
(
the_dir
):
"""Called on process exit to remove a temp directory."""
if
os
.
path
.
exists
(
the_dir
):
shutil
.
rmtree
(
the_dir
)
common/lib/xmodule/xmodule/tests/test_export.py
View file @
c3b571bf
...
...
@@ -4,7 +4,7 @@ from fs.osfs import OSFS
from
nose.tools
import
assert_equals
,
assert_true
from
path
import
path
from
tempfile
import
mkdtemp
from
shutil
import
copytree
import
shutil
from
xmodule.modulestore.xml
import
XMLModuleStore
...
...
@@ -46,11 +46,11 @@ class RoundTripTestCase(unittest.TestCase):
Thus we make sure that export and import work properly.
'''
def
check_export_roundtrip
(
self
,
data_dir
,
course_dir
):
root_dir
=
path
(
mkdtemp
()
)
root_dir
=
path
(
self
.
temp_dir
)
print
"Copying test course to temp dir {0}"
.
format
(
root_dir
)
data_dir
=
path
(
data_dir
)
copytree
(
data_dir
/
course_dir
,
root_dir
/
course_dir
)
shutil
.
copytree
(
data_dir
/
course_dir
,
root_dir
/
course_dir
)
print
"Starting import"
initial_import
=
XMLModuleStore
(
root_dir
,
course_dirs
=
[
course_dir
])
...
...
@@ -108,6 +108,8 @@ class RoundTripTestCase(unittest.TestCase):
def
setUp
(
self
):
self
.
maxDiff
=
None
self
.
temp_dir
=
mkdtemp
()
self
.
addCleanup
(
shutil
.
rmtree
,
self
.
temp_dir
)
def
test_toy_roundtrip
(
self
):
self
.
check_export_roundtrip
(
DATA_DIR
,
"toy"
)
...
...
lms/envs/common.py
View file @
c3b571bf
...
...
@@ -20,7 +20,6 @@ Longer TODO:
"""
import
sys
import
os
import
tempfile
from
xmodule.static_content
import
write_module_styles
,
write_module_js
from
path
import
path
...
...
@@ -133,7 +132,8 @@ OPENID_PROVIDER_TRUSTED_ROOTS = ['cs50.net', '*.cs50.net']
################################## MITXWEB #####################################
# This is where we stick our compiled template files. Most of the app uses Mako
# templates
MAKO_MODULE_DIR
=
tempfile
.
mkdtemp
(
'mako'
)
from
tempdir
import
mkdtemp_clean
MAKO_MODULE_DIR
=
mkdtemp_clean
(
'mako'
)
MAKO_TEMPLATES
=
{}
MAKO_TEMPLATES
[
'main'
]
=
[
PROJECT_ROOT
/
'templates'
,
COMMON_ROOT
/
'templates'
,
...
...
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