Ejemplo n.º 1
0
    def setUp(self):
        """
        Creates an application and
        almost launches it.
        """
        # Make whatever config class that application uses only look for our
        # Set up our customised config file
        logFileName = Path('tmp/app data/test.conf')
        sys.argv[0] = 'exe/exe'
        Config._getConfigPathOptions = lambda s: [logFileName]
        if not logFileName.dirname().exists():
            logFileName.dirname().makedirs()
        confParser = ConfigParser()
        self._setupConfigFile(confParser)
        confParser.write(logFileName)
        # Start up the app and friends
        if G.application is None:
            G.application = Application()

        self.app = G.application
        G.application = self.app
        self.app.loadConfiguration()
        self.app.preLaunch()
        self.client = FakeClient()
        self.package = Package('temp')
        self.session = FakeSession()
        self.app.webServer.root.bindNewPackage(self.package, self.session)
        self.mainpage = self.app.webServer.root.mainpages[
            self.session.uid]['temp']
        self.mainpage.idevicePane.client = self.client
 def setUp(self):
     """
     Creates an application and
     almost launches it.
     """
     # Make whatever config class that application uses only look for our
     # Set up our customised config file
     logFileName = Path('tmp/app data/test.conf')
     sys.argv[0] = 'exe/exe'
     Config._getConfigPathOptions = lambda s: [logFileName]
     if not logFileName.dirname().exists():
         logFileName.dirname().makedirs()
     confParser = ConfigParser()
     self._setupConfigFile(confParser)
     confParser.write(logFileName)
     # Start up the app and friends
     if G.application is None:
         G.application = Application()
         
     self.app = G.application
     G.application = self.app
     self.app.loadConfiguration()
     self.app.preLaunch()
     self.client = FakeClient()
     self.package = Package('temp')
     self.session = FakeSession()
     self.app.webServer.root.bindNewPackage(self.package, self.session)
     self.mainpage = self.app.webServer.root.mainpages[self.session.uid]['temp']
     self.mainpage.idevicePane.client = self.client
Ejemplo n.º 3
0
 def testUpgradeAppDir(self):
     """
     Tests that config files with
     'appDataDir' are upgraded to 'configDir'
     """
     # Write the old style config file
     configPath = Path(u'test.exe.conf')
     if configPath.exists():
         configPath.remove()
     oldParser = ConfigParser()
     system = oldParser.addSection('system')
     system.appDataDir = 'my old app data dir'
     oldParser.write(configPath)
     del system
     del oldParser
     # Make the config instance load it
     Config._getConfigPathOptions = lambda self: ['test.exe.conf']
     myconfig = Config()
     myconfig.loadSettings()
     # Check if it reads the old value into the new variable
     assert not hasattr(myconfig, 'appDataDir')
     self.assertEquals(myconfig.configPath, 'test.exe.conf')
     self.assertEquals(myconfig.configDir, 'my old app data dir')
     # Check if it has upgraded the file and added in some nice default values
     newParser = ConfigParser()
     newParser.read(configPath)
     self.assertEquals(newParser.system.configDir, 'my old app data dir')
Ejemplo n.º 4
0
 def testUpgradeAppDir(self):
     """
     Tests that config files with
     'appDataDir' are upgraded to 'configDir'
     """
     # Write the old style config file
     configPath = Path(u'test.exe.conf')
     if configPath.exists():
         configPath.remove()
     oldParser = ConfigParser()
     system = oldParser.addSection('system')
     system.appDataDir = 'my old app data dir'
     oldParser.write(configPath)
     del system
     del oldParser
     # Make the config instance load it
     Config._getConfigPathOptions = lambda self: ['test.exe.conf']
     myconfig = Config()
     myconfig.loadSettings()
     # Check if it reads the old value into the new variable
     assert not hasattr(myconfig, 'appDataDir')
     self.assertEquals(myconfig.configPath, 'test.exe.conf')
     self.assertEquals(myconfig.configDir, 'my old app data dir')
     # Check if it has upgraded the file and added in some nice default values
     newParser = ConfigParser()
     newParser.read(configPath)
     self.assertEquals(newParser.system.configDir, 'my old app data dir')
Ejemplo n.º 5
0
 def testShortening(self):
     """There was a bug (Issue 66) where when a longer name was read
     and a shorter name was written, the extra characters of the 
     longer name would remain in the entry"""
     file_ = open('temp.ini', 'w')
     file_.write(TEST_TEXT)
     file_.close()
     self.c.read('temp.ini')
     self.c.set('second', 'available', 'abcdefghijklmnop')
     self.c.write('temp.ini')
     c2 = ConfigParser()
     c2.read('temp.ini')
     c2.set('second', 'available', 'short')
     c2.write('temp.ini')
     self.c.read('temp.ini')
     assert self.c.get('second', 'available', '') == 'short', \
         self.c.get('second', 'available', '')
Ejemplo n.º 6
0
 def testShortening(self):
     """There was a bug (Issue 66) where when a longer name was read
     and a shorter name was written, the extra characters of the 
     longer name would remain in the entry"""
     file_ = open('temp.ini', 'w')
     file_.write(TEST_TEXT)
     file_.close()
     self.c.read('temp.ini')
     self.c.set('second', 'available', 'abcdefghijklmnop')
     self.c.write('temp.ini')
     c2 = ConfigParser()
     c2.read('temp.ini')
     c2.set('second', 'available', 'short')
     c2.write('temp.ini')
     self.c.read('temp.ini')
     assert self.c.get('second', 'available', '') == 'short', \
         self.c.get('second', 'available', '')
 def check_application_for_test(cls):
     logFileName = Path('tmp/app data/test.conf')
     sys.argv[0] = 'exe/exe'
     Config._getConfigPathOptions = lambda s: [logFileName]
     if not logFileName.dirname().exists():
         logFileName.dirname().makedirs()
     confParser = ConfigParser()
     SuperTestCase.update_config_parser(confParser)
     confParser.write(logFileName)
     
     if G.application is None:
         G.application = Application()
     
         G.application.loadConfiguration()
         SuperTestCase.update_config_parser(G.application.config.configParser)
         G.application.config.loadSettings()
         
         G.application.preLaunch()
Ejemplo n.º 8
0
 def setUp(self):
     """
     Creates an application and 
     almost launches it.
     """
     logFileName = Path('tmp/app data/test.conf')
     Config._getConfigPathOptions = lambda s: [logFileName]
     if not logFileName.dirname().exists():
         logFileName.dirname().makedirs()
     confParser = ConfigParser()
     self._setupConfigFile(confParser)
     confParser.write(logFileName)
     self.app = Application()
     self.app.loadConfiguration()
     self.app.preLaunch()
     self.client = FakeClient()
     self.package = Package('temp')
     self.app.webServer.root.bindNewPackage(self.package)
     self.mainpage = self.app.webServer.root.children['temp']
Ejemplo n.º 9
0
    def check_application_for_test(cls):
        logFileName = Path('tmp/app data/test.conf')
        sys.argv[0] = 'exe/exe'
        Config._getConfigPathOptions = lambda s: [logFileName]
        if not logFileName.dirname().exists():
            logFileName.dirname().makedirs()
        confParser = ConfigParser()
        SuperTestCase.update_config_parser(confParser)
        confParser.write(logFileName)

        if G.application is None:
            G.application = Application()

            G.application.loadConfiguration()
            SuperTestCase.update_config_parser(
                G.application.config.configParser)
            G.application.config.loadSettings()

            G.application.preLaunch()
Ejemplo n.º 10
0
 def setUp(self):
     """
     Creates an application and 
     almost launches it.
     """
     # Make whatever config class that application uses only look for our
     # Set up our customised config file
     logFileName = Path('tmp/app data/test.conf')
     Config._getConfigPathOptions = lambda s: [logFileName]
     if not logFileName.dirname().exists():
         logFileName.dirname().makedirs()
     confParser = ConfigParser()
     self._setupConfigFile(confParser)
     confParser.write(logFileName)
     # Start up the app and friends
     self.app = Application()
     self.app.loadConfiguration()
     self.app.preLaunch()
     self.client = FakeClient()
     self.package = Package('temp')
     self.app.webServer.root.bindNewPackage(self.package)
     self.mainpage = self.app.webServer.root.children['temp']
