test_qubesutils.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/python -O
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2014 Wojciech Porczyk <wojciech@porczyk.eu>
  6. #
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License
  9. # as published by the Free Software Foundation; either version 2
  10. # of the License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. #
  21. import subprocess
  22. import unittest
  23. import qubes.qubesutils
  24. class TestCaseFunctionsAndConstants(unittest.TestCase):
  25. def check_output_int(self, cmd):
  26. return int(subprocess.check_output(cmd).strip().split(None, 1)[0])
  27. def test_00_BLKSIZE(self):
  28. # this may fail on systems without st_blocks
  29. self.assertEqual(qubes.qubesutils.BLKSIZE, self.check_output_int(['stat', '-c%B', '.']))
  30. def test_01_get_size_one(self):
  31. # this may fail on systems without st_blocks
  32. self.assertEqual(qubes.qubesutils.get_disk_usage_one(os.stat('.')),
  33. self.check_output_int(['stat', '-c%b', '.']) * qubes.qubesutils.BLKSIZE)
  34. def test_02_get_size(self):
  35. self.assertEqual(qubes.qubesutils.get_disk_usage('.'),
  36. self.check_output_int(['du', '-s', '--block-size=1', '.']))
  37. if __name__ == '__main__':
  38. unittest.main()