3
|
1 |
#
|
|
2 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
#
|
|
16 |
|
|
17 |
import unittest
|
|
18 |
|
|
19 |
from cone.public import api
|
|
20 |
from cone.validation.problem_type_filter import ProblemTypeFilter
|
|
21 |
|
|
22 |
class TestProblemTypeFilter(unittest.TestCase):
|
|
23 |
def test_empty_matches_everything(self):
|
|
24 |
filter = ProblemTypeFilter([], [])
|
|
25 |
self.assertTrue(filter.match(''))
|
|
26 |
self.assertTrue(filter.match('foo'))
|
|
27 |
self.assertTrue(filter.match('foo.bar'))
|
|
28 |
self.assertTrue(filter.match('foo.bar.baz'))
|
|
29 |
|
|
30 |
def test_single_include(self):
|
|
31 |
filter = ProblemTypeFilter(['foo.bar'], [])
|
|
32 |
self.assertFalse(filter.match(''))
|
|
33 |
self.assertFalse(filter.match('foo'))
|
|
34 |
self.assertTrue(filter.match('foo.bar'))
|
|
35 |
self.assertTrue(filter.match('foo.bar.baz'))
|
|
36 |
self.assertFalse(filter.match('bar'))
|
|
37 |
|
|
38 |
def test_single_exclude(self):
|
|
39 |
filter = ProblemTypeFilter([], ['foo.bar'])
|
|
40 |
self.assertTrue(filter.match(''))
|
|
41 |
self.assertTrue(filter.match('foo'))
|
|
42 |
self.assertTrue(filter.match('bar'))
|
|
43 |
self.assertFalse(filter.match('foo.bar'))
|
|
44 |
self.assertFalse(filter.match('foo.bar.baz'))
|
|
45 |
|
|
46 |
def test_include_and_exclude(self):
|
|
47 |
filter = ProblemTypeFilter(['foo'], ['foo.bar.baz'])
|
|
48 |
self.assertFalse(filter.match(''))
|
|
49 |
self.assertTrue(filter.match('foo'))
|
|
50 |
self.assertFalse(filter.match('bar'))
|
|
51 |
self.assertTrue(filter.match('foo.bar'))
|
|
52 |
self.assertFalse(filter.match('foo.bar.baz'))
|
|
53 |
self.assertFalse(filter.match('foo.bar.baz.x'))
|
|
54 |
|
|
55 |
def test_multiple_includes_and_excludes(self):
|
|
56 |
filter = ProblemTypeFilter(['foo', 'boo'], ['foo.bar.baz', 'boo.bar.baz'])
|
|
57 |
|
|
58 |
self.assertFalse(filter.match(''))
|
|
59 |
self.assertFalse(filter.match('bar'))
|
|
60 |
|
|
61 |
self.assertTrue(filter.match('foo'))
|
|
62 |
self.assertTrue(filter.match('foo.bar'))
|
|
63 |
self.assertFalse(filter.match('foo.bar.baz'))
|
|
64 |
self.assertFalse(filter.match('foo.bar.baz.x'))
|
|
65 |
|
|
66 |
self.assertTrue(filter.match('boo'))
|
|
67 |
self.assertTrue(filter.match('boo.bar'))
|
|
68 |
self.assertFalse(filter.match('boo.bar.baz'))
|
|
69 |
self.assertFalse(filter.match('boo.bar.baz.x'))
|
|
70 |
|
|
71 |
def test_wildcard_in_include(self):
|
|
72 |
filter = ProblemTypeFilter(['*.bar'], [])
|
|
73 |
|
|
74 |
self.assertFalse(filter.match('foo'))
|
|
75 |
self.assertFalse(filter.match('boo'))
|
|
76 |
self.assertFalse(filter.match('foo.baz.bar'))
|
|
77 |
|
|
78 |
self.assertTrue(filter.match('foo.bar'))
|
|
79 |
self.assertTrue(filter.match('foo.bar.baz'))
|
|
80 |
self.assertTrue(filter.match('boo.bar'))
|
|
81 |
self.assertTrue(filter.match('boo.bar.baz'))
|
|
82 |
|
|
83 |
|
|
84 |
filter = ProblemTypeFilter(['*.*.baz'], [])
|
|
85 |
self.assertTrue(filter.match('foo.bar.baz'))
|
|
86 |
self.assertTrue(filter.match('boo.bar.baz'))
|
|
87 |
|
|
88 |
self.assertFalse(filter.match('baz'))
|
|
89 |
self.assertFalse(filter.match('foo.baz'))
|
|
90 |
|
|
91 |
def test_wildcard_in_exclude(self):
|
|
92 |
filter = ProblemTypeFilter([], ['*.bar'])
|
|
93 |
|
|
94 |
self.assertTrue(filter.match('foo'))
|
|
95 |
self.assertTrue(filter.match('boo'))
|
|
96 |
self.assertTrue(filter.match('foo.baz.bar'))
|
|
97 |
|
|
98 |
self.assertFalse(filter.match('foo.bar'))
|
|
99 |
self.assertFalse(filter.match('foo.bar.baz'))
|
|
100 |
self.assertFalse(filter.match('boo.bar'))
|
|
101 |
self.assertFalse(filter.match('boo.bar.baz'))
|
|
102 |
|
|
103 |
|
|
104 |
filter = ProblemTypeFilter([], ['*.*.baz'])
|
|
105 |
self.assertFalse(filter.match('foo.bar.baz'))
|
|
106 |
self.assertFalse(filter.match('boo.bar.baz'))
|
|
107 |
|
|
108 |
self.assertTrue(filter.match('baz'))
|
|
109 |
self.assertTrue(filter.match('foo.baz'))
|
|
110 |
|
|
111 |
def test_filter_problems(self):
|
|
112 |
filter = ProblemTypeFilter(['foo'], ['foo.bar.baz'])
|
|
113 |
problems = [api.Problem('', type=''),
|
|
114 |
api.Problem('', type='foo'),
|
|
115 |
api.Problem('', type='bar'),
|
|
116 |
api.Problem('', type='foo.bar'),
|
|
117 |
api.Problem('', type='foo.bar.baz'),
|
|
118 |
api.Problem('', type='foo.bar.baz.x')]
|
|
119 |
|
|
120 |
filtered_problems = filter.filter(problems)
|
|
121 |
self.assertEquals(filtered_problems,
|
|
122 |
[api.Problem('', type='foo'),
|
|
123 |
api.Problem('', type='foo.bar')])
|
|
124 |
|
|
125 |
def test_filter_strings(self):
|
|
126 |
filter = ProblemTypeFilter(['foo'], ['foo.bar.baz'])
|
|
127 |
problems = ['',
|
|
128 |
'foo',
|
|
129 |
'bar',
|
|
130 |
'foo.bar',
|
|
131 |
'foo.bar.baz',
|
|
132 |
'foo.bar.baz.x']
|
|
133 |
|
|
134 |
filtered_problems = filter.filter(problems, key=lambda item: item)
|
|
135 |
self.assertEquals(filtered_problems, ['foo', 'foo.bar'])
|