Example #1
0
 def testSubstitute1(self):
     config = Configuration()
     config.readfp(StringIO(CONFIG1))
     assert config.has_section('section1')
     assert not config.has_section('section2')
     assert not config.has_section('foo')
     assert not config.has_section('bar')
     assert not config.has_section('bar2')
     assert config.has_option('section1', 'foo')
     assert config.has_option('section1', 'name')
     assert config.get('section1', 'name') == os.path.basename(sys.argv[0])
     assert config.get('section1', 'cwd') == os.getcwd()
     assert config.has_option('section1', 'bar')
     assert config.has_option('section1', 'bar2')
     assert config.get('section1', 'foo') == 'bar'
     assert config.get('section1', 'bar') == 'bar'
     assert config.get('section1', 'bar2') == 'bar'
Example #2
0
 def testSubstitute2(self):
     os.environ['SOME_ENV_VAR'] = 'test_test_test'
     config = Configuration()
     config.readfp(StringIO(CONFIG2))
     assert config.has_section('section1')
     assert config.has_section('section2')
     assert not config.has_section('foo')
     assert not config.has_section('bar')
     assert not config.has_section('bar2')
     assert config.has_option('section1', 'foo')
     assert config.has_option('section1', 'bar')
     assert not config.has_option('section1', 'bar2')
     assert config.has_option('section2', 'foo')
     assert config.has_option('section2', 'bar')
     assert config.get('section1', 'foo') == 'bar'
     assert config.get('section1', 'bar') == 'bar'
     assert config.get('section2', 'foo') == 'bar'
     assert config.get('section2', 'bar') == os.environ['SOME_ENV_VAR']
Example #3
0
    def testInclude(self):
        fd, tempPath = tempfile.mkstemp(suffix='.cfg')

        def unlinkTemp(path):
            try:
                os.unlink(path)
            except:
                pass

        atexit.register(unlinkTemp, tempPath)
        fp = os.fdopen(fd, "w")
        print >> fp, '[section3]\nbaz = somevalue\n'
        fp.close()

        s = '%s\n\n%%include "%s"\n' % (CONFIG2, tempPath)

        os.environ['SOME_ENV_VAR'] = 'test_test_test'
        config = Configuration()
        config.readfp(StringIO(s))
        unlinkTemp(tempPath)
        assert config.has_section('section1')
        assert config.has_section('section2')
        assert config.has_section('section3')
        assert not config.has_section('foo')
        assert not config.has_section('bar')
        assert not config.has_section('bar2')
        assert config.has_option('section1', 'foo')
        assert config.has_option('section1', 'bar')
        assert not config.has_option('section1', 'bar2')
        assert config.has_option('section2', 'foo')
        assert config.has_option('section2', 'bar')
        assert config.has_option('section3', 'baz')
        assert config.get('section1', 'foo') == 'bar'
        assert config.get('section1', 'bar') == 'bar'
        assert config.get('section2', 'foo') == 'bar'
        assert config.get('section2', 'bar') == os.environ['SOME_ENV_VAR']
        assert config.get('section3', 'baz') == 'somevalue'