| 1 | # -*- Mode: Python; test-case-name: moap.test.test_commands_cl -*- |
|---|
| 2 | # vi:si:et:sw=4:sts=4:ts=4 |
|---|
| 3 | |
|---|
| 4 | import os |
|---|
| 5 | import time |
|---|
| 6 | import StringIO |
|---|
| 7 | |
|---|
| 8 | from moap.test import common |
|---|
| 9 | |
|---|
| 10 | from moap.util import log |
|---|
| 11 | |
|---|
| 12 | from moap.command import cl |
|---|
| 13 | |
|---|
| 14 | class TestClMoap1(common.TestCase): |
|---|
| 15 | def setUp(self): |
|---|
| 16 | file = os.path.join(os.path.dirname(__file__), 'ChangeLog', |
|---|
| 17 | 'ChangeLog.moap') |
|---|
| 18 | self.cl = cl.ChangeLogFile(file) |
|---|
| 19 | self.cl.parse() |
|---|
| 20 | |
|---|
| 21 | def testGetEntry0(self): |
|---|
| 22 | e = self.cl.getEntry(0) |
|---|
| 23 | self.assertEquals(e.date, "2006-06-15") |
|---|
| 24 | self.assertEquals(e.name, "Thomas Vander Stichele") |
|---|
| 25 | self.assertEquals(e.address, "thomas at apestaart dot org") |
|---|
| 26 | self.assertEquals(len(e.files), 1) |
|---|
| 27 | self.assertEquals(e.files, ["moap/vcs/svn.py"]) |
|---|
| 28 | # we don't want the empty line because text ends in \n |
|---|
| 29 | lines = e.text.split("\n")[:-1] |
|---|
| 30 | self.assertEquals(len(lines), 2) |
|---|
| 31 | |
|---|
| 32 | def testGetEntry1(self): |
|---|
| 33 | e = self.cl.getEntry(1) |
|---|
| 34 | self.assertEquals(e.date, "2006-06-12") |
|---|
| 35 | self.assertEquals(e.name, "Thomas Vander Stichele") |
|---|
| 36 | self.assertEquals(e.address, "thomas at apestaart dot org") |
|---|
| 37 | self.assertEquals(len(e.files), 2) |
|---|
| 38 | self.assertEquals(e.files, [ |
|---|
| 39 | "moap/commands/doap.py", |
|---|
| 40 | "moap/doap/doap.py", |
|---|
| 41 | ]) |
|---|
| 42 | |
|---|
| 43 | def testFind(self): |
|---|
| 44 | searchTerms = ['show'] |
|---|
| 45 | entries = self.cl.find(searchTerms) |
|---|
| 46 | self.assertEquals(len(entries), 1) |
|---|
| 47 | e = entries[0] |
|---|
| 48 | self.assertEquals(e.date, "2006-06-12") |
|---|
| 49 | self.assertEquals(e.name, "Thomas Vander Stichele") |
|---|
| 50 | self.assertEquals(e.address, "thomas at apestaart dot org") |
|---|
| 51 | |
|---|
| 52 | def testFindByNameAndDate(self): |
|---|
| 53 | searchTerms = ['Thomas', '2006', 'show'] |
|---|
| 54 | entries = self.cl.find(searchTerms) |
|---|
| 55 | self.assertEquals(len(entries), 1) |
|---|
| 56 | e = entries[0] |
|---|
| 57 | self.assertEquals(e.date, "2006-06-12") |
|---|
| 58 | self.assertEquals(e.name, "Thomas Vander Stichele") |
|---|
| 59 | self.assertEquals(e.address, "thomas at apestaart dot org") |
|---|
| 60 | |
|---|
| 61 | def testFindCaseInsEnSiTiVE(self): |
|---|
| 62 | searchTerms = ['SHOW'] |
|---|
| 63 | entries = self.cl.find(searchTerms) |
|---|
| 64 | self.assertEquals(len(entries), 1) |
|---|
| 65 | e = entries[0] |
|---|
| 66 | self.assertEquals(e.date, "2006-06-12") |
|---|
| 67 | self.assertEquals(e.name, "Thomas Vander Stichele") |
|---|
| 68 | self.assertEquals(e.address, "thomas at apestaart dot org") |
|---|
| 69 | |
|---|
| 70 | def testFindCaseSensitive(self): |
|---|
| 71 | searchTerms = ['SHOW'] |
|---|
| 72 | entries = self.cl.find(searchTerms, caseSensitive=True) |
|---|
| 73 | self.assertEquals(len(entries), 0) |
|---|
| 74 | searchTerms = ['show'] |
|---|
| 75 | entries = self.cl.find(searchTerms, caseSensitive=True) |
|---|
| 76 | self.assertEquals(len(entries), 1) |
|---|
| 77 | e = entries[0] |
|---|
| 78 | self.assertEquals(e.date, "2006-06-12") |
|---|
| 79 | self.assertEquals(e.name, "Thomas Vander Stichele") |
|---|
| 80 | self.assertEquals(e.address, "thomas at apestaart dot org") |
|---|
| 81 | |
|---|
| 82 | def testFindMultiple(self): |
|---|
| 83 | searchTerms = ['svn.py'] |
|---|
| 84 | entries = self.cl.find(searchTerms) |
|---|
| 85 | self.assertEquals(len(entries), 3) |
|---|
| 86 | e = entries[0] |
|---|
| 87 | self.assertEquals(e.date, "2006-06-15") |
|---|
| 88 | self.assertEquals(e.name, "Thomas Vander Stichele") |
|---|
| 89 | self.assertEquals(e.address, "thomas at apestaart dot org") |
|---|
| 90 | e = entries[1] |
|---|
| 91 | self.assertEquals(e.date, "2006-06-11") |
|---|
| 92 | self.assertEquals(e.name, "Thomas Vander Stichele") |
|---|
| 93 | self.assertEquals(e.address, "thomas at apestaart dot org") |
|---|
| 94 | e = entries[2] |
|---|
| 95 | self.assertEquals(e.date, "2006-06-11") |
|---|
| 96 | self.assertEquals(e.name, "Thomas Vander Stichele") |
|---|
| 97 | self.assertEquals(e.address, "thomas at apestaart dot org") |
|---|
| 98 | |
|---|
| 99 | searchTerms = ['svn.py', '--no-commit'] |
|---|
| 100 | entries = self.cl.find(searchTerms) |
|---|
| 101 | self.assertEquals(len(entries), 1) |
|---|
| 102 | e = entries[0] |
|---|
| 103 | self.assertEquals(e.date, "2006-06-11") |
|---|
| 104 | self.assertEquals(e.name, "Thomas Vander Stichele") |
|---|
| 105 | self.assertEquals(e.address, "thomas at apestaart dot org") |
|---|
| 106 | |
|---|
| 107 | searchTerms = ['svn.py', 'foobar'] |
|---|
| 108 | entries = self.cl.find(searchTerms) |
|---|
| 109 | self.assertEquals(len(entries), 0) |
|---|
| 110 | |
|---|
| 111 | class TestClGstPluginsGood(common.TestCase): |
|---|
| 112 | def setUp(self): |
|---|
| 113 | file = os.path.join(os.path.dirname(__file__), 'ChangeLog', |
|---|
| 114 | 'ChangeLog.gst-plugins-good') |
|---|
| 115 | self.cl = cl.ChangeLogFile(file) |
|---|
| 116 | self.cl.parse() |
|---|
| 117 | |
|---|
| 118 | def testGetEntry0(self): |
|---|
| 119 | e = self.cl.getEntry(0) |
|---|
| 120 | self.assertEquals(e.date, "2006-06-29") |
|---|
| 121 | self.assertEquals(e.name, "Thomas Vander Stichele") |
|---|
| 122 | self.assertEquals(e.address, "thomas at apestaart dot org") |
|---|
| 123 | self.assertEquals(len(e.files), 1) |
|---|
| 124 | self.assertEquals(e.files, ["tests/check/elements/level.c"]) |
|---|
| 125 | # we don't want the empty line because text ends in \n |
|---|
| 126 | lines = e.text.split("\n")[:-1] |
|---|
| 127 | self.assertEquals(len(lines), 2) |
|---|
| 128 | |
|---|
| 129 | class TestClGstreamer(common.TestCase): |
|---|
| 130 | def setUp(self): |
|---|
| 131 | file = os.path.join(os.path.dirname(__file__), 'ChangeLog', |
|---|
| 132 | 'ChangeLog.gstreamer') |
|---|
| 133 | self.cl = cl.ChangeLogFile(file) |
|---|
| 134 | self.cl.parse() |
|---|
| 135 | |
|---|
| 136 | def testGetEntry0(self): |
|---|
| 137 | e = self.cl.getEntry(0) |
|---|
| 138 | self.assertEquals(e.date, "2006-07-02") |
|---|
| 139 | self.assertEquals(e.name, "Thomas Vander Stichele") |
|---|
| 140 | self.assertEquals(e.address, "thomas at apestaart dot org") |
|---|
| 141 | self.assertEquals(len(e.files), 1) |
|---|
| 142 | self.assertEquals(e.files, ["tests/check/gst/gststructure.c"]) |
|---|
| 143 | # we don't want the empty line because text ends in \n |
|---|
| 144 | lines = e.text.split("\n")[:-1] |
|---|
| 145 | self.assertEquals(len(lines), 3) |
|---|
| 146 | |
|---|
| 147 | class TestClGstPluginsBase(common.TestCase): |
|---|
| 148 | def setUp(self): |
|---|
| 149 | self.file = os.path.join(os.path.dirname(__file__), 'ChangeLog', |
|---|
| 150 | 'ChangeLog.gst-plugins-base') |
|---|
| 151 | self.cl = cl.ChangeLogFile(self.file) |
|---|
| 152 | self.cl.parse() |
|---|
| 153 | |
|---|
| 154 | def testGetRelease(self): |
|---|
| 155 | e = self.cl.getEntry(0) |
|---|
| 156 | self.assertEquals(e.version, "0.10.10") |
|---|
| 157 | |
|---|
| 158 | def testGetContributors(self): |
|---|
| 159 | e = self.cl.getEntry(1) |
|---|
| 160 | self.assertEquals(e.contributors, ["Michael Smith", ]) |
|---|
| 161 | |
|---|
| 162 | def testContributors(self): |
|---|
| 163 | stdout = StringIO.StringIO() |
|---|
| 164 | c = cl.ChangeLog(stdout=stdout) |
|---|
| 165 | ret = c.parse(['-C', self.file, 'contributors']) |
|---|
| 166 | self.assertEquals(ret, 0) |
|---|
| 167 | self.assertEquals(stdout.getvalue(), "\n") |
|---|
| 168 | |
|---|
| 169 | def testContributorsRelease(self): |
|---|
| 170 | stdout = StringIO.StringIO() |
|---|
| 171 | c = cl.ChangeLog(stdout=stdout) |
|---|
| 172 | ret = c.parse(['-C', self.file, 'contributors', '-r', '0.10.10']) |
|---|
| 173 | self.assertEquals(ret, 0) |
|---|
| 174 | self.assertEquals(stdout.getvalue(), """Michael Smith |
|---|
| 175 | Thomas Vander Stichele |
|---|
| 176 | Wim Taymans |
|---|
| 177 | """) |
|---|
| 178 | |
|---|
| 179 | def testFind(self): |
|---|
| 180 | stdout = StringIO.StringIO() |
|---|
| 181 | c = cl.ChangeLog(stdout=stdout) |
|---|
| 182 | ret = c.parse(['-C', self.file, 'find', 'gnomevfs', ]) |
|---|
| 183 | self.assertEquals(ret, 0) |
|---|
| 184 | self.assertEquals(stdout.getvalue(), |
|---|
| 185 | """2006-09-07 Thomas Vander Stichele <thomas at apestaart dot org> |
|---|
| 186 | |
|---|
| 187 | \tpatch by: Wim Taymans <wim at fluendo dot com> |
|---|
| 188 | |
|---|
| 189 | \t* ext/gnomevfs/gstgnomevfssrc.c: (gst_gnome_vfs_src_start): |
|---|
| 190 | \tThis patch removes the RANDOM flag that was incorrectly introduced with |
|---|
| 191 | \trevision 1.91. Fixes #354590 |
|---|
| 192 | """) |
|---|
| 193 | |
|---|
| 194 | def testFindMultiple(self): |
|---|
| 195 | stdout = StringIO.StringIO() |
|---|
| 196 | c = cl.ChangeLog(stdout=stdout) |
|---|
| 197 | ret = c.parse(['-C', self.file, 'find', 'gst', ]) |
|---|
| 198 | self.assertEquals(ret, 0) |
|---|
| 199 | self.assertEquals(stdout.getvalue(), |
|---|
| 200 | """2006-09-07 Thomas Vander Stichele <thomas at apestaart dot org> |
|---|
| 201 | |
|---|
| 202 | \tpatch by: Michael Smith <msmith at fluendo dot com> |
|---|
| 203 | |
|---|
| 204 | \t* gst/tcp/gstmultifdsink.c: (is_sync_frame), |
|---|
| 205 | \t(gst_multi_fd_sink_client_queue_buffer), |
|---|
| 206 | \t(gst_multi_fd_sink_new_client): |
|---|
| 207 | \t* tests/check/elements/multifdsink.c: (GST_START_TEST), |
|---|
| 208 | \t(multifdsink_suite): |
|---|
| 209 | \t Fix implementation of sync-method 'next-keyframe' |
|---|
| 210 | \t Closes #354594 |
|---|
| 211 | |
|---|
| 212 | 2006-09-07 Thomas Vander Stichele <thomas at apestaart dot org> |
|---|
| 213 | |
|---|
| 214 | \tpatch by: Wim Taymans <wim at fluendo dot com> |
|---|
| 215 | |
|---|
| 216 | \t* ext/gnomevfs/gstgnomevfssrc.c: (gst_gnome_vfs_src_start): |
|---|
| 217 | \tThis patch removes the RANDOM flag that was incorrectly introduced with |
|---|
| 218 | \trevision 1.91. Fixes #354590 |
|---|
| 219 | """) |
|---|
| 220 | |
|---|
| 221 | stdout = StringIO.StringIO() |
|---|
| 222 | c = cl.ChangeLog(stdout=stdout) |
|---|
| 223 | ret = c.parse(['-C', self.file, 'find', 'gst', 'gnomevfs', ]) |
|---|
| 224 | self.assertEquals(ret, 0) |
|---|
| 225 | self.assertEquals(stdout.getvalue(), |
|---|
| 226 | """2006-09-07 Thomas Vander Stichele <thomas at apestaart dot org> |
|---|
| 227 | |
|---|
| 228 | \tpatch by: Wim Taymans <wim at fluendo dot com> |
|---|
| 229 | |
|---|
| 230 | \t* ext/gnomevfs/gstgnomevfssrc.c: (gst_gnome_vfs_src_start): |
|---|
| 231 | \tThis patch removes the RANDOM flag that was incorrectly introduced with |
|---|
| 232 | \trevision 1.91. Fixes #354590 |
|---|
| 233 | """) |
|---|
| 234 | |
|---|
| 235 | stdout = StringIO.StringIO() |
|---|
| 236 | c = cl.ChangeLog(stdout=stdout) |
|---|
| 237 | ret = c.parse(['-C', self.file, 'find', 'gst', 'jpegdec', ]) |
|---|
| 238 | self.assertEquals(ret, 0) |
|---|
| 239 | self.assertEquals(stdout.getvalue(), "") |
|---|
| 240 | |
|---|
| 241 | class TestClGstPluginsBase270(common.TestCase): |
|---|
| 242 | def setUp(self): |
|---|
| 243 | self.file = os.path.join(os.path.dirname(__file__), 'ChangeLog', |
|---|
| 244 | 'ChangeLog.gst-plugins-base.270') |
|---|
| 245 | self.cl = cl.ChangeLogFile(self.file) |
|---|
| 246 | self.cl.parse() |
|---|
| 247 | |
|---|
| 248 | def testGetContributors(self): |
|---|
| 249 | e = self.cl.getEntry(0) |
|---|
| 250 | # because it's written Patch by and not Patch by: it fails to find |
|---|
| 251 | # contributors |
|---|
| 252 | self.assertEquals(e.contributors, []) |
|---|
| 253 | |
|---|
| 254 | def testFind(self): |
|---|
| 255 | stdout = StringIO.StringIO() |
|---|
| 256 | c = cl.ChangeLog(stdout=stdout) |
|---|
| 257 | ret = c.parse(['-C', self.file, 'find', 'ogg', ]) |
|---|
| 258 | self.assertEquals(ret, 0) |
|---|
| 259 | self.assertEquals(stdout.getvalue(), "") |
|---|
| 260 | |
|---|
| 261 | # In ticket #271, the trailing space in the date/name/address line used to |
|---|
| 262 | # cause misparsing |
|---|
| 263 | class TestClGstPluginsBase271(common.TestCase): |
|---|
| 264 | def setUp(self): |
|---|
| 265 | self.file = os.path.join(os.path.dirname(__file__), 'ChangeLog', |
|---|
| 266 | 'ChangeLog.gst-plugins-base.271') |
|---|
| 267 | self.cl = cl.ChangeLogFile(self.file) |
|---|
| 268 | self.cl.parse() |
|---|
| 269 | |
|---|
| 270 | def testGetContributors(self): |
|---|
| 271 | e = self.cl.getEntry(0) |
|---|
| 272 | self.assertEquals(e.date, "2006-09-29") |
|---|
| 273 | self.assertEquals(e.name, "Philippe Kalaf") |
|---|
| 274 | self.assertEquals(e.address, "philippe.kalaf@collabora.co.uk") |
|---|
| 275 | |
|---|
| 276 | class TestCheckin(common.SVNTestCase): |
|---|
| 277 | def setUp(self): |
|---|
| 278 | common.SVNTestCase.setUp(self) |
|---|
| 279 | self.repodir = self.createRepository() |
|---|
| 280 | self.livedir = self.createLive() |
|---|
| 281 | |
|---|
| 282 | def tearDown(self): |
|---|
| 283 | log.debug('unittest', 'removing temp repodir in %s' % self.repodir) |
|---|
| 284 | os.system('rm -rf %s' % self.repodir) |
|---|
| 285 | log.debug('unittest', 'removing temp livedir in %s' % self.livedir) |
|---|
| 286 | os.system('rm -rf %s' % self.livedir) |
|---|
| 287 | common.SVNTestCase.tearDown(self) |
|---|
| 288 | |
|---|
| 289 | def testCheckinNewDirectory(self): |
|---|
| 290 | # test a moap cl ci when a parent directory has just been added, |
|---|
| 291 | # and is not listed in the ChangeLog of course |
|---|
| 292 | os.system('svn co file://%s %s > /dev/null' % ( |
|---|
| 293 | self.repodir, self.livedir)) |
|---|
| 294 | self.liveCreateDirectory('src') |
|---|
| 295 | self.liveWriteFile('src/test', 'some contents') |
|---|
| 296 | self.liveWriteFile('ChangeLog', '') |
|---|
| 297 | os.system('svn add %s > /dev/null' % os.path.join( |
|---|
| 298 | self.livedir, 'ChangeLog')) |
|---|
| 299 | os.system('svn add %s > /dev/null' % os.path.join(self.livedir, 'src')) |
|---|
| 300 | self.liveWriteFile('ChangeLog', """2006-08-15 Thomas Vander Stichele <thomas at apestaart dot org> |
|---|
| 301 | |
|---|
| 302 | \t* src/test: |
|---|
| 303 | \t some content |
|---|
| 304 | """) |
|---|
| 305 | # FIXME: setting stdout and stderr doesn't work yet |
|---|
| 306 | c = cl.ChangeLog(stdout=open('/dev/null'), stderr=open('/dev/null')) |
|---|
| 307 | ret = c.parse(['-C', self.livedir, 'checkin']) |
|---|
| 308 | self.assertEquals(ret, 0) |
|---|
| 309 | |
|---|
| 310 | def testPrepareDiff(self): |
|---|
| 311 | # Override any externally set CHANGE_LOG_NAME and _EMAIL_ADDRESS |
|---|
| 312 | os.environ['CHANGE_LOG_NAME'] = 'Hugo van der Hardcore' |
|---|
| 313 | os.environ['CHANGE_LOG_EMAIL_ADDRESS'] ='hugo@ninenin.jas' |
|---|
| 314 | |
|---|
| 315 | os.system('svn co file://%s %s > /dev/null' % ( |
|---|
| 316 | self.repodir, self.livedir)) |
|---|
| 317 | self.liveWriteFile('ChangeLog', '') |
|---|
| 318 | os.system('svn add %s > /dev/null' % os.path.join(self.livedir, |
|---|
| 319 | 'ChangeLog')) |
|---|
| 320 | self.liveWriteFile('test', '') |
|---|
| 321 | os.system('svn add %s > /dev/null' % os.path.join(self.livedir, |
|---|
| 322 | 'test')) |
|---|
| 323 | os.system('svn commit -m "add" %s' % |
|---|
| 324 | os.path.join(self.livedir)) |
|---|
| 325 | |
|---|
| 326 | self.liveWriteFile('test', 'some contents') |
|---|
| 327 | |
|---|
| 328 | # FIXME: this fails because an empty ChangeLog causes tracebacks |
|---|
| 329 | # c = cl.Diff() |
|---|
| 330 | # print c.do([self.livedir, ]) |
|---|
| 331 | |
|---|
| 332 | log.debug('unittest', 'moap cl prep -c') |
|---|
| 333 | c = cl.ChangeLog(stdout=common.FakeStdOut()) |
|---|
| 334 | c.parse(['-C', self.livedir, 'prepare', '-c', ]) |
|---|
| 335 | # FIXME: the diff command will diff relative paths; |
|---|
| 336 | # so running just moap cl diff will not actually change to the repo |
|---|
| 337 | # path and fail to show diffs |
|---|
| 338 | oldPath = os.getcwd() |
|---|
| 339 | os.chdir(self.livedir) |
|---|
| 340 | log.debug('unittest', 'moap cl diff') |
|---|
| 341 | stdout = StringIO.StringIO() |
|---|
| 342 | c = cl.ChangeLog(stdout=stdout) |
|---|
| 343 | c.parse(['-C', self.livedir, 'diff', ]) |
|---|
| 344 | os.chdir(oldPath) |
|---|
| 345 | |
|---|
| 346 | firstline = time.strftime('%Y-%m-%d') + ' ' + \ |
|---|
| 347 | 'Hugo van der Hardcore' + ' <' + 'hugo@ninenin.jas' + '>' |
|---|
| 348 | expected = firstline + """ |
|---|
| 349 | |
|---|
| 350 | \treviewed by: <delete if not using a buddy> |
|---|
| 351 | \tpatch by: <delete if not someone else's patch> |
|---|
| 352 | |
|---|
| 353 | \t* test: |
|---|
| 354 | |
|---|
| 355 | Index: test |
|---|
| 356 | =================================================================== |
|---|
| 357 | --- test\t(revision 1) |
|---|
| 358 | +++ test\t(working copy) |
|---|
| 359 | @@ -0,0 +1 @@ |
|---|
| 360 | +some contents |
|---|
| 361 | \ No newline at end of file |
|---|
| 362 | """ |
|---|
| 363 | # skip the date |
|---|
| 364 | l = len("2007-07-30") |
|---|
| 365 | self.assertEquals(stdout.getvalue()[l:], expected[l:]) |
|---|
| 366 | |
|---|
| 367 | def testDoubleDiff(self): |
|---|
| 368 | # see https://thomas.apestaart.org/moap/trac/ticket/303 |
|---|
| 369 | |
|---|
| 370 | # Override any externally set CHANGE_LOG_NAME and _EMAIL_ADDRESS |
|---|
| 371 | os.environ['CHANGE_LOG_NAME'] = 'Hugo van der Hardcore' |
|---|
| 372 | os.environ['CHANGE_LOG_EMAIL_ADDRESS'] ='hugo@ninenin.jas' |
|---|
| 373 | |
|---|
| 374 | os.system('svn co file://%s %s > /dev/null' % ( |
|---|
| 375 | self.repodir, self.livedir)) |
|---|
| 376 | self.liveWriteFile('ChangeLog', '') |
|---|
| 377 | os.system('svn add %s > /dev/null' % os.path.join(self.livedir, |
|---|
| 378 | 'ChangeLog')) |
|---|
| 379 | self.liveWriteFile('test', '') |
|---|
| 380 | os.system('svn add %s > /dev/null' % os.path.join(self.livedir, |
|---|
| 381 | 'test')) |
|---|
| 382 | os.system('svn commit -m "add" %s' % |
|---|
| 383 | os.path.join(self.livedir)) |
|---|
| 384 | |
|---|
| 385 | self.liveWriteFile('test', 'some contents') |
|---|
| 386 | |
|---|
| 387 | log.debug('unittest', 'moap cl prep -c') |
|---|
| 388 | c = cl.ChangeLog(stdout=common.FakeStdOut()) |
|---|
| 389 | c.parse(['-C', self.livedir, 'prepare', '-c', ]) |
|---|
| 390 | # add the test file a second time |
|---|
| 391 | handle = open(os.path.join(self.livedir, 'ChangeLog'), 'a') |
|---|
| 392 | handle.write('\t* test:\n') |
|---|
| 393 | handle.close() |
|---|
| 394 | |
|---|
| 395 | |
|---|
| 396 | # FIXME: the diff command will diff relative paths; |
|---|
| 397 | # so running just moap cl diff will not actually change to the repo |
|---|
| 398 | # path and fail to show diffs |
|---|
| 399 | oldPath = os.getcwd() |
|---|
| 400 | os.chdir(self.livedir) |
|---|
| 401 | log.debug('unittest', 'moap cl diff') |
|---|
| 402 | stdout = StringIO.StringIO() |
|---|
| 403 | c = cl.ChangeLog(stdout=stdout) |
|---|
| 404 | c.parse(['-C', self.livedir, 'diff', ]) |
|---|
| 405 | os.chdir(oldPath) |
|---|
| 406 | |
|---|
| 407 | firstline = time.strftime('%Y-%m-%d') + ' ' + \ |
|---|
| 408 | 'Hugo van der Hardcore' + ' <' + 'hugo@ninenin.jas' + '>' |
|---|
| 409 | expected = firstline + """ |
|---|
| 410 | |
|---|
| 411 | \treviewed by: <delete if not using a buddy> |
|---|
| 412 | \tpatch by: <delete if not someone else's patch> |
|---|
| 413 | |
|---|
| 414 | \t* test: |
|---|
| 415 | |
|---|
| 416 | \t* test: |
|---|
| 417 | Index: test |
|---|
| 418 | =================================================================== |
|---|
| 419 | --- test\t(revision 1) |
|---|
| 420 | +++ test\t(working copy) |
|---|
| 421 | @@ -0,0 +1 @@ |
|---|
| 422 | +some contents |
|---|
| 423 | \ No newline at end of file |
|---|
| 424 | """ |
|---|
| 425 | # skip the date |
|---|
| 426 | l = len("2007-07-30") |
|---|
| 427 | self.assertEquals(stdout.getvalue()[l:], expected[l:]) |
|---|
| 428 | |
|---|
| 429 | |
|---|
| 430 | def testPrepareTagged(self): |
|---|
| 431 | # test an actual patch set commited to moap to see if |
|---|
| 432 | # we extract tags correctly. |
|---|
| 433 | os.system('svn co file://%s %s > /dev/null' % ( |
|---|
| 434 | self.repodir, self.livedir)) |
|---|
| 435 | |
|---|
| 436 | # copy and add mail.py |
|---|
| 437 | file = os.path.join(os.path.dirname(__file__), 'prepare', |
|---|
| 438 | 'mail.py') |
|---|
| 439 | os.system("cp %s %s" % (file, self.livedir)) |
|---|
| 440 | codePath = os.path.join(self.livedir, 'mail.py') |
|---|
| 441 | os.system('svn add %s' % codePath) |
|---|
| 442 | os.system('svn commit -m "add" %s' % self.livedir) |
|---|
| 443 | |
|---|
| 444 | # patch it |
|---|
| 445 | patchPath = os.path.join(os.path.dirname(__file__), 'prepare', |
|---|
| 446 | 'mail.patch') |
|---|
| 447 | os.system('patch %s < %s' % (codePath, patchPath)) |
|---|
| 448 | |
|---|
| 449 | # prepare entry |
|---|
| 450 | log.debug('unittest', 'moap cl prep -c') |
|---|
| 451 | c = cl.ChangeLog(stdout=common.FakeStdOut()) |
|---|
| 452 | # try the version of prepare that allows you to pass the path |
|---|
| 453 | c.parse(['prepare', '-c', self.livedir, ]) |
|---|
| 454 | |
|---|
| 455 | # now check the fresh ChangeLog entry |
|---|
| 456 | ChangeLog = os.path.join(self.livedir, "ChangeLog") |
|---|
| 457 | lines = open(ChangeLog, 'r').readlines() |
|---|
| 458 | # FIXME: Message.send is in here because the diff marks a line |
|---|
| 459 | # of whitespace before the new Message.mailto method as added; |
|---|
| 460 | # we should filter this by parsing the diff better and only looking |
|---|
| 461 | # for affected tags within blocks of non-whitespace, |
|---|
| 462 | # or better defining (nested) location (ie, including end) for tags |
|---|
| 463 | self.assertEquals(lines[5], |
|---|
| 464 | "\t* mail.py " |
|---|
| 465 | "(Message.__init__, Message.setFromm, Message.send,\n") |
|---|
| 466 | self.assertEquals(lines[6], |
|---|
| 467 | "\t Message.mailto):\n") |
|---|
| 468 | |
|---|
| 469 | |
|---|
| 470 | class TestClMoap2(common.TestCase): |
|---|
| 471 | def setUp(self): |
|---|
| 472 | file = os.path.join(os.path.dirname(__file__), 'ChangeLog', |
|---|
| 473 | 'ChangeLog.moap.2') |
|---|
| 474 | self.cl = cl.ChangeLogFile(file) |
|---|
| 475 | self.cl.parse() |
|---|
| 476 | |
|---|
| 477 | def testGetEntry0(self): |
|---|
| 478 | e = self.cl.getEntry(0) |
|---|
| 479 | self.assertEquals(e.date, "2007-03-20") |
|---|
| 480 | self.assertEquals(e.name, "Thomas Vander Stichele") |
|---|
| 481 | self.assertEquals(e.address, "thomas at apestaart dot org") |
|---|
| 482 | self.assertEquals(len(e.files), 7) |
|---|
| 483 | self.assertEquals(e.files[0], "moap/util/Makefile.am") |
|---|
| 484 | self.assertEquals(e.files[6], "moap/vcs/vcs.py") |
|---|
| 485 | # we don't want the empty line because text ends in \n |
|---|
| 486 | lines = e.text.split("\n")[:-1] |
|---|
| 487 | self.assertEquals(len(lines), 13) |
|---|
| 488 | |
|---|
| 489 | def testFindByVersion(self): |
|---|
| 490 | searchTerms = ['0.2.1'] |
|---|
| 491 | entries = self.cl.find(searchTerms) |
|---|
| 492 | self.assertEquals(len(entries), 2) |
|---|
| 493 | |
|---|
| 494 | e = entries[0] |
|---|
| 495 | self.assertEquals(e.version, "0.2.1") |
|---|
| 496 | |
|---|
| 497 | e = entries[1] |
|---|
| 498 | self.assertEquals(e.name, "Thomas Vander Stichele") |
|---|
| 499 | self.assertEquals(e.address, "thomas at apestaart dot org") |
|---|
| 500 | |
|---|
| 501 | class TestClNotEdited(common.TestCase): |
|---|
| 502 | def setUp(self): |
|---|
| 503 | file = os.path.join(os.path.dirname(__file__), 'ChangeLog', |
|---|
| 504 | 'ChangeLog.notedited') |
|---|
| 505 | self.cl = cl.ChangeLogFile(file) |
|---|
| 506 | self.cl.parse() |
|---|
| 507 | |
|---|
| 508 | def testGetBadEntry(self): |
|---|
| 509 | entry = self.cl.getEntry(0) |
|---|
| 510 | self.failUnless(isinstance(entry, cl.ChangeEntry)) |
|---|
| 511 | self.failUnless("mail" in entry.notEdited) |
|---|
| 512 | self.failUnless("name" in entry.notEdited) |
|---|
| 513 | self.failUnless("patched by" in entry.notEdited) |
|---|
| 514 | self.failUnless("reviewer" in entry.notEdited) |
|---|
| 515 | |
|---|
| 516 | |
|---|
| 517 | |
|---|