summaryrefslogtreecommitdiff
path: root/tests/regressiontests/admin_scripts/tests.py
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2012-05-05 14:01:38 +0200
committerClaude Paroz <claude@2xlibre.net>2012-05-05 14:06:36 +0200
commit865cd35c9b357e20994f6c6a51f2ae000ba0a3ee (patch)
tree9db42053673c856a2527d5573d7f8fd682334182 /tests/regressiontests/admin_scripts/tests.py
parentec5423df05dedeee6651c36dd4d90fec0d8cca7c (diff)
Made more extensive usage of context managers with open.
Diffstat (limited to 'tests/regressiontests/admin_scripts/tests.py')
-rw-r--r--tests/regressiontests/admin_scripts/tests.py53
1 files changed, 26 insertions, 27 deletions
diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py
index 4c4edbbb71..98492ffbdd 100644
--- a/tests/regressiontests/admin_scripts/tests.py
+++ b/tests/regressiontests/admin_scripts/tests.py
@@ -27,32 +27,32 @@ class AdminScriptTestCase(unittest.TestCase):
if is_dir:
settings_dir = os.path.join(test_dir, filename)
os.mkdir(settings_dir)
- settings_file = open(os.path.join(settings_dir, '__init__.py'), 'w')
+ settings_file_path = os.path.join(settings_dir, '__init__.py')
else:
- settings_file = open(os.path.join(test_dir, filename), 'w')
- settings_file.write('# Settings file automatically generated by regressiontests.admin_scripts test case\n')
- exports = [
- 'DATABASES',
- 'ROOT_URLCONF',
- 'SECRET_KEY',
- ]
- for s in exports:
- if hasattr(settings, s):
- o = getattr(settings, s)
- if not isinstance(o, dict):
- o = "'%s'" % o
- settings_file.write("%s = %s\n" % (s, o))
+ settings_file_path = os.path.join(test_dir, filename)
- if apps is None:
- apps = ['django.contrib.auth', 'django.contrib.contenttypes', 'regressiontests.admin_scripts']
+ with open(settings_file_path, 'w') as settings_file:
+ settings_file.write('# Settings file automatically generated by regressiontests.admin_scripts test case\n')
+ exports = [
+ 'DATABASES',
+ 'ROOT_URLCONF',
+ 'SECRET_KEY',
+ ]
+ for s in exports:
+ if hasattr(settings, s):
+ o = getattr(settings, s)
+ if not isinstance(o, dict):
+ o = "'%s'" % o
+ settings_file.write("%s = %s\n" % (s, o))
- settings_file.write("INSTALLED_APPS = %s\n" % apps)
+ if apps is None:
+ apps = ['django.contrib.auth', 'django.contrib.contenttypes', 'regressiontests.admin_scripts']
- if sdict:
- for k, v in sdict.items():
- settings_file.write("%s = %s\n" % (k, v))
+ settings_file.write("INSTALLED_APPS = %s\n" % apps)
- settings_file.close()
+ if sdict:
+ for k, v in sdict.items():
+ settings_file.write("%s = %s\n" % (k, v))
def remove_settings(self, filename, is_dir=False):
full_name = os.path.join(test_dir, filename)
@@ -989,13 +989,12 @@ class ManageSettingsWithImportError(AdminScriptTestCase):
if is_dir:
settings_dir = os.path.join(test_dir, filename)
os.mkdir(settings_dir)
- settings_file = open(os.path.join(settings_dir, '__init__.py'), 'w')
+ settings_file_path = os.path.join(settings_dir, '__init__.py')
else:
- settings_file = open(os.path.join(test_dir, filename), 'w')
- settings_file.write('# Settings file automatically generated by regressiontests.admin_scripts test case\n')
- settings_file.write('# The next line will cause an import error:\nimport foo42bar\n')
-
- settings_file.close()
+ settings_file_path = os.path.join(test_dir, filename)
+ with open(settings_file_path, 'w') as settings_file:
+ settings_file.write('# Settings file automatically generated by regressiontests.admin_scripts test case\n')
+ settings_file.write('# The next line will cause an import error:\nimport foo42bar\n')
def test_builtin_command(self):
"import error: manage.py builtin commands shows useful diagnostic info when settings with import errors is provided"