Lines Matching refs:cf
37 self.cf = self.config_class(allow_no_value=self.allow_no_value)
39 self.cf = self.config_class(defaults,
41 return self.cf
44 cf = self.newconfig(defaults)
46 cf.readfp(sio)
47 return cf
76 cf = self.fromstring(config_string)
77 L = cf.sections()
96 eq(cf.get('Foo Bar', 'foo'), 'bar')
97 eq(cf.get('Spacey Bar', 'foo'), 'bar')
98 eq(cf.get('Commented Bar', 'foo'), 'bar')
99 eq(cf.get('Spaces', 'key with spaces'), 'value')
100 eq(cf.get('Spaces', 'another with spaces'), 'splat!')
102 eq(cf.get('NoValue', 'option-without-value'), None)
104 self.assertNotIn('__name__', cf.options("Foo Bar"),
109 self.assertTrue(cf.remove_option('Foo Bar', 'foo'),
111 self.assertFalse(cf.has_option('Foo Bar', 'foo'),
113 self.assertFalse(cf.remove_option('Foo Bar', 'foo'),
118 cf.remove_option, 'No Such Section', 'foo')
120 eq(cf.get('Long Line', 'foo'),
124 cf = self.newconfig()
125 cf.add_section("A")
126 cf.add_section("a")
127 L = cf.sections()
131 cf.set("a", "B", "value")
132 eq(cf.options("a"), ["b"])
133 eq(cf.get("a", "b"), "value",
135 self.assertTrue(cf.has_option("a", "b"))
136 cf.set("A", "A-B", "A-B value")
139 cf.has_option("A", opt),
141 eq(cf.options("A"), ["a-b"])
142 eq(cf.options("a"), ["b"])
143 cf.remove_option("a", "B")
144 eq(cf.options("a"), [])
147 cf = self.fromstring(
149 eq(cf.options("MySection"), ["option"])
150 eq(cf.get("MySection", "Option"), "first line\nsecond line")
153 cf = self.fromstring("[section]\nnekey=nevalue\n",
155 self.assertTrue(cf.has_option("section", "Key"))
159 cf = self.newconfig({"foo": "Bar"})
161 cf.get("DEFAULT", "Foo"), "Bar",
163 cf = self.newconfig({"Foo": "Bar"})
165 cf.get("DEFAULT", "Foo"), "Bar",
183 self.assertRaises(exc, self.cf.readfp, sio)
186 cf = self.newconfig()
187 self.assertEqual(cf.sections(), [],
189 self.assertFalse(cf.has_section("Foo"),
193 cf.options, "Foo")
195 cf.set, "foo", "bar", "value")
197 cf.add_section("foo")
202 self.cf.get(section, option)
210 cf = self.fromstring(
229 self.assertTrue(cf.getboolean('BOOLTEST', 't%d' % x))
230 self.assertFalse(cf.getboolean('BOOLTEST', 'f%d' % x))
232 cf.getboolean, 'BOOLTEST', 'e%d' % x)
235 cf = self.newconfig()
236 cf.add_section("Foo")
238 cf.add_section, "Foo")
255 cf = self.fromstring(config_string)
257 cf.write(output)
277 cf = self.fromstring("[sect]\n"
283 cf.set("sect", "option1", "splat")
284 cf.set("sect", "option1", mystr("splat"))
285 cf.set("sect", "option2", "splat")
286 cf.set("sect", "option2", mystr("splat"))
292 cf.set("sect", "option1", unicode("splat"))
293 cf.set("sect", "option2", unicode("splat"))
298 cf = self.newconfig()
299 parsed_files = cf.read([file1, "nonexistent-file"])
301 self.assertEqual(cf.get("Foo Bar", "foo"), "newbar")
303 cf = self.newconfig()
304 parsed_files = cf.read(file1)
306 self.assertEqual(cf.get("Foo Bar", "foo"), "newbar")
308 cf = self.newconfig()
309 parsed_files = cf.read(["nonexistent-file"])
312 cf = self.newconfig()
313 parsed_files = cf.read([])
346 cf = self.fromstring(
353 L = list(cf.items("section"))
368 cf = self.get_interpolation_config()
370 eq(cf.get("Foo", "getname"), "Foo")
371 eq(cf.get("Foo", "bar"), "something with interpolation (1 step)")
372 eq(cf.get("Foo", "bar9"),
374 eq(cf.get("Foo", "bar10"),
394 cf = self.newconfig()
395 cf.add_section('non-string')
396 cf.set('non-string', 'int', 1)
397 cf.set('non-string', 'list', [0, 1, 1, 2, 3, 5, 8, 13, '%('])
398 cf.set('non-string', 'dict', {'pi': 3.14159, '%(': 1,
400 cf.set('non-string', 'string_with_interpolation', '%(list)s')
401 cf.set('non-string', 'no-value')
402 self.assertEqual(cf.get('non-string', 'int', raw=True), 1)
403 self.assertRaises(TypeError, cf.get, 'non-string', 'int')
404 self.assertEqual(cf.get('non-string', 'list', raw=True),
406 self.assertRaises(TypeError, cf.get, 'non-string', 'list')
407 self.assertEqual(cf.get('non-string', 'dict', raw=True),
409 self.assertRaises(TypeError, cf.get, 'non-string', 'dict')
410 self.assertEqual(cf.get('non-string', 'string_with_interpolation',
412 self.assertRaises(ValueError, cf.get, 'non-string',
414 self.assertEqual(cf.get('non-string', 'no-value'), None)
423 cf = self.newconfig()
426 cf.add_section(s)
428 cf.set(s, 'lovely_spam{}'.format(j), self.wonderful_spam)
430 cf.write(f)
448 cf = self.get_interpolation_config()
450 eq(cf.get("Foo", "getname"), "%(__name__)s")
451 eq(cf.get("Foo", "bar"),
453 eq(cf.get("Foo", "bar9"),
455 eq(cf.get("Foo", "bar10"),
457 eq(cf.get("Foo", "bar11"),
468 cf = self.newconfig()
469 cf.add_section('non-string')
470 cf.set('non-string', 'int', 1)
471 cf.set('non-string', 'list', [0, 1, 1, 2, 3, 5, 8, 13])
472 cf.set('non-string', 'dict', {'pi': 3.14159})
473 self.assertEqual(cf.get('non-string', 'int'), 1)
474 self.assertEqual(cf.get('non-string', 'list'),
476 self.assertEqual(cf.get('non-string', 'dict'), {'pi': 3.14159})
484 cf = self.fromstring("[section]\n"
489 self.assertEqual(cf.get("section", "ok"), "xxx/%s")
490 self.assertEqual(cf.get("section", "not_ok"), "xxx/xxx/%s")
493 cf = self.fromstring("[sect]\n"
496 self.assertEqual(cf.get('sect', "option1"), "foo")
498 self.assertRaises(ValueError, cf.set, "sect", "option1", "%foo")
499 self.assertRaises(ValueError, cf.set, "sect", "option1", "foo%")
500 self.assertRaises(ValueError, cf.set, "sect", "option1", "f%oo")
502 self.assertEqual(cf.get('sect', "option1"), "foo")
505 cf.set("sect", "option2", "foo%%bar")
506 self.assertEqual(cf.get("sect", "option2"), "foo%bar")
509 cf = self.fromstring("[sect]\n"
513 self.assertRaises(TypeError, cf.set, "sect", "option1", 1)
514 self.assertRaises(TypeError, cf.set, "sect", "option1", 1.0)
515 self.assertRaises(TypeError, cf.set, "sect", "option1", object())
516 self.assertRaises(TypeError, cf.set, "sect", "option2", 1)
517 self.assertRaises(TypeError, cf.set, "sect", "option2", 1.0)
518 self.assertRaises(TypeError, cf.set, "sect", "option2", object())
521 cf = self.newconfig()
522 self.assertRaises(ValueError, cf.add_section, "default")
525 cf = self.newconfig()
526 self.assertRaises(ValueError, cf.add_section, "DEFAULT")
584 self.cf = self.config_class(defaults=defaults, dict_type=SortedDict)
585 return self.cf
596 self.cf.write(output)