home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / pyshared / computerjanitorapp / state_tests.py < prev    next >
Encoding:
Python Source  |  2009-03-04  |  1.8 KB  |  57 lines

  1. # state_tests.py - unit tests for store.py
  2. # Copyright (C) 2008, 2009  Canonical, Ltd.
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, version 3 of the License.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  15.  
  16.  
  17. import os
  18. import tempfile
  19. import unittest
  20.  
  21. import computerjanitorapp
  22.  
  23.  
  24. class StateTests(unittest.TestCase):
  25.  
  26.     def setUp(self):
  27.         self.state = computerjanitorapp.State()
  28.  
  29.     def testInitiallyEverythingIsEnabled(self):
  30.         self.assert_(self.state.is_enabled("foo"))
  31.  
  32.     def testDisablesWhenAsked(self):
  33.         self.state.disable("foo")
  34.         self.assertFalse(self.state.is_enabled("foo"))
  35.  
  36.     def testEnablesDisabledCruft(self):
  37.         self.state.disable("foo")
  38.         self.state.enable("foo")
  39.         self.assert_(self.state.is_enabled("foo"))
  40.  
  41.     def testEnablesEnabledCruft(self):
  42.         self.state.enable("foo")
  43.         self.assert_(self.state.is_enabled("foo"))
  44.  
  45.     def testSavesAndLoadsFiles(self):
  46.         fd, filename = tempfile.mkstemp()
  47.         os.close(fd)
  48.         self.state.enable("foo")
  49.         self.state.disable("bar")
  50.         self.state.save(filename)
  51.         self.state.disable("foo")
  52.         self.state.enable("bar")
  53.         self.state.load(filename)
  54.         self.assert_(self.state.is_enabled("foo"))
  55.         self.assertFalse(self.state.is_enabled("bar"))
  56.         os.remove(filename)
  57.