Move downloading code into separate function for readability.
This commit is contained in:
		
							parent
							
								
									5c74c7a93e
								
							
						
					
					
						commit
						9d7e7ad33a
					
				
							
								
								
									
										34
									
								
								test/test.py
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								test/test.py
									
									
									
									
									
								
							@ -204,6 +204,23 @@ def makeBrowserCommands(browserManifestFile):
 | 
				
			|||||||
        browsers = [BrowserCommand(browser) for browser in json.load(bmf)]
 | 
					        browsers = [BrowserCommand(browser) for browser in json.load(bmf)]
 | 
				
			||||||
    return browsers
 | 
					    return browsers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def downloadLinkedPDFs(manifestList):
 | 
				
			||||||
 | 
					    for item in manifestList:
 | 
				
			||||||
 | 
					        f, isLink = item['file'], item.get('link', False)
 | 
				
			||||||
 | 
					        if isLink and not os.access(f, os.R_OK):
 | 
				
			||||||
 | 
					            linkFile = open(f +'.link')
 | 
				
			||||||
 | 
					            link = linkFile.read()
 | 
				
			||||||
 | 
					            linkFile.close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            sys.stdout.write('Downloading '+ link +' to '+ f +' ...')
 | 
				
			||||||
 | 
					            sys.stdout.flush()
 | 
				
			||||||
 | 
					            response = urllib2.urlopen(link)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            with open(f, 'w') as out:
 | 
				
			||||||
 | 
					                out.write(response.read())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            print 'done'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def setUp(options):
 | 
					def setUp(options):
 | 
				
			||||||
    # Only serve files from a pdf.js clone
 | 
					    # Only serve files from a pdf.js clone
 | 
				
			||||||
    assert not ANAL or os.path.isfile('../pdf.js') and os.path.isdir('../.git')
 | 
					    assert not ANAL or os.path.isfile('../pdf.js') and os.path.isdir('../.git')
 | 
				
			||||||
@ -227,22 +244,7 @@ def setUp(options):
 | 
				
			|||||||
    with open(options.manifestFile) as mf:
 | 
					    with open(options.manifestFile) as mf:
 | 
				
			||||||
        manifestList = json.load(mf)
 | 
					        manifestList = json.load(mf)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for item in manifestList:
 | 
					    downloadLinkedPDFs(manifestList)
 | 
				
			||||||
        f, isLink = item['file'], item.get('link', False)
 | 
					 | 
				
			||||||
        if isLink and not os.access(f, os.R_OK):
 | 
					 | 
				
			||||||
            linkFile = open(f +'.link')
 | 
					 | 
				
			||||||
            link = linkFile.read()
 | 
					 | 
				
			||||||
            linkFile.close()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            sys.stdout.write('Downloading '+ link +' to '+ f +' ...')
 | 
					 | 
				
			||||||
            sys.stdout.flush()
 | 
					 | 
				
			||||||
            response = urllib2.urlopen(link)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            out = open(f, 'w')
 | 
					 | 
				
			||||||
            out.write(response.read())
 | 
					 | 
				
			||||||
            out.close()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            print 'done'
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for b in testBrowsers:
 | 
					    for b in testBrowsers:
 | 
				
			||||||
        State.taskResults[b.name] = { }
 | 
					        State.taskResults[b.name] = { }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user