<s> import logging <EOL> import os <EOL> import re <EOL> import sys <EOL> from nose . plugins import Plugin <EOL> from base import Knows <EOL> def modname ( qualname ) : <EOL> candidate = qualname [ <NUM_LIT:0> ] <EOL> for elem in qualname [ <NUM_LIT:1> : ] : <EOL> if "<STR_LIT:.>" . join ( ( candidate , elem ) ) not in sys . modules : <EOL> return candidate <EOL> candidate = "<STR_LIT:.>" . join ( ( candidate , elem ) ) <EOL> TESTMETH = re . compile ( r"<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> TESTFUNC = re . compile ( r"<STR_LIT>" ) <EOL> def parse_test_name ( test_name ) : <EOL> mo = TESTMETH . match ( test_name ) <EOL> if mo : <EOL> qualname = mo . groupdict ( ) [ "<STR_LIT:class>" ] . split ( "<STR_LIT:.>" ) <EOL> method_name = mo . groupdict ( ) [ "<STR_LIT>" ] <EOL> module_name = "<STR_LIT:.>" . join ( qualname [ : - <NUM_LIT:1> ] ) <EOL> class_name = qualname [ - <NUM_LIT:1> ] <EOL> return "<STR_LIT>" % ( module_name , class_name , method_name ) <EOL> mo = TESTFUNC . match ( test_name ) <EOL> if mo : <EOL> qualname = mo . groupdict ( ) [ "<STR_LIT>" ] . split ( "<STR_LIT:.>" ) <EOL> module_name = modname ( qualname ) <EOL> func_name = qualname [ - <NUM_LIT:1> ] <EOL> return "<STR_LIT>" % ( module_name , func_name ) <EOL> return '<STR_LIT>' <EOL> class KnowsNosePlugin ( Plugin ) : <EOL> name = '<STR_LIT>' <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . output = True <EOL> self . enableOpt = '<STR_LIT>' <EOL> self . logger = logging . getLogger ( '<STR_LIT>' ) <EOL> def options ( self , parser , env = os . environ ) : <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> type = '<STR_LIT:string>' , <EOL> dest = '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> type = '<STR_LIT:string>' , <EOL> dest = '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> type = '<STR_LIT:string>' , <EOL> action = '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> super ( KnowsNosePlugin , self ) . options ( parser , env = env ) <EOL> def configure ( self , options , config ) : <EOL> self . enabled = getattr ( options , self . enableOpt ) <EOL> if self . enabled : <EOL> self . knows = Knows ( <EOL> knows_filename = options . knows_file , <EOL> output = options . knows_out , <EOL> knows_directory = options . knows_dir , <EOL> exclude = options . knows_exclude , <EOL> ) <EOL> input_files = config . testNames <EOL> if not options . knows_out : <EOL> if input_files : <EOL> config . testNames = self . knows . get_tests_to_run ( <EOL> input_files , <EOL> ) <EOL> super ( KnowsNosePlugin , self ) . configure ( options , config ) <EOL> def begin ( self ) : <EOL> self . knows . begin ( ) <EOL> def startTest ( self , test ) : <EOL> self . knows . start_test ( parse_test_name ( repr ( test ) ) ) <EOL> def stopTest ( self , test ) : <EOL> self . knows . stop_test ( parse_test_name ( repr ( test ) ) ) <EOL> def finalize ( self , result ) : <EOL> self . knows . finalize ( ) </s>
