def test_save(self): """ save """ p = self.preferences # Get the application scope. application = p.node('application/') tmp = join(self.tmpdir, 'test.ini') application.filename = tmp # Set a value. p.set('acme.ui.bgcolor', 'red') # Save all scopes. p.save() # Make sure a file was written. self.assertEqual(True, os.path.exists(tmp)) # Load the 'ini' file into a new preferences node and make sure the # preference is in there. p = Preferences() p.load(tmp) self.assertEqual('red', p.get('acme.ui.bgcolor')) # Cleanup. os.remove(tmp) return
def test_save(self): """ save """ p = self.preferences # Load the preferences from an 'ini' file. p.load(self.example) # Make sure it was all loaded! self.assertEqual('blue', p.get('acme.ui.bgcolor')) self.assertEqual('50', p.get('acme.ui.width')) self.assertEqual('1.0', p.get('acme.ui.ratio')) self.assertEqual('True', p.get('acme.ui.visible')) self.assertEqual('acme ui', p.get('acme.ui.description')) self.assertEqual('[1, 2, 3, 4]', p.get('acme.ui.offsets')) self.assertEqual("['joe', 'fred', 'jane']", p.get('acme.ui.names')) self.assertEqual('splash', p.get('acme.ui.splash_screen.image')) self.assertEqual('red', p.get('acme.ui.splash_screen.fgcolor')) # Make a change. p.set('acme.ui.bgcolor', 'yellow') # Save it to another file. tmp = join(self.tmpdir, 'tmp.ini') p.save(tmp) try: # Load it into a new node. p = Preferences() p.load(tmp) # Make sure it was all loaded! self.assertEqual('yellow', p.get('acme.ui.bgcolor')) self.assertEqual('50', p.get('acme.ui.width')) self.assertEqual('1.0', p.get('acme.ui.ratio')) self.assertEqual('True', p.get('acme.ui.visible')) self.assertEqual('acme ui', p.get('acme.ui.description')) self.assertEqual('[1, 2, 3, 4]', p.get('acme.ui.offsets')) self.assertEqual("['joe', 'fred', 'jane']", p.get('acme.ui.names')) self.assertEqual('splash', p.get('acme.ui.splash_screen.image')) self.assertEqual('red', p.get('acme.ui.splash_screen.fgcolor')) finally: # Clean up! os.remove(tmp) return
def test_flush(self): """ flush """ p = self.preferences # A temporary .ini file for this test. tmp = join(self.tmpdir, 'tmp.ini') # This could be set in the constructor of course, its just here we # want to use the instance declared in 'setUp'. p.filename = tmp try: # Load the preferences from an 'ini' file. p.load(self.example) # Flush it. p.flush() # Load it into a new node. p = Preferences() p.load(tmp) # Make sure it was all loaded! self.assertEqual('blue', p.get('acme.ui.bgcolor')) self.assertEqual('50', p.get('acme.ui.width')) self.assertEqual('1.0', p.get('acme.ui.ratio')) self.assertEqual('True', p.get('acme.ui.visible')) self.assertEqual('acme ui', p.get('acme.ui.description')) self.assertEqual('[1, 2, 3, 4]', p.get('acme.ui.offsets')) self.assertEqual("['joe', 'fred', 'jane']", p.get('acme.ui.names')) self.assertEqual('splash', p.get('acme.ui.splash_screen.image')) self.assertEqual('red', p.get('acme.ui.splash_screen.fgcolor')) finally: # Clean up! os.remove(tmp) return