#NEWLINE# def fetch_test_data( ) : #NEWLINE# #INDENT# "\n    Fetches test data if it's missing.\n    " #NEWLINE# data_dir = os . path . join ( SETUP_DIR , 'tests' , 'data' ) #NEWLINE# if ( os . path . isdir ( data_dir ) and ( not os . listdir ( data_dir ) ) and os . path . isfile ( os . path . join ( SETUP_DIR , '.gitmodules' ) ) ) : #NEWLINE# #INDENT# import subprocess #NEWLINE# subprocess . call ( [ 'git' , 'submodule' , 'update' , '--init' , '--recursive' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# os . mkdir ( data_dir ) #NEWLINE# #UNINDENT# except OSError as exc : #NEWLINE# #INDENT# if ( exc . errno != errno . EEXIST ) : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# #UNINDENT# if ( not os . listdir ( data_dir ) ) : #NEWLINE# #INDENT# import requests #NEWLINE# import six #NEWLINE# resp = requests . get ( 'https://github.com/spaceboats/busbus-test-data/archive/v{0}.zip' . format ( VERSION ) ) #NEWLINE# with zipfile . ZipFile ( six . BytesIO ( resp . content ) ) as z : #NEWLINE# #INDENT# prefix = 'busbus-test-data-{0}/' . format ( VERSION ) #NEWLINE# for filename in z . namelist ( ) : #NEWLINE# #INDENT# if ( ( filename == prefix ) or ( not filename . startswith ( prefix ) ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# filename = filename [ len ( prefix ) : ] #NEWLINE# if filename . endswith ( '/' ) : #NEWLINE# #INDENT# os . mkdir ( os . path . join ( data_dir , filename ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# with open ( os . path . join ( data_dir , filename ) , 'wb' ) as f : #NEWLINE# #INDENT# f . write ( z . read ( ( prefix + filename ) ) )