Add %env section support
[tools/mic.git] / tests / test_chroot.py
1 #!/usr/bin/python
2
3 import os
4 import sys
5 import shutil
6 import tarfile
7 import StringIO
8 import unittest
9 from mic import chroot
10
11 CWD = os.path.dirname(__file__) or '.'
12 TEST_CHROOT_LOC = os.path.join(CWD, 'chroot_fixtures')
13 TEST_CHROOT_TAR = os.path.join(TEST_CHROOT_LOC, 'minchroot.tar.gz')
14 TEST_CHROOT_DIR = os.path.join(TEST_CHROOT_LOC, 'minchroot')
15
16 def suite():
17     return unittest.makeSuite(ChrootTest)
18
19 class ChrootTest(unittest.TestCase):
20
21     def setUp(self):
22         tar = tarfile.open(TEST_CHROOT_TAR, "r:gz")
23         tar.extractall(path=TEST_CHROOT_LOC)
24         self.chrootdir = TEST_CHROOT_DIR
25         self.stdout = sys.stdout
26         self.stderr = sys.stderr
27         sys.stdout = StringIO.StringIO()
28         sys.stderr = StringIO.StringIO()
29
30     def tearDown(self):
31         sys.stdout = self.stdout
32         sys.stderr = self.stderr
33         shutil.rmtree(TEST_CHROOT_DIR, ignore_errors=True)
34
35 if os.getuid() == 0:
36     def testChroot(self):
37         try:
38             chroot.chroot(TEST_CHROOT_DIR, None, 'exit')
39         except Exception, e:
40             raise self.failureException(e)
41
42 if __name__ == "__main__":
43     unittest.main()
44