Update to genscripts rev 382. This has more fixes for py3k and the modular rewrite...
[gentoolkit.git] / pym / gentoolkit / test / test_helpers.py
1 import unittest
2 import warnings
3 from tempfile import NamedTemporaryFile, mktemp
4 try:
5         from test import test_support
6 except ImportError:
7         from test import support as test_support
8
9 from portage import os
10
11 from gentoolkit import helpers
12
13
14 class TestChangeLog(unittest.TestCase):
15
16         def setUp(self):
17                 pass
18
19         def tearDown(self):
20                 pass
21
22         def test_split_changelog(self):
23                 changelog = """
24 *portage-2.1.6.2 (20 Dec 2008)
25
26   20 Dec 2008; Zac Medico <zmedico@gentoo.org> +portage-2.1.6.2.ebuild:
27   2.1.6.2 bump. This fixes bug #251591 (repoman inherit.autotools false
28   positives) and bug #251616 (performance issue in build log search regex
29   makes emerge appear to hang). Bug #216231 tracks all bugs fixed since
30   2.1.4.x.
31
32   20 Dec 2008; Zac Medico <zmedico@gentoo.org> -portage-2.1.6.ebuild,
33   -portage-2.1.6.1.ebuild, -portage-2.2_rc17.ebuild:
34   Remove old versions.
35
36
37 *portage-2.1.6.1 (12 Dec 2008)
38
39   12 Dec 2008; Zac Medico <zmedico@gentoo.org> +portage-2.1.6.1.ebuild:
40   2.1.6.1 bump. This fixes bug #250148 (emerge hangs with selinux if ebuild
41   spawns a daemon), bug #250166 (trigger download when generating manifest
42   if file size differs from existing entry), and bug #250212 (new repoman
43   upstream.workaround category for emake -j1 warnings). Bug #216231 tracks
44   all bugs fixed since 2.1.4.x.
45
46
47 *portage-2.1.6 (07 Dec 2008)
48
49   07 Dec 2008; Zac Medico <zmedico@gentoo.org> +portage-2.1.6.ebuild:
50   2.1.6 final release. This fixes bug #249586. Bug #216231 tracks all bugs
51   fixed since 2.1.4.x.
52
53   07 Dec 2008; Zac Medico <zmedico@gentoo.org> -portage-2.1.6_rc1.ebuild,
54   -portage-2.1.6_rc2.ebuild, -portage-2.1.6_rc3.ebuild,
55   -portage-2.2_rc16.ebuild:
56   Remove old versions.
57                 """
58
59 class TestFileOwner(unittest.TestCase):
60
61         def setUp(self):
62                 pass
63
64         def tearDown(self):
65                 pass
66
67         def test_expand_abspaths(self):
68                 expand_abspaths = helpers.FileOwner.expand_abspaths
69                 
70                 initial_file_list = ['foo0', '/foo1', '~/foo2', './foo3']
71                 # This function should only effect foo3, and not ordering:
72                 
73                 final_file_list = [
74                         'foo0',
75                         '/foo1',
76                         '~/foo2',
77                         os.path.join(os.getcwd(), os.path.normpath(initial_file_list[3]))
78                 ]
79
80                 self.failUnlessEqual(expand_abspaths(initial_file_list), final_file_list)
81
82         def test_extend_realpaths(self):
83                 extend_realpaths = helpers.FileOwner.extend_realpaths
84
85                 # Test that symlinks's realpaths are extended
86                 f1 = NamedTemporaryFile(prefix='equeryunittest')
87                 f2 = NamedTemporaryFile(prefix='equeryunittest')
88                 f3 = NamedTemporaryFile(prefix='equeryunittest')
89                 with warnings.catch_warnings():
90                         warnings.simplefilter("ignore")
91                         sym1 = mktemp()
92                         os.symlink(f1.name, sym1)
93                         sym2 = mktemp()
94                         os.symlink(f3.name, sym2)
95                 # We've created 3 files and 2 symlinks for testing. We're going to pass
96                 # in only the first two files and both symlinks. sym1 points to f1.
97                 # Since f1 is already in the list, sym1's realpath should not be added.
98                 # sym2 points to f3, but f3's not in our list, so sym2's realpath
99                 # should be added to the list.
100                 p = [f1.name, f2.name, sym1, sym2]
101                 p_xr = extend_realpaths(p)
102
103                 self.failUnlessEqual(p_xr[0], f1.name)
104                 self.failUnlessEqual(p_xr[1], f2.name)
105                 self.failUnlessEqual(p_xr[2], sym1)
106                 self.failUnlessEqual(p_xr[3], sym2)
107                 self.failUnlessEqual(p_xr[4], f3.name)
108
109                 # Clean up
110                 os.unlink(sym1)
111                 os.unlink(sym2)
112
113                 # Make sure we raise an exception if we don't get acceptable input
114                 self.failUnlessRaises(AttributeError, extend_realpaths, 'str')
115                 self.failUnlessRaises(AttributeError, extend_realpaths, set())
116
117
118 def test_main():
119         test_support.run_unittest(TestGentoolkitHelpers2)
120
121
122 if __name__ == '__main__':
123         test_main()