fw4spl
test_forbidtoken.py
1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*-
3 
4 import os
5 import unittest
6 
7 import common
8 import forbidtoken
9 
10 
11 class TestForbidtoken(unittest.TestCase):
12  def test_crlf_with_lf_file(self):
13  # Be verbose by default
14  common.g_trace = True
15 
16  # Load the test file
17  dir_path = os.path.dirname(os.path.realpath(__file__))
18  file = common.file_on_disk(dir_path + '/data/forbidtoken_lf.cpp')
19 
20  # Apply the hook
21  result = forbidtoken.forbidtoken(file, 'crlf')
22 
23  # Check result
24  self.assertFalse(result, "crlf were detected in test file.")
25 
26  def test_crlf_with_crlf_file(self):
27  # Be verbose by default
28  common.g_trace = True
29 
30  # Load the test file
31  dir_path = os.path.dirname(os.path.realpath(__file__))
32  file = common.file_on_disk(dir_path + '/data/forbidtoken_crlf.cpp')
33 
34  # Apply the hook
35  result = forbidtoken.forbidtoken(file, 'crlf')
36 
37  # Check result
38  self.assertTrue(result, "crlf were not detected in test file.")
39 
40  def test_cr_with_lf_file(self):
41  # Be verbose by default
42  common.g_trace = True
43 
44  # Load the test file
45  dir_path = os.path.dirname(os.path.realpath(__file__))
46  file = common.file_on_disk(dir_path + '/data/forbidtoken_lf.cpp')
47 
48  # Apply the hook
49  result = forbidtoken.forbidtoken(file, 'cr')
50 
51  # Check result
52  self.assertFalse(result, "cr were detected in test file.")
53 
54  def test_cr_with_cr_file(self):
55  # Be verbose by default
56  common.g_trace = True
57 
58  # Load the test file
59  dir_path = os.path.dirname(os.path.realpath(__file__))
60  file = common.file_on_disk(dir_path + '/data/forbidtoken_cr.cpp')
61 
62  # Apply the hook
63  result = forbidtoken.forbidtoken(file, 'cr')
64 
65  # Check result
66  self.assertTrue(result, "cr were not detected in test file.")
67 
68  def test_tab_with_lf_file(self):
69  # Be verbose by default
70  common.g_trace = True
71 
72  # Load the test file
73  dir_path = os.path.dirname(os.path.realpath(__file__))
74  file = common.file_on_disk(dir_path + '/data/forbidtoken_lf.cpp')
75 
76  # Apply the hook
77  result = forbidtoken.forbidtoken(file, 'tab')
78 
79  # Check result
80  self.assertFalse(result, "tab were detected in test file.")
81 
82  def test_tab_with_tab_file(self):
83  # Be verbose by default
84  common.g_trace = True
85 
86  # Load the test file
87  dir_path = os.path.dirname(os.path.realpath(__file__))
88  file = common.file_on_disk(dir_path + '/data/forbidtoken_tab.cpp')
89 
90  # Apply the hook
91  result = forbidtoken.forbidtoken(file, 'tab')
92 
93  # Check result
94  self.assertTrue(result, "tab were not detected in test file.")
95 
96  def test_lgpl_with_lf_file(self):
97  # Be verbose by default
98  common.g_trace = True
99 
100  # Load the test file
101  dir_path = os.path.dirname(os.path.realpath(__file__))
102  file = common.file_on_disk(dir_path + '/data/forbidtoken_lf.cpp')
103 
104  # Apply the hook
105  result = forbidtoken.forbidtoken(file, 'lgpl')
106 
107  # Check result
108  self.assertFalse(result, "lgpl were detected in test file.")
109 
110  def test_lgpl_with_lgpl_file(self):
111  # Be verbose by default
112  common.g_trace = True
113 
114  # Load the test file
115  dir_path = os.path.dirname(os.path.realpath(__file__))
116  file = common.file_on_disk(dir_path + '/data/forbidtoken_lgpl.cpp')
117 
118  # Apply the hook
119  result = forbidtoken.forbidtoken(file, 'lgpl')
120 
121  # Check result
122  self.assertTrue(result, "lgpl were not detected in test file.")
123 
124  def test_oslmlog_with_lf_file(self):
125  # Be verbose by default
126  common.g_trace = True
127 
128  # Load the test file
129  dir_path = os.path.dirname(os.path.realpath(__file__))
130  file = common.file_on_disk(dir_path + '/data/forbidtoken_lf.cpp')
131 
132  # Apply the hook
133  result = forbidtoken.forbidtoken(file, 'oslmlog')
134 
135  # Check result
136  self.assertFalse(result, "oslmlog were detected in test file.")
137 
138  def test_oslmlog_with_oslmlog_file(self):
139  # Be verbose by default
140  common.g_trace = True
141 
142  # Load the test file
143  dir_path = os.path.dirname(os.path.realpath(__file__))
144  file = common.file_on_disk(dir_path + '/data/forbidtoken_oslm.cpp')
145 
146  # Apply the hook
147  result = forbidtoken.forbidtoken(file, 'oslmlog')
148 
149  # Check result
150  self.assertTrue(result, "oslmlog were not detected in test file.")
151 
152  def test_digraph_with_lf_file(self):
153  # Be verbose by default
154  common.g_trace = True
155 
156  # Load the test file
157  dir_path = os.path.dirname(os.path.realpath(__file__))
158  file = common.file_on_disk(dir_path + '/data/forbidtoken_lf.cpp')
159 
160  # Apply the hook
161  result = forbidtoken.forbidtoken(file, 'digraphs')
162 
163  # Check result
164  self.assertFalse(result, "digraphs were detected in test file.")
165 
166  def test_digraphs_with_digraphs_file(self):
167  # Be verbose by default
168  common.g_trace = True
169 
170  # Load the test file
171  dir_path = os.path.dirname(os.path.realpath(__file__))
172  file = common.file_on_disk(dir_path + '/data/forbidtoken_digraphs.cpp')
173 
174  # Apply the hook
175  result = forbidtoken.forbidtoken(file, 'digraphs')
176 
177  # Check result
178  self.assertTrue(result, "digraphs were not detected in test file.")
179 
180  def test_digraphs_with_nodigraphs_file(self):
181  # Be verbose by default
182  common.g_trace = True
183 
184  # Load the test file
185  dir_path = os.path.dirname(os.path.realpath(__file__))
186  file = common.file_on_disk(dir_path + '/data/forbidtoken_nodigraphs.cpp')
187 
188  # Apply the hook
189  result = forbidtoken.forbidtoken(file, 'digraphs')
190 
191  # Check result
192  self.assertFalse(result, "digraphs were detected in test file.")
193 
194  def test_doxygen_with_lf_file(self):
195  # Be verbose by default
196  common.g_trace = True
197 
198  # Load the test file
199  dir_path = os.path.dirname(os.path.realpath(__file__))
200  file = common.file_on_disk(dir_path + '/data/forbidtoken_lf.cpp')
201 
202  # Apply the hook
203  result = forbidtoken.forbidtoken(file, 'doxygen')
204 
205  # Check result
206  self.assertFalse(result, "doxygen were detected in test file.")
207 
208  def test_doxygen_with_doxygen_file(self):
209  # Be verbose by default
210  common.g_trace = True
211 
212  # Load the test file
213  dir_path = os.path.dirname(os.path.realpath(__file__))
214  file = common.file_on_disk(dir_path + '/data/forbidtoken_doxygen.cpp')
215 
216  # Apply the hook
217  result = forbidtoken.forbidtoken(file, 'doxygen')
218 
219  # Check result
220  self.assertTrue(result, "doxygen were not detected in test file.")
221 
222  def test_copain_with_lf_file(self):
223  # Be verbose by default
224  common.g_trace = True
225 
226  # Load the test file
227  dir_path = os.path.dirname(os.path.realpath(__file__))
228  file = common.file_on_disk(dir_path + '/data/forbidtoken_lf.cpp')
229 
230  # Apply the hook
231  result = forbidtoken.forbidtoken(file, 'copain')
232 
233  # Check result
234  self.assertFalse(result, "copain were detected in test file.")
235 
236  def test_copain_with_copain_file(self):
237  # Be verbose by default
238  common.g_trace = True
239 
240  # Load the test file
241  dir_path = os.path.dirname(os.path.realpath(__file__))
242  file = common.file_on_disk(dir_path + '/data/forbidtoken_copain.cpp')
243 
244  # Apply the hook
245  result = forbidtoken.forbidtoken(file, 'copain')
246 
247  # Check result
248  self.assertTrue(result, "copain were not detected in test file.")
249 
250 
251 if __name__ == '__main__':
252  unittest.main()
def file_on_disk(path)
Definition: common.py:314
def forbidtoken(files, config_name)
Definition: forbidtoken.py:57