root/branches/mk/tests/unit/test_index_unpack.py

Revision 146, 2.2 kB (checked in by mk, 6 years ago)

Each abnormal termination of cheesecake_index should end with line starting with "Error:".

Line 
1 import os
2 import tempfile
3
4 import _path_cheesecake
5 from _helper_cheesecake import DATA_PATH
6 from cheesecake.cheesecake_index import Cheesecake, CheesecakeError, pad_msg
7
8 default_temp_directory = os.path.join(tempfile.gettempdir(), 'cheesecake_sandbox')
9
10 class TestIndexUnpack(object):
11     def setUp(self):
12         self.cheesecake = None
13         self.logfile = None
14
15     def tearDown(self):
16         if self.cheesecake:
17             self.cheesecake.cleanup()
18
19         if self.logfile:
20             os.unlink(self.logfile)
21
22     def _run_valid(self, package_file):
23         self.cheesecake = Cheesecake(path=os.path.join(DATA_PATH, package_file))
24
25         index = self.cheesecake.index["INSTALLABILITY"]["IndexUnpack"]
26         index.compute_with(self.cheesecake)
27
28         assert index.name == "IndexUnpack"
29         assert index.value == index.max_value
30         assert index.details == "package unpacked successfully"
31
32     def test_index_unpack_valid_tar_gz(self):
33         self._run_valid("package1.tar.gz")
34
35     def test_index_unpack_valid_tgz(self):
36         self._run_valid("package1.tgz")
37
38     def test_index_unpack_valid_zip(self):
39         self._run_valid("package1.zip")
40
41     def _run_invalid(self, package_file):
42         self.logfile = tempfile.mktemp()
43
44         try:
45             self.cheesecake = Cheesecake(path=os.path.join(DATA_PATH, package_file),
46                                          sandbox=default_temp_directory,
47                                          logfile=self.logfile)
48             assert 0 # This statement should not be reached
49         except CheesecakeError, e:
50             msg = "Error: Could not unpack package %s ... exiting" % \
51                   os.path.join(default_temp_directory, package_file)
52             msg += "\nDetailed info available in log file %s" % self.logfile
53             assert str(e) == msg
54
55             # If run failed log file should not be deleted.
56             assert os.path.isfile(self.logfile)
57
58     def test_index_unpack_invalid_tar_gz(self):
59         self._run_invalid("invalid_package.tar.gz")
60
61     def test_index_unpack_invalid_tgz(self):
62         self._run_invalid("invalid_package.tgz")
63
64     def test_index_unpack_invalid_zip(self):
65         self._run_invalid("invalid_package.zip")
Note: See TracBrowser for help on using the browser.