forked from openshift/openshift-client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_selector.py
More file actions
53 lines (38 loc) · 2.23 KB
/
test_selector.py
File metadata and controls
53 lines (38 loc) · 2.23 KB
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
from __future__ import absolute_import
import unittest
from .selector import selector
from .naming import qname_matches
class TestSelector(unittest.TestCase):
def test_qname_matches(self):
self.assertTrue(qname_matches('template/x', 'template/x'))
self.assertTrue(qname_matches('template/x', ['template/x']))
self.assertTrue(qname_matches('template/x', ['template/y', 'template/x']))
self.assertFalse(qname_matches('template/x', ['template/y', 'template/x2']))
# See whether fuzzy matching of kinds is working
self.assertTrue(qname_matches('template/django', ['template.template.openshift.io/django']))
self.assertFalse(qname_matches('template/django', ['template.template.openshift.io/django.2']))
self.assertTrue(qname_matches('template/django', ['template.template/django']))
self.assertFalse(qname_matches('template/django', ['template.template/django.2']))
self.assertFalse(qname_matches('template2/django', ['template.template.openshift.io/django']))
self.assertFalse(qname_matches('template/django2', ['template.template.openshift.io/django']))
def test_set_operations(self):
s1 = selector([])
s2 = selector(['pod/abc', 'pod/xyz'])
self.assertEqual(s1.subtract(s2).qnames(), [])
self.assertEqual(s1.union(s2).qnames(), ['pod/abc', 'pod/xyz'])
s3 = selector(['pod/abc2', 'pod/xyz'])
self.assertEqual(s2.subtract(s3).qnames(), ['pod/abc'])
self.assertEqual(s2.intersect(s3).qnames(), ['pod/xyz'])
# See whether fuzzy matching of kinds is working
t1 = selector(['template/django'])
t2 = selector(['template.template.openshift.io/django', 'template.template.openshift.io/django2'])
self.assertEqual(len(t1.union(t2).qnames()), 2)
self.assertEqual(len(t1.intersect(t2).qnames()), 1)
self.assertEqual(len(t1.subtract(t2).qnames()), 0)
t1 = selector(['template/django'])
t2 = selector(['template.template.openshift.io/django'])
self.assertEqual(len(t1.union(t2).qnames()), 1)
self.assertEqual(len(t1.intersect(t2).qnames()), 1)
self.assertEqual(len(t1.subtract(t2).qnames()), 0)
if __name__ == '__main__':
unittest.main()