root/trunk/tests/unit/_mockup_cheesecake.py

Revision 97, 1.8 kB (checked in by mk, 7 years ago)

Search for classes that define special methods (like setUp/tearDown) and files that match test_* or *_test and assume they contain unit tests.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1
2 import os
3 import shutil
4 import tempfile
5
6 import _path_cheesecake
7 from cheesecake.cheesecake_index import Cheesecake
8 from cheesecake.cheesecake_index import CheesecakeIndex
9
10 from _helper_cheesecake import create_empty_files_in_directory
11
12
13 class MockupCheesecakeTest(object):
14     project_name = 'test_project'
15
16     class CheesecakeMockup(Cheesecake):
17         def run_step(self, step_name):
18             if step_name == 'install_pkg':
19                 return
20             Cheesecake.run_step(self, step_name)
21
22         def __init__(self, sandbox, package_name, logfile):
23             self.name = package_name
24             self.package_name = package_name
25             self.package = package_name
26             self.sandbox = sandbox
27
28             self.verbose = False
29             self.quiet = True
30
31             self.unpack_dir = sandbox
32
33             self.configure_logging(logfile)
34             self.index = CheesecakeIndex()
35
36     def setUp(self):
37         self.temp_top_dir = tempfile.mkdtemp()
38         self.temp_project_dir = os.path.join(self.temp_top_dir, self.project_name)
39         os.mkdir(self.temp_project_dir)
40
41         self._mock_logfile = tempfile.mktemp()
42
43         self.cheesecake = self.CheesecakeMockup(self.temp_top_dir,
44                                                 self.project_name,
45                                                 self._mock_logfile)
46
47     def tearDown(self):
48         shutil.rmtree(self.temp_top_dir)
49         os.unlink(self._mock_logfile)
50
51     def create_files(self, files):
52         for f in files:
53             fd = file(os.path.join(self.temp_top_dir, f), "w")
54             fd.write('not_empty')
55             fd.close()
56
57     def create_empty_files(self, files):
58         create_empty_files_in_directory(files, self.temp_top_dir)
59
60     def prefix_with_package_name(self, files):
61         return map(lambda x: os.path.join(self.cheesecake.package_name, x), files)
Note: See TracBrowser for help on using the browser.