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
=== modified file 'dosage/mainline.py'
--- dosage/mainline.py 2010-01-06 21:44:17 +0000
+++ dosage/mainline.py 2010-01-12 00:45:21 +0000
@@ -2,6 +2,7 @@
2import os2import os
3import optparse3import optparse
4import traceback4import traceback
5from itertools import izip
56
6from dosage import events, scraper7from dosage import events, scraper
7from dosage.output import out8from dosage.output import out
@@ -13,6 +14,7 @@
13 parser = optparse.OptionParser(usage=usage)14 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('-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('-q', '--quiet', action='count', dest='quiet', default=0, help='suppress all output')
17 parser.add_option('--test', action='store_true', dest='test', default=False, help='test comic scrapers')
16 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('-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')
17 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('-b', '--base-path', action='store', dest='basepath', default='Comics', help='set the path to create invidivual comic directories in, default is Comics', metavar='PATH')
18 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 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')
@@ -82,6 +84,31 @@
82 if not self.saveComics(comics) and self.settings['catchup'] < 2:84 if not self.saveComics(comics) and self.settings['catchup'] < 2:
83 break85 break
8486
87
88
89 def testScraper(self):
90 """
91 Test a scraper.
92
93 We must be able to traverse backward for at least 5 pages from the
94 start, and find strip images on at least 4 pages.
95 """
96 empty = 0
97 for n, comics in izip(xrange(5), self.module):
98 if len(comics) == 0:
99 empty += 1
100 else:
101 self.saveComics(comics)
102
103 if n < 4:
104 out.write('Traversal failed after %d strips.' % (n + 1), 0)
105 elif empty > 1:
106 out.write('Failed to find strip images on %d pages.' % empty, 0)
107 else:
108 out.write('Test successful!', 0)
109
110
111
85 def catchupIndex(self, index):112 def catchupIndex(self, index):
86 out.write('Catching up from index "%s"...' % (index,), 0)113 out.write('Catching up from index "%s"...' % (index,), 0)
87 self.module.setStrip(index)114 self.module.setStrip(index)
@@ -134,6 +161,15 @@
134 else:161 else:
135 self.safeOp(self.catchup)162 self.safeOp(self.catchup)
136163
164
165 def doTest(self):
166 """
167 Invoke test mode for each of the selected comics.
168 """
169 for comic in self.useComics():
170 self.safeOp(self.testScraper)
171
172
137 def doCurrent(self):173 def doCurrent(self):
138 for comic in self.useComics():174 for comic in self.useComics():
139 if self.indices:175 if self.indices:
@@ -200,6 +236,8 @@
200 out.write('Warning: No comics specified, bailing out!', 0)236 out.write('Warning: No comics specified, bailing out!', 0)
201 elif self.settings['modhelp']:237 elif self.settings['modhelp']:
202 self.doHelp()238 self.doHelp()
239 elif self.settings['test']:
240 self.doTest()
203 elif self.settings['catchup']:241 elif self.settings['catchup']:
204 self.doCatchup()242 self.doCatchup()
205 else:243 else:

Subscribers

People subscribed via source and target branches

to all changes: