Home | History | Annotate | Download | only in suite_scheduler
      1 #!/usr/bin/python
      2 #
      3 # Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
      4 # Use of this source code is governed by a BSD-style license that can be
      5 # found in the LICENSE file.
      6 
      7 """Unit tests for site_utils/forgiving_config_parser.py."""
      8 
      9 import logging, mox, os, tempfile, unittest
     10 import forgiving_config_parser
     11 
     12 class ForgivingConfigParserTest(mox.MoxTestBase):
     13 
     14 
     15     def setUp(self):
     16         super(ForgivingConfigParserTest, self).setUp()
     17         self._tmpconfig = tempfile.NamedTemporaryFile()
     18 
     19 
     20     def testReRead(self):
     21         """Test that we reread() loads the same config file over again."""
     22         section = 'first'
     23         option1 = 'option1'
     24         value1 = 'value1'
     25         option2 = 'option2'
     26         value2 = 'value2'
     27 
     28         # Create initial file.
     29         initial = forgiving_config_parser.ForgivingConfigParser()
     30         initial.add_section(section)
     31         initial.set(section, option1, value1)
     32         with open(self._tmpconfig.name, 'w') as conf_file:
     33             initial.write(conf_file)
     34 
     35         to_test = forgiving_config_parser.ForgivingConfigParser()
     36         to_test.read(self._tmpconfig.name)
     37         self.assertEquals(value1, to_test.getstring(section, option1))
     38         self.assertEquals(None, to_test.getstring(section, option2))
     39 
     40 
     41         initial.set(section, option2, value2)
     42         initial.remove_option(section, option1)
     43         with open(self._tmpconfig.name, 'w') as conf_file:
     44             initial.write(conf_file)
     45 
     46         to_test.reread()
     47         self.assertEquals(None, to_test.getstring(section, option1))
     48         self.assertEquals(value2, to_test.getstring(section, option2))
     49 
     50 
     51 if __name__ == '__main__':
     52     unittest.main()
     53