Merge genscripts rev 406
[gentoolkit.git] / pym / gentoolkit / test / eclean / test_clean.py
1 #!/usr/bin/python
2 #
3 # Copyright 2010 Brian Dolbec <brian.dolbec@gmail.com>
4 # Copyright 2010 Gentoo Foundation
5 # Distributed under the terms of the GNU General Public License v2
6 #
7 # $Header$
8
9 from __future__ import print_function
10
11 __version__= "0.0.1"
12 __author__ = "Brian Dolbec"
13 __email__ = "brian.dolbec@gmail.com"
14
15 from getopt import gnu_getopt, GetoptError
16
17 import unittest
18 import os
19 import sys
20
21 import gentoolkit.pprinter as pp
22 try:
23         from test import test_support
24 except ImportError:
25         from test import support as test_support
26
27 from gentoolkit.eclean.clean import CleanUp
28
29
30 class Controllers(object):
31         """Contains controller methods for use in testing
32         the clean module methods"""
33         
34         def __init__(self):
35                 self.gathered_data = []
36                 self.authorize = True
37                 self.authorize_list = []
38                 self.authorize_index = 0
39
40         def authorize_all_controller(self, size, key, clean_list):
41                 """data gatherering controller.
42                 
43                 @rtype: Boolean
44                 @returns: self.authorize which controls the cleaning method
45                 """
46                 self.gathered_data.append([size, key, clean_list])
47                 return self.authorize
48
49         def authorize_list_controller(self, size, key, clean_list):
50                 """data gathering and controller which
51                 authorizes acoring to a pre-determined list
52                 
53                 @rtype: Boolean
54                 @return self.authorize_list[self.authorize_index]"""
55                 self.gathered_data.append([size, key, clean_list])
56                 index = self.authorize_index
57                 self.authorize_index =+ 1
58                 return self.authorize_list[index]
59                 
60
61 #class TestCleanUp(unittest.TestCase):
62 #       """Test module for the various CleanUp class methods
63 #       
64 #       @param options: dict of module options
65 #       @param testdata: dict. of path and test parameters
66 #                       as created by the TestDirCreation class"""
67 #
68 #       def __init__(self, options, testdata):
69 #               self.options = options
70 #               self.tesdata = testdata
71 #               
72 #
73 #       def test_symlink_clean():
74 #               """Tests the symbolic link portion of the distfiles
75 #               cleaning"""
76 #               pass
77 #
78 #
79 #       def test_dist_clean():
80 #               """Test the distfiles cleaning"""
81 #               pass
82 #
83 #
84 #       def test_pkg_clean():
85 #               """Test the packages cleaning"""
86 #               pass
87 #
88 #
89 #       def test_pretend_clean():
90 #               """Test the pretend_clean output"""
91 #               controlller = Controllers().authorize_all_controller
92 #               clean = CleanUp(controller)
93 #               clean.pretend_clean(self.dist_clean)
94 #               data = controller.gathered_data
95                 
96
97
98 def useage():
99         """output run options"""
100         print("Useage: test_clean [OPTONS] path=test-dir")
101         print(" where test-dir is the location to create and populate")
102         print("the testing distfiles and packages directories.")
103         print("All tests in this module test only the clean.py module functions")
104         print()
105         print("OPTIONS:")
106         print(" -a, --all         run all tests")
107         print(" -c, --clean       clean up any previous test dirs & files")
108         print(" -D, --distfiles   run the distfiles cleaning test")
109         print(" -k, --keep-dirs   keep the test directories and files after the test")
110         print(" -p, --pretend     run the test in pretend mode only")
111         print(" -P, --packages    run the packages cleaning test")
112         print(" -S, --symlinks    run the symlinks test")
113         print(" --path            the location to create the temporary distfiles")
114         print("                   and packages directories that will be test cleaned")
115         print(" --version         test module version")
116         print()
117
118
119 def parse_opts():
120         """Parse the options dict
121         
122         @return options: dictionary of module options"""
123         try:
124                 opts, args = getopt(sys.argv[1:], 'acDkpPS', ["version",
125                         "help", "path=", "all", "distfiles", "packages",
126                         "pretend", "symlinks", "keep-dirs", "clean"])
127                 #print opts
128                 #print args
129         except GetoptError as e:
130                 print(e.msg, file=sys.stderr)
131                 usage()
132                 sys.exit(1)
133
134
135
136 def main(cmdline=False):
137         """parse options and run the tests"""
138         
139         if cmdline:
140                 options = parse_opts()
141         
142
143 if __name__ == "__main__":
144         """actually call main() if launched as a script"""
145         try:
146                 main(True)
147         except KeyboardInterrupt:
148                 print("Aborted.")
149                 sys.exit(130)
150         sys.exit(0)
151
152