<s> """<STR_LIT>""" <EOL> import sys <EOL> from unittest import TestCase <EOL> from ovs . extensions . storage . persistent . dummystore import DummyPersistentStore <EOL> from ovs . extensions . storage . volatile . dummystore import DummyVolatileStore <EOL> from ovs . dal . tests . mockups import FactoryModule , StorageDriver <EOL> from ovs . extensions . storage . persistentfactory import PersistentFactory <EOL> from ovs . extensions . storage . volatilefactory import VolatileFactory <EOL> from ovs . dal . helpers import HybridRunner , Descriptor <EOL> from ovs . dal . relations import RelationMapper <EOL> class Hybrid ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> """<STR_LIT>""" <EOL> sys . modules [ '<STR_LIT>' ] = FactoryModule <EOL> sys . modules [ '<STR_LIT>' ] = StorageDriver <EOL> PersistentFactory . store = DummyPersistentStore ( ) <EOL> PersistentFactory . store . clean ( ) <EOL> PersistentFactory . store . clean ( ) <EOL> VolatileFactory . store = DummyVolatileStore ( ) <EOL> VolatileFactory . store . clean ( ) <EOL> VolatileFactory . store . clean ( ) <EOL> @ classmethod <EOL> def setUp ( cls ) : <EOL> """<STR_LIT>""" <EOL> PersistentFactory . store = DummyPersistentStore ( ) <EOL> PersistentFactory . store . clean ( ) <EOL> VolatileFactory . store = DummyVolatileStore ( ) <EOL> VolatileFactory . store . clean ( ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def test_objectproperties ( self ) : <EOL> """<STR_LIT>""" <EOL> hybrid_structure = HybridRunner . get_hybrids ( ) <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> for class_descriptor in hybrid_structure . values ( ) : <EOL> cls = Descriptor ( ) . load ( class_descriptor ) . get_object ( ) <EOL> print '<STR_LIT>' . format ( cls . __name__ ) <EOL> relation_info = RelationMapper . load_foreign_relations ( cls ) <EOL> remote_properties_n = [ ] <EOL> remote_properties_1 = [ ] <EOL> if relation_info is not None : <EOL> for key , info in relation_info . iteritems ( ) : <EOL> if info [ '<STR_LIT:list>' ] is True : <EOL> remote_properties_n . append ( key ) <EOL> else : <EOL> remote_properties_1 . append ( key ) <EOL> self . assertIsInstance ( cls . _properties , list , '<STR_LIT>' . format ( cls . __name__ ) ) <EOL> self . assertIsInstance ( cls . _relations , list , '<STR_LIT>' . format ( cls . __name__ ) ) <EOL> self . assertIsInstance ( cls . _dynamics , list , '<STR_LIT>' . format ( cls . __name__ ) ) <EOL> allowed_types = [ int , float , long , str , bool , list , dict ] <EOL> for prop in cls . _properties : <EOL> is_allowed_type = prop . property_type in allowed_types or isinstance ( prop . property_type , list ) <EOL> self . assertTrue ( is_allowed_type , <EOL> '<STR_LIT>' . format ( <EOL> cls . __name__ , str ( allowed_types ) <EOL> ) ) <EOL> for dynamic in cls . _dynamics : <EOL> is_allowed_type = dynamic . return_type in allowed_types or isinstance ( dynamic . return_type , list ) <EOL> self . assertTrue ( is_allowed_type , <EOL> '<STR_LIT>' . format ( <EOL> cls . __name__ , str ( allowed_types ) <EOL> ) ) <EOL> instance = cls ( ) <EOL> for prop in cls . _properties : <EOL> self . assertEqual ( getattr ( instance , prop . name ) , prop . default , <EOL> '<STR_LIT>' ) <EOL> self . assertIsNotNone ( instance . guid ) <EOL> properties = [ ] <EOL> for item in dir ( instance ) : <EOL> if hasattr ( cls , item ) and isinstance ( getattr ( cls , item ) , property ) : <EOL> properties . append ( item ) <EOL> missing_props = [ ] <EOL> for dynamic in instance . _dynamics : <EOL> if dynamic . name not in properties : <EOL> missing_props . append ( dynamic . name ) <EOL> self . assertEqual ( len ( missing_props ) , <NUM_LIT:0> , <EOL> '<STR_LIT>' . format ( cls . __name__ , missing_props ) ) <EOL> missing_metadata = [ ] <EOL> for found_prop in properties : <EOL> found = found_prop in [ prop . name for prop in cls . _properties ] or found_prop in ( cls . _fixed_properties if hasattr ( cls , '<STR_LIT>' ) else [ ] ) or found_prop in [ relation . name for relation in cls . _relations ] or found_prop in [ '<STR_LIT>' . format ( relation . name ) for relation in cls . _relations ] or found_prop in [ dynamic . name for dynamic in cls . _dynamics ] or found_prop in remote_properties_n or found_prop in remote_properties_1 or found_prop in [ '<STR_LIT>' . format ( key ) for key in remote_properties_n ] or found_prop in [ '<STR_LIT>' . format ( key ) for key in remote_properties_1 ] or found_prop == '<STR_LIT>' <EOL> if not found : <EOL> missing_metadata . append ( found_prop ) <EOL> self . assertEqual ( len ( missing_metadata ) , <NUM_LIT:0> , <EOL> '<STR_LIT>' . format ( cls . __name__ , missing_metadata ) ) <EOL> instance . delete ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import unittest <EOL> suite = unittest . TestLoader ( ) . loadTestsFromTestCase ( Hybrid ) <EOL> result = not unittest . TextTestRunner ( verbosity = <NUM_LIT:2> ) . run ( suite ) . wasSuccessful ( ) <EOL> sys . exit ( result ) </s>
