<s> """<STR_LIT>""" <EOL> from client import exceptions as ex <EOL> from client . sources . common import models as common_models <EOL> from client . sources . ok_test import models as ok_models <EOL> from client . sources . common import core <EOL> import textwrap <EOL> import logging <EOL> log = logging . getLogger ( __name__ ) <EOL> class ConceptSuite ( ok_models . Suite ) : <EOL> scored = core . Boolean ( default = False ) <EOL> def post_instantiation ( self ) : <EOL> for i , case in enumerate ( self . cases ) : <EOL> if not isinstance ( case , dict ) : <EOL> raise ex . SerializeException ( '<STR_LIT>' ) <EOL> self . cases [ i ] = ConceptCase ( ** case ) <EOL> def run ( self , test_name , suite_number ) : <EOL> results = { <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> } <EOL> for i , case in enumerate ( self . cases ) : <EOL> if case . locked == True or results [ '<STR_LIT>' ] > <NUM_LIT:0> : <EOL> log . info ( '<STR_LIT>' . format ( i ) ) <EOL> results [ '<STR_LIT>' ] += <NUM_LIT:1> <EOL> continue <EOL> success , output_log = self . _run_case ( test_name , suite_number , <EOL> case , i + <NUM_LIT:1> ) <EOL> assert success , '<STR_LIT>' <EOL> results [ '<STR_LIT>' ] += <NUM_LIT:1> <EOL> if self . verbose : <EOL> print ( '<STR_LIT>' . join ( output_log ) ) <EOL> return results <EOL> class ConceptCase ( common_models . Case ) : <EOL> question = core . String ( ) <EOL> answer = core . String ( ) <EOL> choices = core . List ( type = str , optional = True ) <EOL> def post_instantiation ( self ) : <EOL> self . question = textwrap . dedent ( self . question ) . strip ( ) <EOL> self . answer = textwrap . dedent ( self . answer ) . strip ( ) <EOL> if self . choices != core . NoValue : <EOL> for i , choice in enumerate ( self . choices ) : <EOL> self . choices [ i ] = textwrap . dedent ( choice ) . strip ( ) <EOL> def run ( self ) : <EOL> """<STR_LIT>""" <EOL> print ( '<STR_LIT>' + self . question ) <EOL> print ( '<STR_LIT>' + self . answer ) <EOL> return True <EOL> def lock ( self , hash_fn ) : <EOL> self . answer = hash_fn ( self . answer ) <EOL> self . locked = True <EOL> def unlock ( self , unique_id_prefix , case_id , interact ) : <EOL> """<STR_LIT>""" <EOL> print ( '<STR_LIT>' + self . question ) <EOL> answer = interact ( unique_id_prefix + '<STR_LIT:\n>' + self . question , <EOL> case_id , self . question , [ self . answer ] , self . choices ) <EOL> assert len ( answer ) == <NUM_LIT:1> <EOL> answer = answer [ <NUM_LIT:0> ] <EOL> if answer != self . answer : <EOL> self . locked = False <EOL> self . answer = answer </s>
