home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / pyshared / computerjanitor / file_cruft_tests.py < prev    next >
Encoding:
Python Source  |  2009-04-27  |  2.2 KB  |  64 lines

  1. # file_cruft_tests.py - unit tests for file_cruft.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 subprocess
  19. import tempfile
  20.  
  21. import unittest
  22.  
  23. import computerjanitor
  24.  
  25.  
  26. class FileCruftTests(unittest.TestCase):
  27.  
  28.     def setUp(self):
  29.         fd, self.pathname = tempfile.mkstemp()
  30.         os.write(fd, "x" * 1024)
  31.         os.close(fd)
  32.         self.cruft = computerjanitor.FileCruft(self.pathname, "description")
  33.  
  34.     def tearDown(self):
  35.         if False and os.path.exists(self.pathname):
  36.             os.remove(self.pathname)
  37.  
  38.     def testReturnsCorrectPrefix(self):
  39.         self.assertEqual(self.cruft.get_prefix(), "file")
  40.  
  41.     def testReturnsCorrectPrefixDescription(self):
  42.         self.assertEqual(self.cruft.get_prefix_description(), "A file on disk")
  43.  
  44.     def testReturnsCorrectShortname(self):
  45.         self.assertEqual(self.cruft.get_shortname(), self.pathname)
  46.  
  47.     def testReturnsCorrectName(self):
  48.         self.assertEqual(self.cruft.get_name(), "file:%s" % self.pathname)
  49.  
  50.     def testReturnsCorrectDescription(self):
  51.         self.assertEqual(self.cruft.get_description(), "description\n")
  52.  
  53.     def testReturnsCorrectDiskUsage(self):
  54.         p = subprocess.Popen(["du", "-s", "-B", "1", self.pathname], 
  55.                              stdout=subprocess.PIPE)
  56.         stdout, stderr = p.communicate()
  57.         du = int(stdout.splitlines()[0].split("\t")[0])
  58.         self.assertEqual(self.cruft.get_disk_usage(), du)
  59.     
  60.     def testDeletesPackage(self):
  61.         self.assert_(os.path.exists(self.pathname))
  62.         self.cruft.cleanup()
  63.         self.assertFalse(os.path.exists(self.pathname))
  64.