Ejemplo n.º 11
0
 def setUp(self):
     """
     Creates an application and 
     almost launches it.
     """
     # Make whatever config class that application uses only look for our
     # Set up our customised config file
     logFileName = Path('tmp/app data/test.conf')
     Config._getConfigPathOptions = lambda s: [logFileName]
     if not logFileName.dirname().exists():
         logFileName.dirname().makedirs()
     confParser = ConfigParser()
     self._setupConfigFile(confParser)
     confParser.write(logFileName)
     # Start up the app and friends
     self.app = Application()
     self.app.loadConfiguration()
     self.app.preLaunch()
     self.client = FakeClient()
     self.package = Package('temp')
     self.app.webServer.root.bindNewPackage(self.package)
     self.mainpage = self.app.webServer.root.children['temp']
Ejemplo n.º 12
0
 def testUpgradeAppDir(self):
     """
     Tests that config files with
     'appDataDir' are upgraded to 'configDir'
     """
     configPath = Path(u'test.exe.conf')
     if configPath.exists():
         configPath.remove()
     oldParser = ConfigParser()
     system = oldParser.addSection('system')
     system.appDataDir = 'my old app data dir'
     oldParser.write(configPath)
     del system
     del oldParser
     Config._getConfigPathOptions = lambda self: ['test.exe.conf']
     myconfig = Config()
     myconfig.loadSettings()
     assert not hasattr(myconfig, 'appDataDir')
     self.assertEquals(myconfig.configPath, 'test.exe.conf')
     self.assertEquals(myconfig.configDir, 'my old app data dir')
     newParser = ConfigParser()
     newParser.read(configPath)
     self.assertEquals(newParser.system.configDir, 'my old app data dir')
