]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Fix options.parse_config_file on Python 3.
authorBen Darnell <ben@bendarnell.com>
Thu, 28 Mar 2013 02:55:04 +0000 (22:55 -0400)
committerBen Darnell <ben@bendarnell.com>
Thu, 28 Mar 2013 02:55:04 +0000 (22:55 -0400)
Add a test for this function.

Closes #702.

MANIFEST.in
setup.py
tornado/options.py
tornado/test/options_test.cfg [new file with mode: 0644]
tornado/test/options_test.py

index 6e817251f0f9f7dbf393738d654378785420dd90..73848e386de77c7da5941409871e1673cc4f0b18 100644 (file)
@@ -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*
\ No newline at end of file
index 56b8e9c579b5733703d77e23a7b7933d8352cd20..19741e6e152df43d798aed1cbb0220af0a7eb285 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -38,13 +38,14 @@ distutils.core.setup(
         # 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",
index 45c30f7f56bc893f27d44cf1f7efa26c163140c6..b96f815d29da6de5568aff7a7197821767a12487 100644 (file)
@@ -69,7 +69,7 @@ import textwrap
 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 @@ class OptionParser(object):
         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])
diff --git a/tornado/test/options_test.cfg b/tornado/test/options_test.cfg
new file mode 100644 (file)
index 0000000..1727146
--- /dev/null
@@ -0,0 +1,2 @@
+port=443
+port=443
\ No newline at end of file
index 9ec37ffb596b08afd46ae127e7cdad67fa4ed44e..ba34495d9b1d443354d807355865684f5cffc33d 100644 (file)
@@ -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 @@ class OptionsTest(unittest.TestCase):
         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