Merge lp:~dosage-dev/dosage/test-mode into lp:~dosage-dev/dosage/old

Proposed by Tristan Seligmann
Status: Merged
Approved by: Jonathan Jacobs
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~dosage-dev/dosage/test-mode
Merge into: lp:~dosage-dev/dosage/old
Diff against target: 76 lines (+38/-0)
1 file modified
dosage/mainline.py (+38/-0)
To merge this branch: bzr merge lp:~dosage-dev/dosage/test-mode
Reviewer Review Type Date Requested Status
Jonathan Jacobs Approve
Review via email: mp+17178@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Tristan Seligmann (mithrandi) wrote :

Implements a --test mode for testing scrapers.

lp:~dosage-dev/dosage/test-mode updated
608. By Tristan Seligmann

Use izip

Revision history for this message
Jonathan Jacobs (jjacobs) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'dosage/mainline.py'
2--- dosage/mainline.py 2010-01-06 21:44:17 +0000
3+++ dosage/mainline.py 2010-01-12 00:45:21 +0000
4@@ -2,6 +2,7 @@
5 import os
6 import optparse
7 import traceback
8+from itertools import izip
9
10 from dosage import events, scraper
11 from dosage.output import out
12@@ -13,6 +14,7 @@
13 parser = optparse.OptionParser(usage=usage)
14 parser.add_option('-v', '--verbose', action='count', dest='verbose', default=0, help='provides verbose output, use multiple times for more verbosity')
15 parser.add_option('-q', '--quiet', action='count', dest='quiet', default=0, help='suppress all output')
16+ parser.add_option('--test', action='store_true', dest='test', default=False, help='test comic scrapers')
17 parser.add_option('-c', '--catch-up', action='count', dest='catchup', default=None, help='traverse and retrieve all available comics up until the strip that already exists locally, use twice to retrieve until all strips exist locally')
18 parser.add_option('-b', '--base-path', action='store', dest='basepath', default='Comics', help='set the path to create invidivual comic directories in, default is Comics', metavar='PATH')
19 parser.add_option('--base-url', action='store', dest='baseurl', default=None, help='the base URL of your comics directory (for RSS, HTML, etc.); this should correspond to --base-path', metavar='PATH')
20@@ -82,6 +84,31 @@
21 if not self.saveComics(comics) and self.settings['catchup'] < 2:
22 break
23
24+
25+
26+ def testScraper(self):
27+ """
28+ Test a scraper.
29+
30+ We must be able to traverse backward for at least 5 pages from the
31+ start, and find strip images on at least 4 pages.
32+ """
33+ empty = 0
34+ for n, comics in izip(xrange(5), self.module):
35+ if len(comics) == 0:
36+ empty += 1
37+ else:
38+ self.saveComics(comics)
39+
40+ if n < 4:
41+ out.write('Traversal failed after %d strips.' % (n + 1), 0)
42+ elif empty > 1:
43+ out.write('Failed to find strip images on %d pages.' % empty, 0)
44+ else:
45+ out.write('Test successful!', 0)
46+
47+
48+
49 def catchupIndex(self, index):
50 out.write('Catching up from index "%s"...' % (index,), 0)
51 self.module.setStrip(index)
52@@ -134,6 +161,15 @@
53 else:
54 self.safeOp(self.catchup)
55
56+
57+ def doTest(self):
58+ """
59+ Invoke test mode for each of the selected comics.
60+ """
61+ for comic in self.useComics():
62+ self.safeOp(self.testScraper)
63+
64+
65 def doCurrent(self):
66 for comic in self.useComics():
67 if self.indices:
68@@ -200,6 +236,8 @@
69 out.write('Warning: No comics specified, bailing out!', 0)
70 elif self.settings['modhelp']:
71 self.doHelp()
72+ elif self.settings['test']:
73+ self.doTest()
74 elif self.settings['catchup']:
75 self.doCatchup()
76 else:

Subscribers

People subscribed via source and target branches

to all changes: