1#!/usr/bin/python
2
3import unittest
4from kernelexpand import decompose_kernel
5from kernelexpand import mirror_kernel_components
6
7km = 'http://www.kernel.org/pub/linux/kernel/'
8akpm = km + 'people/akpm/patches/'
9
10kml = 'http://www.example.com/mirror/kernel.org/'
11akpml = 'http://www.example.com/mirror/akpm/'
12
13mirrorA = [
14        [ akpm, akpml ],
15        [ km, kml ],
16]
17
18class kernelexpandTest(unittest.TestCase):
19    def test_decompose_simple(self):
20        correct = [ [ km + 'v2.6/linux-2.6.23.tar.bz2' ] ]
21        sample = decompose_kernel('2.6.23')
22        self.assertEqual(sample, correct)
23
24
25    def test_decompose_fail(self):
26        success = False
27        try:
28            sample = decompose_kernel('1.0.0.0.0')
29            success = True
30        except NameError:
31            pass
32        except Exception, e:
33            self.fail('expected NameError, got something else')
34
35        if success:
36            self.fail('expected NameError, was successful')
37
38
39    def test_decompose_rcN(self):
40        correct = [
41          [ km + 'v2.6/testing/v2.6.23/linux-2.6.23-rc1.tar.bz2',
42            km + 'v2.6/testing/linux-2.6.23-rc1.tar.bz2']
43        ]
44        sample = decompose_kernel('2.6.23-rc1')
45        self.assertEqual(sample, correct)
46
47
48    def test_decompose_mmN(self):
49        correct = [
50          [ km + 'v2.6/linux-2.6.23.tar.bz2' ],
51          [ akpm + '2.6/2.6.23/2.6.23-mm1/2.6.23-mm1.bz2' ]
52        ]
53        sample = decompose_kernel('2.6.23-mm1')
54        self.assertEqual(sample, correct)
55
56
57    def test_decompose_gitN(self):
58        correct = [
59          [ km + 'v2.6/linux-2.6.23.tar.bz2' ],
60          [ km + 'v2.6/snapshots/old/patch-2.6.23-git1.bz2',
61            km + 'v2.6/snapshots/patch-2.6.23-git1.bz2']
62        ]
63        sample = decompose_kernel('2.6.23-git1')
64        self.assertEqual(sample, correct)
65
66
67    def test_decompose_rcN_mmN(self):
68        correct = [
69          [ km + 'v2.6/testing/v2.6.23/linux-2.6.23-rc1.tar.bz2',
70            km + 'v2.6/testing/linux-2.6.23-rc1.tar.bz2' ],
71          [ akpm + '2.6/2.6.23-rc1/2.6.23-rc1-mm1/2.6.23-rc1-mm1.bz2']
72        ]
73        sample = decompose_kernel('2.6.23-rc1-mm1')
74        self.assertEqual(sample, correct)
75
76
77    def test_mirrorA_simple(self):
78        correct = [
79          [ kml + 'v2.6/linux-2.6.23.tar.bz2',
80            km + 'v2.6/linux-2.6.23.tar.bz2' ]
81        ]
82        sample = decompose_kernel('2.6.23')
83        sample = mirror_kernel_components(mirrorA, sample)
84
85        self.assertEqual(sample, correct)
86
87
88    def test_mirrorA_rcN(self):
89        correct = [
90          [ kml + 'v2.6/testing/v2.6.23/linux-2.6.23-rc1.tar.bz2',
91            kml + 'v2.6/testing/linux-2.6.23-rc1.tar.bz2',
92            km + 'v2.6/testing/v2.6.23/linux-2.6.23-rc1.tar.bz2',
93            km + 'v2.6/testing/linux-2.6.23-rc1.tar.bz2' ]
94        ]
95        sample = decompose_kernel('2.6.23-rc1')
96        sample = mirror_kernel_components(mirrorA, sample)
97        self.assertEqual(sample, correct)
98
99
100    def test_mirrorA_mmN(self):
101        correct = [
102          [ kml + 'v2.6/linux-2.6.23.tar.bz2',
103            km + 'v2.6/linux-2.6.23.tar.bz2'],
104          [ akpml + '2.6/2.6.23/2.6.23-mm1/2.6.23-mm1.bz2',
105            kml + 'people/akpm/patches/2.6/2.6.23/2.6.23-mm1/2.6.23-mm1.bz2',
106            akpm + '2.6/2.6.23/2.6.23-mm1/2.6.23-mm1.bz2' ]
107        ]
108
109        sample = decompose_kernel('2.6.23-mm1')
110        sample = mirror_kernel_components(mirrorA, sample)
111        self.assertEqual(sample, correct)
112
113
114    def test_mirrorA_gitN(self):
115        correct = [
116          [ kml + 'v2.6/linux-2.6.23.tar.bz2',
117            km + 'v2.6/linux-2.6.23.tar.bz2'],
118          [ kml + 'v2.6/snapshots/old/patch-2.6.23-git1.bz2',
119            kml + 'v2.6/snapshots/patch-2.6.23-git1.bz2',
120            km + 'v2.6/snapshots/old/patch-2.6.23-git1.bz2',
121            km + 'v2.6/snapshots/patch-2.6.23-git1.bz2' ]
122        ]
123        sample = decompose_kernel('2.6.23-git1')
124        sample = mirror_kernel_components(mirrorA, sample)
125        self.assertEqual(sample, correct)
126
127
128    def test_mirrorA_rcN_mmN(self):
129        correct = [
130          [ kml + 'v2.6/testing/v2.6.23/linux-2.6.23-rc1.tar.bz2',
131            kml + 'v2.6/testing/linux-2.6.23-rc1.tar.bz2',
132            km + 'v2.6/testing/v2.6.23/linux-2.6.23-rc1.tar.bz2',
133            km + 'v2.6/testing/linux-2.6.23-rc1.tar.bz2'],
134          [ akpml + '2.6/2.6.23-rc1/2.6.23-rc1-mm1/2.6.23-rc1-mm1.bz2',
135            kml + 'people/akpm/patches/2.6/2.6.23-rc1/2.6.23-rc1-mm1/2.6.23-rc1-mm1.bz2',
136            akpm + '2.6/2.6.23-rc1/2.6.23-rc1-mm1/2.6.23-rc1-mm1.bz2' ]
137        ]
138        sample = decompose_kernel('2.6.23-rc1-mm1')
139        sample = mirror_kernel_components(mirrorA, sample)
140        self.assertEqual(sample, correct)
141
142
143if __name__ == '__main__':
144    unittest.main()
145