Only remove contents of directory when clicking 'clear cache'
[mevemon] / package / src / tests / test_util.py
1 """ this module tests the util.py module """
2 import unittest
3 import tempfile
4 import shutil
5 import os
6
7 import util
8
9 NUMBERS = { 12345:'12,345', 12345.23:'12,345.23', 1234:'1,234'}
10
11 class TestUtil(unittest.TestCase):
12     def test_comma(self):
13         for number in NUMBERS.keys():
14             self.assertEqual(util.comma(number), NUMBERS[number])
15
16     def test_clean_dir(self):
17         self._setup_files()
18         try: 
19             self.assertEqual(len(os.listdir(self.basedir)), 3)
20             util.clean_dir(self.basedir)
21             self.assertTrue(os.path.exists(self.basedir))
22             self.assertEqual(len(os.listdir(self.basedir)), 0)
23         finally:
24             if os.path.exists(self.basedir):
25                 shutil.rmtree(self.basedir)
26
27     def _setup_files(self):
28         self.basedir = os.path.join(tempfile.gettempdir(), "mevemontest")
29         os.mkdir(self.basedir)
30         os.mkdir(os.path.join(self.basedir, "testdir"))
31         os.system("touch %s" % os.path.join(self.basedir, "testfile1"))
32         os.system("touch %s" % os.path.join(self.basedir, "testfile2"))
33