/
test-regexps.py
executable file
·120 lines (104 loc) · 4.89 KB
/
test-regexps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/python3
##
## Copyright (C) 2008-2010 Nokia. All rights reserved.
##
## Contact: Marius Vollmer <marius.vollmer@nokia.com>
##
## This library is free software; you can redistribute it and/or
## modify it under the terms of the GNU Lesser General Public License
## version 2.1 as published by the Free Software Foundation.
##
## This library is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public
## License along with this library; if not, write to the Free Software
## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
## 02110-1301 USA
import sys
import os
# Otherwise env.py won't be found when running tests inside a VPATH build dir
sys.path.insert(0, os.getcwd())
try: import env
except: pass
import unittest
from subprocess import getstatusoutput
from cltool import CLTool
from tempfile import mkdtemp
class Regexps(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def testStringMimes1(self):
# only the general
(status, output) = getstatusoutput("lca-tool --string --printmimes foo")
self.assertTrue(status == 0)
self.assertTrue(output.find("general-1") != -1)
self.assertTrue(output.find("special-1a") == -1)
self.assertTrue(output.find("special-1b") == -1)
# general and one special case
(status, output) = getstatusoutput("lca-tool --string --printmimes foobar")
self.assertTrue(status == 0)
self.assertTrue(output.find("special-1a") != -1)
self.assertTrue(output.find("general-1") != -1)
self.assertTrue(output.find("special-1b") == -1)
# verify the order
self.assertTrue(output.find("special-1a") < output.find("general-1"))
# general and another special case
(status, output) = getstatusoutput("lca-tool --string --printmimes foobazxx")
self.assertTrue(status == 0)
self.assertTrue(output.find("special-1b") != -1)
self.assertTrue(output.find("general-1") != -1)
self.assertTrue(output.find("special-1a") == -1)
# verify the order
self.assertTrue(output.find("special-1b") < output.find("general-1"))
def testStringMimes2(self):
# only the general
(status, output) = getstatusoutput("lca-tool --string --printmimes cat")
self.assertTrue(status == 0)
self.assertTrue(output.find("general-2") != -1)
self.assertTrue(output.find("special-2") == -1)
self.assertTrue(output.find("superspecial-2") == -1)
# general and one special case
(status, output) = getstatusoutput("lca-tool --string --printmimes catdog")
self.assertTrue(status == 0)
self.assertTrue(output.find("general-2") != -1)
self.assertTrue(output.find("special-2") != -1)
self.assertTrue(output.find("superspecial-2") == -1)
# verify the order
self.assertTrue(output.find("special-2") < output.find("general-2"))
# general and both special cases
(status, output) = getstatusoutput("lca-tool --string --printmimes catdogzebra")
self.assertTrue(status == 0)
self.assertTrue(output.find("general-2") != -1)
self.assertTrue(output.find("special-2") != -1)
self.assertTrue(output.find("superspecial-2") != -1)
# verify the order
self.assertTrue(output.find("special-2") < output.find("general-2"))
self.assertTrue(output.find("superspecial-2") < output.find("special-2"))
def testActionsForString(self):
(status, output) = getstatusoutput("lca-tool --string --print www.foo.com")
self.assertTrue(status == 0)
self.assertTrue(output.find("browser") != -1)
self.assertTrue(output.find("special-browser") == -1)
(status, output) = getstatusoutput("lca-tool --string --print http://example.com")
self.assertTrue(status == 0)
self.assertTrue(output.find("special-browser") != -1)
self.assertTrue(output.find("browser") != -1)
self.assertTrue(output.find("special-browser") < output.find("browser"))
def testDefaultActionForString(self):
(status, output) = getstatusoutput("lca-tool --string --printdefault www.foo.com")
self.assertTrue(status == 0)
self.assertTrue(output.find("browser") != -1)
(status, output) = getstatusoutput("lca-tool --string --printdefault http://example.com")
self.assertTrue(status == 0)
self.assertTrue(output.find("special-browser") != -1)
def runTests():
suite = unittest.TestLoader().loadTestsFromTestCase(Regexps)
result = unittest.TextTestRunner(verbosity=2).run(suite)
return len(result.errors + result.failures)
if __name__ == "__main__":
sys.exit(runTests())