Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix options.parse_config_file on Python 3.

Add a test for this function.

Closes #702.
  • Loading branch information...
commit dd388bf18453a6e1e0ece5adfd93af83e7e3d971 1 parent e48cf35
@bdarnell bdarnell authored
View
5 MANIFEST.in
@@ -1,12 +1,13 @@
recursive-include demos *.py *.yaml *.html *.css *.js *.xml *.sql README
include tornado/ca-certificates.crt
include tornado/test/README
-include tornado/test/test.crt
-include tornado/test/test.key
include tornado/test/csv_translations/fr_FR.csv
include tornado/test/gettext_translations/fr_FR/LC_MESSAGES/tornado_test.mo
include tornado/test/gettext_translations/fr_FR/LC_MESSAGES/tornado_test.po
+include tornado/test/options_test.cfg
include tornado/test/static/robots.txt
include tornado/test/templates/utf8.html
+include tornado/test/test.crt
+include tornado/test/test.key
include runtests.sh
global-exclude _auto2to3*
View
9 setup.py
@@ -38,13 +38,14 @@
# in the sdist tarball)
"tornado.test": [
"README",
- "test.crt",
- "test.key",
- "static/robots.txt",
- "templates/utf8.html",
"csv_translations/fr_FR.csv",
"gettext_translations/fr_FR/LC_MESSAGES/tornado_test.mo",
"gettext_translations/fr_FR/LC_MESSAGES/tornado_test.po",
+ "options_test.cfg",
+ "static/robots.txt",
+ "templates/utf8.html",
+ "test.crt",
+ "test.key",
],
},
author="Facebook",
View
5 tornado/options.py
@@ -69,7 +69,7 @@ def connect():
from tornado.escape import _unicode
from tornado.log import define_logging_options
from tornado import stack_context
-from tornado.util import basestring_type
+from tornado.util import basestring_type, exec_in
class Error(Exception):
@@ -211,7 +211,8 @@ def parse_config_file(self, path, final=True):
from multiple sources.
"""
config = {}
- execfile(path, config, config)
+ with open(path) as f:
+ exec_in(f.read(), config, config)
for name in config:
if name in self._options:
self._options[name].set(config[name])
View
2  tornado/test/options_test.cfg
@@ -0,0 +1,2 @@
+port=443
+port=443
View
8 tornado/test/options_test.py
@@ -1,5 +1,6 @@
from __future__ import absolute_import, division, print_function, with_statement
+import os
import sys
from tornado.options import OptionParser, Error
@@ -26,6 +27,13 @@ def test_parse_command_line(self):
options.parse_command_line(["main.py", "--port=443"])
self.assertEqual(options.port, 443)
+ def test_parse_config_file(self):
+ options = OptionParser()
+ options.define("port", default=80)
+ options.parse_config_file(os.path.join(os.path.dirname(__file__),
+ "options_test.cfg"))
+ self.assertEquals(options.port, 443)
+
def test_parse_callbacks(self):
options = OptionParser()
self.called = False

1 comment on commit dd388bf

@whardier

Thank you!

Please sign in to comment.
Something went wrong with that request. Please try again.