<s> import shlex <EOL> import subprocess <EOL> import re <EOL> TEST_CASES_FOLDER = "<STR_LIT>" <EOL> PREDEFINED_OPTIONS = [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> class IllegalArgument ( Exception ) : <EOL> pass <EOL> class NoseArgumentBuilder ( ) : <EOL> def __init__ ( self , args ) : <EOL> self . args = args <EOL> self . nose_arguments = "<STR_LIT>" <EOL> def build ( self ) : <EOL> self . add_category ( ) <EOL> self . find_and_add_modules ( ) <EOL> self . process_only_option ( ) <EOL> self . process_all_option ( ) <EOL> self . add_predefined_arguments ( ) <EOL> return "<STR_LIT>" + self . nose_arguments <EOL> def add_category ( self ) : <EOL> all_categories = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> if ( self . args . category in all_categories ) : <EOL> self . nose_arguments = TEST_CASES_FOLDER + "<STR_LIT:/>" + self . args . category + "<STR_LIT>" <EOL> def find_and_add_modules ( self ) : <EOL> if ( self . args . modules is not None ) : <EOL> modules = self . args . modules . split ( "<STR_LIT:U+002C>" ) <EOL> files = [ ] <EOL> for module in modules : <EOL> files_for_module = self . find_files_matching ( module ) <EOL> files . extend ( files_for_module ) <EOL> self . nose_arguments = "<STR_LIT:U+0020>" . join ( files ) <EOL> def process_only_option ( self ) : <EOL> if ( self . args . only is not None ) : <EOL> self . nose_arguments = self . args . only . replace ( "<STR_LIT:U+002C>" , "<STR_LIT:U+0020>" ) + "<STR_LIT:U+0020>" <EOL> def process_all_option ( self ) : <EOL> if ( self . args . all == True ) : <EOL> self . nose_arguments = TEST_CASES_FOLDER + "<STR_LIT>" <EOL> def add_predefined_arguments ( self ) : <EOL> self . nose_arguments += "<STR_LIT:U+0020>" . join ( PREDEFINED_OPTIONS ) <EOL> def find_files_matching ( self , module_name ) : <EOL> self . check_input ( module_name ) <EOL> command = "<STR_LIT>" + module_name + "<STR_LIT:U+0020>" + TEST_CASES_FOLDER + "<STR_LIT>" <EOL> return subprocess . check_output ( shlex . split ( command ) , shell = False ) . split ( "<STR_LIT:\n>" ) <EOL> def check_input ( self , input ) : <EOL> """<STR_LIT>""" <EOL> if re . match ( "<STR_LIT>" , input ) is None : <EOL> raise IllegalArgument ( "<STR_LIT>" ) </s>