Ejemplo n.º 13
0
class TestConfigParser(unittest.TestCase):
    """
    Tests the main ConfigParser class
    """

    def setUp(self):
        """
        Creates a ConfigParser to play with
        """
        self.c = ConfigParser()

    def testRead(self):
        """Ensures that it can read from a file correctly"""
        file_ = testFile()
        self.c.read(file_)
        assert self.c._sections == {'second':
                                       {'good': 'yes',
                                        'bad': 'no',
                                         'available': 'yes',
                                         'funny-name_mate': 'crusty the clown'}, 
                                    'main': 
                                        {'running': u'on\t\u0100\u01100',
                                         'testing': 'false',
                                         'two words': 'are better than one',
                                         'no_value': '',
                                         'power': 'on', 'level': '5'}
                                    }, self.c._sections

    def testReadFileName(self):
        """Can read text"""
        goodDict = {'second': 
                        {'good': 'yes',
                         'bad': 'no',
                          'available': 'yes',
                          'funny-name_mate': 'crusty the clown'}, 
                    'main': 
                        {'running': u'on\t\u0100\u01100',
                         'testing': 'false',
                         'two words': 'are better than one',
                         'no_value': '',
                         'power': 'on',
                         'level': '5'}}
        file_ = open('temp.ini', 'w')
        file_.write(TEST_TEXT)
        file_.close()
        self.c.read('temp.ini')
        assert self.c._sections == goodDict, self.c._sections
        # Can read unicode filenames
        self.c = ConfigParser()
        self.c.read(u'temp.ini')
        assert self.c._sections == goodDict, self.c._sections
        # Can read funny string object filenames
        class MyStr(str):
            """Simply overrides string to make it a different type"""
        self.c.read(MyStr('temp.ini'))
        assert self.c._sections == goodDict, self.c._sections

    def testWrite(self):
        """Test that it writes the file nicely"""
        file_ = testFile()
        self.c.read(file_)
        # Remove an option
        del self.c._sections['main']['testing']
        # Change an option
        self.c._sections['second']['bad'] = 'definately not!   '
        # Add an option
        self.c._sections['second']['squishy'] = 'Indeed'
        # Add a section at the end
        self.c._sections['middle'] = {'is here': 'yes'}
        # write the file
        file_.seek(0)
        self.c.write(file_)
        file_.seek(0)
        result = file_.readlines()
        result = map(unicode, result, ['utf8']*len(result))
        goodResult = ['nosection=here\n',
                      '[main]\n',
                      'level=5\n',
                      'power : on\n',
                      u'running =on\t\u0100\u01100\n',
                      'two words = \tare better than one\n',
                      'no_value = \n',
                      '\n', '\n',
                      '[second]\n',
                      'good :yes\n',
                      'bad:\tdefinately not!   \n',
                      '# comment=1\n',
                      '~comment2=2\n',
                      'available\t=   yes\n',
                      'funny-name_mate: crusty the clown\n',
                      'squishy = Indeed\n',
                      '\n',
                      '[middle]\n',
                      'is here = yes']
        if result != goodResult:
            print
            for good, got in zip(goodResult, result):
                if good != got:
                    print 'Different', repr(good), repr(got)
            self.fail('See above printout')

    def testWriteNewFile(self):
        """Shouldn't have any trouble writing a write only file"""
        file_ = open('temp.ini', 'w')
        self.c.set('main', 'testing', 'de repente')
        self.c.write(file_)
        file_.close()
        file_ = open('temp.ini')
        try:
            data = file_.read()
            assert data == '[main]\ntesting = de repente', data
        finally:
            file_.close()
            os.remove('temp.ini')

    def testWriteFromFileName(self):
        """If we pass write a file name, it should open or create that file
        and write or update it"""
        if os.path.exists('temp.ini'):
            os.remove('temp.ini')
        self.c.set('main', 'testing', 'de repente')
        self.c.write('temp.ini')
        file_ = open('temp.ini')
        try:
            data = file_.read()
            assert data == '[main]\ntesting = de repente', data
        finally:
            file_.close()
            os.remove('temp.ini')
        # Test updating an existing file
        self.c.set('main', 'testing', 'ok')
        self.c.write('temp.ini')
        file_ = open('temp.ini')
        try:
            data = file_.read()
            assert data == '[main]\ntesting = ok', data
        finally:
            file_.close()
            os.remove('temp.ini')

    def testGet(self):
        """Tests the get method"""
        file_ = testFile()
        self.c.read(file_)
        assert self.c.get('main', 'testing') == 'false'
        assert self.c.get('main', 'not exists', 'default') == 'default'
        self.failUnlessRaises(ValueError, self.c.get, 'main', 'not exists')

    def testSet(self):
        """Test the set method"""
        file_ = testFile()
        self.c.read(file_)
        # An existing option
        self.c.set('main', 'testing', 'perhaps')
        assert self.c._sections['main']['testing'] == 'perhaps'
        # A new and numeric option
        self.c.set('main', 'new option', 4.1)
        self.assertEquals(self.c._sections['main']['new option'], '4.1')
        # A new option in a new section
        self.c.set('new section', 'new option', 4.1)
        assert self.c._sections['new section']['new option'] == '4.1'

    def testDel(self):
        """Should be able to delete a section and/or a value in a section"""
        file_ = testFile()
        self.c.read(file_)
        assert self.c._sections['main']['level'] == '5'
        self.c.delete('main', 'level')
        assert not self.c._sections['main'].has_key('level')
        self.c.delete('main')
        assert not self.c._sections.has_key('main')

    def testShortening(self):
        """There was a bug (Issue 66) where when a longer name was read
        and a shorter name was written, the extra characters of the 
        longer name would remain in the entry"""
        file_ = open('temp.ini', 'w')
        file_.write(TEST_TEXT)
        file_.close()
        self.c.read('temp.ini')
        self.c.set('second', 'available', 'abcdefghijklmnop')
        self.c.write('temp.ini')
        c2 = ConfigParser()
        c2.read('temp.ini')
        c2.set('second', 'available', 'short')
        c2.write('temp.ini')
        self.c.read('temp.ini')
        assert self.c.get('second', 'available', '') == 'short', \
            self.c.get('second', 'available', '')

    def testUnicodeSet(self):
        """
        Should be able to set unicode option values
        with both python internal unicode strings
        or raw string containing utf8 encoded data
        """
        file_ = open('temp.ini', 'w')
        file_.write(TEST_TEXT)
        file_.close()
        self.c.read('temp.ini')
        self.c.set('main', 'power', '\xc4\x80\xc4\x900')
        self.c.set('main', 'name', unicode('\xc4\x80\xc4\x900', 'utf8'))
        self.c.set('newSecy', 'unicode', unicode('\xc4\x80\xc4\x900', 'utf8'))
        self.c.write('temp.ini')
        c2 = ConfigParser()
        c2.read('temp.ini')
        val = unicode('\xc4\x80\xc4\x900', 'utf8')
        self.assertEquals(c2.main.power, val)
        self.assertEquals(c2.main.name, val)
        self.assertEquals(c2.newSecy.unicode, val)

    def testUnicodeFileName(self):
        """
        Should be able to write to unicode filenames
        """
        # Invent a unicode filename
        dirName = unicode('\xc4\x80\xc4\x900', 'utf8')
        fn = os.path.join(dirName, dirName)
        fn += '.ini'
        if not os.path.exists(dirName):
            os.mkdir(dirName)
        # Write some test data to our unicode file
        file_ = open(fn, 'wb')
        file_.write(TEST_TEXT)
        file_.close()
        # See if we can read and write it
        self.c.read(fn)
        self.assertEquals(self.c.main.power, 'on')
        self.c.main.power = 'off'
        self.c.write()
        # Check that it was written ok
        c2 = ConfigParser()
        c2.read(fn)
        self.assertEquals(c2.main.power, 'off')
        # Clean up
        os.remove(fn)
        os.rmdir(dirName)
