root/branches/mk/tests/functional/test_cleaning_up.py

Revision 131, 2.4 kB (checked in by mk, 6 years ago)

Second part of cleaning_up test fix.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 from glob import glob
2 import os
3 import tempfile
4
5 from _helper_cheesecake import FunctionalTest, read_file_contents, NOSE_PATH, INVALID_PACKAGE_PATH
6
7
8 def filter_our_files(files):
9     uid = os.getuid()
10     return filter(lambda filename: os.lstat(filename).st_uid == uid, files)
11
12 def get_tmp_files_starting_with(prefix):
13     return glob(os.path.join(tempfile.gettempdir(), prefix + "*"))
14
15 def get_tmp_files():
16     return get_tmp_files_starting_with(tempfile.gettempprefix())
17
18 def get_cheesecake_files():
19     return get_tmp_files_starting_with("cheesecake")
20
21
22 class TestCleaningUp(FunctionalTest):
23     def setUp(self):
24         self.temp_files = filter_our_files(get_tmp_files())
25         self.cheesecake_files = filter_our_files(get_cheesecake_files())
26         self.sandbox = tempfile.mkdtemp()
27         self.logfile = tempfile.mktemp(prefix='log')
28
29     def test_valid_no_tmp(self):
30         "Check that no files are left in temp by Cheesecake."
31         self._run_cheesecake('-p %s -s %s -l %s' % (NOSE_PATH, self.sandbox, self.logfile))
32
33         self._assert_success()
34
35         # Check that Cheesecake didn't leave sandbox.
36         assert not os.path.exists(self.sandbox)
37
38         # Check that log file has been removed.
39         assert not os.path.exists(self.logfile)
40
41         # Check that Cheesecake didn't leave any cheesecake* files.
42         assert filter_our_files(get_cheesecake_files()) == self.cheesecake_files
43
44         # Check that Cheesecake didn't leave any new tmp* files.
45         assert filter_our_files(get_tmp_files()) == self.temp_files
46
47     def test_invalid_no_tmp(self):
48         "Check that no files are left in temp by Cheesecake during scoring an invalid package."
49         self._run_cheesecake('-p %s -s %s -l %s' % (INVALID_PACKAGE_PATH, self.sandbox, self.logfile))
50
51         # Package cannot be unpacked, but error was handled and scores, so no error here.
52         self._assert_success()
53
54         # Check that Cheesecake didn't leave sandbox.
55         assert not os.path.exists(self.sandbox)
56
57         # Check that Cheesecake didn't leave any cheesecake* files.
58         assert filter_our_files(get_cheesecake_files()) == self.cheesecake_files
59
60         # Check that Cheesecake didn't leave any new tmp* files.
61         assert filter_our_files(get_tmp_files()) == self.temp_files
62
63         # Delete the log file, so that it doesn't pollute /tmp
64         self._cleanup_logfile()
65
66     def _cleanup_logfile(self):
67         os.unlink(self.logfile)
Note: See TracBrowser for help on using the browser.