root/branches/mk/tests/test_index_unpack.py

Revision 21, 2.9 kB (checked in by mk, 7 years ago)

Use tempfile.gettempdir() instead of fixed /tmp/.

Line 
1 import _path_cheesecake
2 from cheesecake.cheesecake_index import Cheesecake, CheesecakeError, pad_msg
3
4 import os
5 import tempfile
6
7 default_temp_directory = os.path.join(tempfile.gettempdir(), 'cheesecake_sandbox')
8 datadir = os.path.abspath(os.path.join(os.path.dirname(__file__), "data"))
9
10 class TestIndexUnpack(object):
11
12     def setUp(self):
13         self.cheesecake = None
14
15     def tearDown(self):
16         if not self.cheesecake:
17             return
18         self.cheesecake.cleanup()
19         os.unlink(self.cheesecake.logfile)
20
21     def test_index_unpack_valid_tar_gz(self):
22         self.cheesecake = Cheesecake(path=os.path.join(datadir, "package1.tar.gz"))
23         index = self.cheesecake.index_unpack()
24         assert index.name == "index_unpack"
25         assert index.value == self.cheesecake.INDEX_UNPACK
26         assert index.details == "package untar-ed successfully"
27
28     def test_index_unpack_valid_tgz(self):
29         self.cheesecake = Cheesecake(path=os.path.join(datadir, "package1.tgz"))
30         index = self.cheesecake.index_unpack()
31         assert index.name == "index_unpack"
32         assert index.value == self.cheesecake.INDEX_UNPACK
33         assert index.details == "package untar-ed successfully"
34
35     def test_index_unpack_valid_zip(self):
36         self.cheesecake = Cheesecake(path=os.path.join(datadir, "package1.zip"))
37         index = self.cheesecake.index_unpack()
38         assert index.name == "index_unpack"
39         assert index.value == self.cheesecake.INDEX_UNPACK
40         assert index.details == "package unzipped successfully"
41
42     def test_index_unpack_invalid_tar_gz(self):
43         try:
44             self.cheesecake = Cheesecake(path=os.path.join(datadir, "invalid_package.tar.gz"))
45             assert 0 # This statement should not be reached
46         except CheesecakeError, e:
47             msg = "Could not read tar file %s ... exiting\n" % \
48                   os.path.join(default_temp_directory, 'invalid_package.tar.gz')
49             msg += pad_msg("CHEESECAKE INDEX", 0)
50             assert str(e) == msg
51
52     def test_index_unpack_invalid_tgz(self):
53         try:
54             self.cheesecake = Cheesecake(path=os.path.join(datadir, "invalid_package.tgz"))
55             assert 0 # This statement should not be reached
56         except CheesecakeError, e:
57             msg = "Could not read tar file %s ... exiting\n" % \
58                   os.path.join(default_temp_directory, 'invalid_package.tgz')
59             msg += pad_msg("CHEESECAKE INDEX", 0)
60             assert str(e) == msg
61
62     def test_index_unpack_invalid_zip(self):
63         try:
64             self.cheesecake = Cheesecake(path=os.path.join(datadir, "invalid_package.zip"))
65             assert 0 # This statement should not be reached
66         except CheesecakeError, e:
67             msg = "Error unzipping file %s ... exiting\n" % \
68                   os.path.join(default_temp_directory, 'invalid_package.zip')
69             msg += pad_msg("CHEESECAKE INDEX", 0)
70             assert str(e) == msg
Note: See TracBrowser for help on using the browser.