Ejemplo n.º 14
0
class TestConfigParser(unittest.TestCase):
    """
    Tests the main ConfigParser class
    """

    def setUp(self):
        """
        Creates a ConfigParser to play with
        """
        self.c = ConfigParser()

    def testRead(self):
        """Ensures that it can read from a file correctly"""
        file_ = testFile()
        self.c.read(file_)
        assert self.c._sections == {'second':
                                       {'good': 'yes',
                                        'bad': 'no',
                                         'available': 'yes',
                                         'funny-name_mate': 'crusty the clown'}, 
                                    'main': 
                                        {'running': u'on\t\u0100\u01100',
                                         'testing': 'false',
                                         'two words': 'are better than one',
                                         'no_value': '',
                                         'power': 'on', 'level': '5'}
                                    }, self.c._sections

    def testReadFileName(self):
        """Can read text"""
        goodDict = {'second': 
                        {'good': 'yes',
                         'bad': 'no',
                          'available': 'yes',
                          'funny-name_mate': 'crusty the clown'}, 
                    'main': 
                        {'running': u'on\t\u0100\u01100',
                         'testing': 'false',
                         'two words': 'are better than one',
                         'no_value': '',
                         'power': 'on',
                         'level': '5'}}
        file_ = open('temp.ini', 'w')
        file_.write(TEST_TEXT)
        file_.close()
        self.c.read('temp.ini')
        assert self.c._sections == goodDict, self.c._sections
        # Can read unicode filenames
        self.c = ConfigParser()
        self.c.read(u'temp.ini')
        assert self.c._sections == goodDict, self.c._sections
        # Can read funny string object filenames
        class MyStr(str):
            """Simply overrides string to make it a different type"""
        self.c.read(MyStr('temp.ini'))
        assert self.c._sections == goodDict, self.c._sections

    def testWrite(self):
        """Test that it writes the file nicely"""
        file_ = testFile()
        self.c.read(file_)
        # Remove an option
        del self.c._sections['main']['testing']
        # Change an option
        self.c._sections['second']['bad'] = 'definately not!   '
        # Add an option
        self.c._sections['second']['squishy'] = 'Indeed'
        # Add a section at the end
        self.c._sections['middle'] = {'is here': 'yes'}
        # write the file
        file_.seek(0)
        self.c.write(file_)
        file_.seek(0)
        result = file_.readlines()
        result = map(unicode, result, ['utf8']*len(result))
        goodResult = ['nosection=here\n',
                      '[main]\n',
                      'level=5\n',
                      'power : on\n',
                      u'running =on\t\u0100\u01100\n',
                      'two words = \tare better than one\n',
                      'no_value = \n',
                      '\n', '\n',
                      '[second]\n',
                      'good :yes\n',
                      'bad:\tdefinately not!   \n',
                      '# comment=1\n',
                      '~comment2=2\n',
                      'available\t=   yes\n',
                      'funny-name_mate: crusty the clown\n',
                      'squishy = Indeed\n',
                      '\n',
                      '[middle]\n',
                      'is here = yes']
        if result != goodResult:
            print
            for good, got in zip(goodResult, result):
                if good != got:
                    print 'Different', repr(good), repr(got)
            self.fail('See above printout')

    def testWriteNewFile(self):
        """Shouldn't have any trouble writing a write only file"""
        file_ = open('temp.ini', 'w')
        self.c.set('main', 'testing', 'de repente')
        self.c.write(file_)
        file_.close()
        file_ = open('temp.ini')
        try:
            data = file_.read()
            assert data == '[main]\ntesting = de repente', data
        finally:
            file_.close()
            os.remove('temp.ini')

    def testWriteFromFileName(self):
        """If we pass write a file name, it should open or create that file
        and write or update it"""
        if os.path.exists('temp.ini'):
            os.remove('temp.ini')
        self.c.set('main', 'testing', 'de repente')
        self.c.write('temp.ini')
        file_ = open('temp.ini')
        try:
            data = file_.read()
            assert data == '[main]\ntesting = de repente', data
        finally:
            file_.close()
            os.remove('temp.ini')
        # Test updating an existing file
        self.c.set('main', 'testing', 'ok')
        self.c.write('temp.ini')
        file_ = open('temp.ini')
        try:
            data = file_.read()
            assert data == '[main]\ntesting = ok', data
        finally:
            file_.close()
            os.remove('temp.ini')

    def testGet(self):
        """Tests the get method"""
        file_ = testFile()
        self.c.read(file_)
        assert self.c.get('main', 'testing') == 'false'
        assert self.c.get('main', 'not exists', 'default') == 'default'
        self.failUnlessRaises(ValueError, self.c.get, 'main', 'not exists')

    def testSet(self):
        """Test the set method"""
        file_ = testFile()
        self.c.read(file_)
        # An existing option
        self.c.set('main', 'testing', 'perhaps')
        assert self.c._sections['main']['testing'] == 'perhaps'
        # A new and numeric option
        self.c.set('main', 'new option', 4.1)
        self.assertEquals(self.c._sections['main']['new option'], '4.1')
        # A new option in a new section
        self.c.set('new section', 'new option', 4.1)
        assert self.c._sections['new section']['new option'] == '4.1'

    def testDel(self):
        """Should be able to delete a section and/or a value in a section"""
        file_ = testFile()
        self.c.read(file_)
        assert self.c._sections['main']['level'] == '5'
        self.c.delete('main', 'level')
        assert not self.c._sections['main'].has_key('level')
        self.c.delete('main')
        assert not self.c._sections.has_key('main')

    def testShortening(self):
        """There was a bug (Issue 66) where when a longer name was read
        and a shorter name was written, the extra characters of the 
        longer name would remain in the entry"""
        file_ = open('temp.ini', 'w')
        file_.write(TEST_TEXT)
        file_.close()
        self.c.read('temp.ini')
        self.c.set('second', 'available', 'abcdefghijklmnop')
        self.c.write('temp.ini')
        c2 = ConfigParser()
        c2.read('temp.ini')
        c2.set('second', 'available', 'short')
        c2.write('temp.ini')
        self.c.read('temp.ini')
        assert self.c.get('second', 'available', '') == 'short', \
            self.c.get('second', 'available', '')

    def testUnicodeSet(self):
        """
        Should be able to set unicode option values
        with both python internal unicode strings
        or raw string containing utf8 encoded data
        """
        file_ = open('temp.ini', 'w')
        file_.write(TEST_TEXT)
        file_.close()
        self.c.read('temp.ini')
        self.c.set('main', 'power', '\xc4\x80\xc4\x900')
        self.c.set('main', 'name', unicode('\xc4\x80\xc4\x900', 'utf8'))
        self.c.set('newSecy', 'unicode', unicode('\xc4\x80\xc4\x900', 'utf8'))
        self.c.write('temp.ini')
        c2 = ConfigParser()
        c2.read('temp.ini')
        val = unicode('\xc4\x80\xc4\x900', 'utf8')
        self.assertEquals(c2.main.power, val)
        self.assertEquals(c2.main.name, val)
        self.assertEquals(c2.newSecy.unicode, val)

    def testUnicodeFileName(self):
        """
        Should be able to write to unicode filenames
        """
        # Invent a unicode filename
        dirName = unicode('\xc4\x80\xc4\x900', 'utf8')
        fn = os.path.join(dirName, dirName)
        fn += '.ini'
        if not os.path.exists(dirName):
            os.mkdir(dirName)
        # Write some test data to our unicode file
        file_ = open(fn, 'wb')
        file_.write(TEST_TEXT)
        file_.close()
        # See if we can read and write it
        self.c.read(fn)
        self.assertEquals(self.c.main.power, 'on')
        self.c.main.power = 'off'
        self.c.write()
        # Check that it was written ok
        c2 = ConfigParser()
        c2.read(fn)
        self.assertEquals(c2.main.power, 'off')
        # Clean up
        os.remove(fn)
        os.rmdir(dirName)