<s> import re <EOL> import warnings <EOL> try : <EOL> from unittest2 import TestCase as BaseTestCase <EOL> except ImportError : <EOL> from unittest import TestCase as BaseTestCase <EOL> try : <EOL> from datadiff . tools import assert_equal as datadiff_assert_equal <EOL> except ImportError : <EOL> datadiff_assert_equal = None <EOL> try : <EOL> from nose import tools <EOL> except ImportError : <EOL> tools = type ( '<STR_LIT>' , ( object , ) , { '<STR_LIT>' : [ ] } ) <EOL> from tddspry . utils import * <EOL> __all__ = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class BaseTestCaseMetaclass ( type ) : <EOL> def __new__ ( cls , name , bases , attrs ) : <EOL> for base in bases : <EOL> for base_name in dir ( base ) : <EOL> base_value = getattr ( base , base_name ) <EOL> if not callable ( base_value ) or not base_name . startswith ( '<STR_LIT>' ) : <EOL> continue <EOL> if not base_name in attrs : <EOL> attrs . update ( { base_name : base_value } ) <EOL> for attr_name , attr_value in attrs . items ( ) : <EOL> if not attr_name . startswith ( '<STR_LIT>' ) or attr_name == '<STR_LIT>' : <EOL> continue <EOL> if attr_name [ <NUM_LIT:6> ] == '<STR_LIT:_>' : <EOL> new_name = underscore_to_camelcase ( attr_name ) <EOL> else : <EOL> new_name = camelcase_to_underscore ( attr_name ) <EOL> if not new_name in attrs : <EOL> attrs [ new_name ] = attr_value <EOL> for attr in tools . __all__ : <EOL> attrs . update ( { attr : getattr ( tools , attr ) } ) <EOL> attrs [ attr ] = staticmethod ( attrs [ attr ] ) <EOL> if datadiff_assert_equal : <EOL> key = attrs . get ( '<STR_LIT>' , False ) and '<STR_LIT>' or '<STR_LIT>' <EOL> attrs . update ( { key : datadiff_assert_equal } ) <EOL> attrs [ key ] = staticmethod ( attrs [ key ] ) <EOL> elif attrs . get ( '<STR_LIT>' , False ) : <EOL> warnings . warn ( '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' ) <EOL> return type . __new__ ( cls , name , bases , attrs ) <EOL> class TestCaseMetaclass ( BaseTestCaseMetaclass ) : <EOL> def __new__ ( cls , name , bases , attrs ) : <EOL> for attr_name , attr_value in attrs . items ( ) : <EOL> if attr_name == '<STR_LIT>' and not '<STR_LIT>' in attrs : <EOL> attrs [ '<STR_LIT>' ] = attr_value <EOL> if attr_name == '<STR_LIT>' and not '<STR_LIT>' in attrs : <EOL> attrs [ '<STR_LIT>' ] = attr_value <EOL> return super ( TestCaseMetaclass , cls ) . __new__ ( cls , name , bases , attrs ) <EOL> class TestCase ( BaseTestCase ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = TestCaseMetaclass <EOL> def assert_not_unicode ( self , first , second , message = None ) : <EOL> """<STR_LIT>""" <EOL> return self . assert_not_equal ( unicode ( first ) , unicode ( second ) , message ) <EOL> def assert_unicode ( self , first , second , message = None ) : <EOL> """<STR_LIT>""" <EOL> return self . assert_equal ( unicode ( first ) , unicode ( second ) , message ) <EOL> def find_in ( self , what , where , flags = None , count = None , escape = False , <EOL> flat = False ) : <EOL> """<STR_LIT>""" <EOL> if flat : <EOL> found = None <EOL> real_count = where . count ( what ) <EOL> else : <EOL> if escape : <EOL> what = re . escape ( what ) <EOL> regexp = re . compile ( what , process_re_flags ( flags ) ) <EOL> found = filter ( lambda matched : matched , regexp . finditer ( where ) ) <EOL> real_count = len ( found ) <EOL> if found : <EOL> setattr ( self , '<STR_LIT>' , found ) <EOL> elif not found and hasattr ( self , '<STR_LIT>' ) : <EOL> delattr ( self , '<STR_LIT>' ) <EOL> if count is not None : <EOL> assert count == real_count , '<STR_LIT>' '<STR_LIT>' % ( what , real_count , count , where ) <EOL> else : <EOL> assert real_count , '<STR_LIT>' % ( what , where ) <EOL> return True <EOL> def notfind_in ( self , what , where , flags = None , escape = False , flat = False ) : <EOL> """<STR_LIT>""" <EOL> message = '<STR_LIT>' % ( what , where ) <EOL> if not flat : <EOL> if escape : <EOL> what = re . escape ( what ) <EOL> regexp = re . compile ( what , process_re_flags ( flags ) ) <EOL> assert not regexp . search ( where ) , message <EOL> else : <EOL> assert not what in where , message <EOL> return True <EOL> NoseTestCase = TestCase </s>
