~pythonregexp2.7/python/issue2636-12

« back to all changes in this revision

Viewing changes to Lib/test/test_cfgparser.py

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-06-09 14:52:42 UTC
  • mfrom: (39033.1.3 Regexp-2.6)
  • Revision ID: darklord@timehorse.com-20080609145242-9m268zc6u87rp1vp
Merged in changes from the core Regexp branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import configparser
 
1
import ConfigParser
2
2
import StringIO
3
3
import unittest
4
4
import UserDict
94
94
                    "remove_option() failed to report non-existance of option"
95
95
                    " that was removed")
96
96
 
97
 
        self.assertRaises(configparser.NoSectionError,
 
97
        self.assertRaises(ConfigParser.NoSectionError,
98
98
                          cf.remove_option, 'No Such Section', 'foo')
99
99
 
100
100
        eq(cf.get('Long Line', 'foo'),
147
147
 
148
148
    def test_parse_errors(self):
149
149
        self.newconfig()
150
 
        self.parse_error(configparser.ParsingError,
 
150
        self.parse_error(ConfigParser.ParsingError,
151
151
                         "[Foo]\n  extra-spaces: splat\n")
152
 
        self.parse_error(configparser.ParsingError,
 
152
        self.parse_error(ConfigParser.ParsingError,
153
153
                         "[Foo]\n  extra-spaces= splat\n")
154
 
        self.parse_error(configparser.ParsingError,
 
154
        self.parse_error(ConfigParser.ParsingError,
155
155
                         "[Foo]\noption-without-value\n")
156
 
        self.parse_error(configparser.ParsingError,
 
156
        self.parse_error(ConfigParser.ParsingError,
157
157
                         "[Foo]\n:value-without-option-name\n")
158
 
        self.parse_error(configparser.ParsingError,
 
158
        self.parse_error(ConfigParser.ParsingError,
159
159
                         "[Foo]\n=value-without-option-name\n")
160
 
        self.parse_error(configparser.MissingSectionHeaderError,
 
160
        self.parse_error(ConfigParser.MissingSectionHeaderError,
161
161
                         "No Section!\n")
162
162
 
163
163
    def parse_error(self, exc, src):
170
170
                         "new ConfigParser should have no defined sections")
171
171
        self.failIf(cf.has_section("Foo"),
172
172
                    "new ConfigParser should have no acknowledged sections")
173
 
        self.assertRaises(configparser.NoSectionError,
 
173
        self.assertRaises(ConfigParser.NoSectionError,
174
174
                          cf.options, "Foo")
175
 
        self.assertRaises(configparser.NoSectionError,
 
175
        self.assertRaises(ConfigParser.NoSectionError,
176
176
                          cf.set, "foo", "bar", "value")
177
 
        self.get_error(configparser.NoSectionError, "foo", "bar")
 
177
        self.get_error(ConfigParser.NoSectionError, "foo", "bar")
178
178
        cf.add_section("foo")
179
 
        self.get_error(configparser.NoOptionError, "foo", "bar")
 
179
        self.get_error(ConfigParser.NoOptionError, "foo", "bar")
180
180
 
181
181
    def get_error(self, exc, section, option):
182
182
        try:
215
215
    def test_weird_errors(self):
216
216
        cf = self.newconfig()
217
217
        cf.add_section("Foo")
218
 
        self.assertRaises(configparser.DuplicateSectionError,
 
218
        self.assertRaises(ConfigParser.DuplicateSectionError,
219
219
                          cf.add_section, "Foo")
220
220
 
221
221
    def test_write(self):
324
324
 
325
325
 
326
326
class ConfigParserTestCase(TestCaseBase):
327
 
    config_class = configparser.ConfigParser
 
327
    config_class = ConfigParser.ConfigParser
328
328
 
329
329
    def test_interpolation(self):
330
330
        cf = self.get_interpolation_config()
335
335
           "something with lots of interpolation (9 steps)")
336
336
        eq(cf.get("Foo", "bar10"),
337
337
           "something with lots of interpolation (10 steps)")
338
 
        self.get_error(configparser.InterpolationDepthError, "Foo", "bar11")
 
338
        self.get_error(ConfigParser.InterpolationDepthError, "Foo", "bar11")
339
339
 
340
340
    def test_interpolation_missing_value(self):
341
341
        cf = self.get_interpolation_config()
342
 
        e = self.get_error(configparser.InterpolationError,
 
342
        e = self.get_error(ConfigParser.InterpolationError,
343
343
                           "Interpolation Error", "name")
344
344
        self.assertEqual(e.reference, "reference")
345
345
        self.assertEqual(e.section, "Interpolation Error")
375
375
 
376
376
 
377
377
class RawConfigParserTestCase(TestCaseBase):
378
 
    config_class = configparser.RawConfigParser
 
378
    config_class = ConfigParser.RawConfigParser
379
379
 
380
380
    def test_interpolation(self):
381
381
        cf = self.get_interpolation_config()
410
410
 
411
411
 
412
412
class SafeConfigParserTestCase(ConfigParserTestCase):
413
 
    config_class = configparser.SafeConfigParser
 
413
    config_class = ConfigParser.SafeConfigParser
414
414
 
415
415
    def test_safe_interpolation(self):
416
416
        # See http://www.python.org/sf/511737