Package portage :: Package tests :: Package repoman :: Module test_echangelog
[hide private]

Source Code for Module portage.tests.repoman.test_echangelog

  1  # Copyright 2012 Gentoo Foundation 
  2  # Distributed under the terms of the GNU General Public License v2 
  3   
  4  import tempfile 
  5  import time 
  6   
  7  from portage import os 
  8  from portage import shutil 
  9  from portage.tests import TestCase 
 10  from repoman.utilities import UpdateChangeLog 
 11   
12 -class RepomanEchangelogTestCase(TestCase):
13
14 - def setUp(self):
15 super(RepomanEchangelogTestCase, self).setUp() 16 17 self.tmpdir = tempfile.mkdtemp(prefix='repoman.echangelog.') 18 19 self.skel_changelog = os.path.join(self.tmpdir, 'skel.ChangeLog') 20 skel = [ 21 '# ChangeLog for <CATEGORY>/<PACKAGE_NAME>\n', 22 '# Copyright 1999-2000 Gentoo Foundation; Distributed under the GPL v2\n', 23 '# $Header: $\n' 24 ] 25 self._writelines(self.skel_changelog, skel) 26 27 self.cat = 'mycat' 28 self.pkg = 'mypkg' 29 self.pkgdir = os.path.join(self.tmpdir, self.cat, self.pkg) 30 os.makedirs(self.pkgdir) 31 32 self.header_pkg = '# ChangeLog for %s/%s\n' % (self.cat, self.pkg) 33 self.header_copyright = '# Copyright 1999-%s Gentoo Foundation; Distributed under the GPL v2\n' % \ 34 time.strftime('%Y', time.gmtime()) 35 self.header_cvs = '# $Header: $\n' 36 37 self.changelog = os.path.join(self.pkgdir, 'ChangeLog') 38 39 self.user = 'Testing User <portage@gentoo.org>'
40
41 - def tearDown(self):
42 super(RepomanEchangelogTestCase, self).tearDown() 43 shutil.rmtree(self.tmpdir)
44
45 - def _readlines(self, file):
46 with open(file, 'r') as f: 47 return f.readlines()
48
49 - def _writelines(self, file, data):
50 with open(file, 'w') as f: 51 f.writelines(data)
52
53 - def testRejectRootUser(self):
54 self.assertEqual(UpdateChangeLog(self.pkgdir, 'me <root@gentoo.org>', '', '', '', '', quiet=True), None)
55
56 - def testMissingSkelFile(self):
57 # Test missing ChangeLog, but with empty skel (i.e. do nothing). 58 UpdateChangeLog(self.pkgdir, self.user, 'test!', '/does/not/exist', self.cat, self.pkg, quiet=True) 59 actual_cl = self._readlines(self.changelog) 60 self.assertTrue(len(actual_cl[0]) > 0)
61
62 - def testEmptyChangeLog(self):
63 # Make sure we do the right thing with a 0-byte ChangeLog 64 open(self.changelog, 'w').close() 65 UpdateChangeLog(self.pkgdir, self.user, 'test!', self.skel_changelog, self.cat, self.pkg, quiet=True) 66 actual_cl = self._readlines(self.changelog) 67 self.assertEqual(actual_cl[0], self.header_pkg) 68 self.assertEqual(actual_cl[1], self.header_copyright) 69 self.assertEqual(actual_cl[2], self.header_cvs)
70
71 - def testCopyrightUpdate(self):
72 # Make sure updating the copyright line works 73 UpdateChangeLog(self.pkgdir, self.user, 'test!', self.skel_changelog, self.cat, self.pkg, quiet=True) 74 actual_cl = self._readlines(self.changelog) 75 self.assertEqual(actual_cl[1], self.header_copyright)
76
77 - def testSkelHeader(self):
78 # Test skel.ChangeLog -> ChangeLog 79 UpdateChangeLog(self.pkgdir, self.user, 'test!', self.skel_changelog, self.cat, self.pkg, quiet=True) 80 actual_cl = self._readlines(self.changelog) 81 self.assertEqual(actual_cl[0], self.header_pkg) 82 self.assertNotEqual(actual_cl[-1], '\n')
83
84 - def testExistingGoodHeader(self):
85 # Test existing ChangeLog (correct values) 86 self._writelines(self.changelog, [self.header_pkg]) 87 88 UpdateChangeLog(self.pkgdir, self.user, 'test!', self.skel_changelog, self.cat, self.pkg, quiet=True) 89 actual_cl = self._readlines(self.changelog) 90 self.assertEqual(actual_cl[0], self.header_pkg)
91
92 - def testExistingBadHeader(self):
93 # Test existing ChangeLog (wrong values) 94 self._writelines(self.changelog, ['# ChangeLog for \n']) 95 96 UpdateChangeLog(self.pkgdir, self.user, 'test!', self.skel_changelog, self.cat, self.pkg, quiet=True) 97 actual_cl = self._readlines(self.changelog) 98 self.assertEqual(actual_cl[0], self.header_pkg)
99
100 - def testTrailingNewlines(self):
101 # Make sure trailing newlines get chomped. 102 self._writelines(self.changelog, ['#\n', 'foo\n', '\n', 'bar\n', '\n', '\n']) 103 104 UpdateChangeLog(self.pkgdir, self.user, 'test!', self.skel_changelog, self.cat, self.pkg, quiet=True) 105 actual_cl = self._readlines(self.changelog) 106 self.assertNotEqual(actual_cl[-1], '\n')
107