<s> import unittest <EOL> import logging <EOL> from imgfac . PluginManager import PluginManager <EOL> import tempfile <EOL> import json <EOL> import os . path <EOL> import os <EOL> import shutil <EOL> import sys <EOL> INFO1 = { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ] , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:email>" : "<STR_LIT>" , <EOL> "<STR_LIT:url>" : "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT:version>" : "<STR_LIT:1.0>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> INFO2 = { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ] , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:email>" : "<STR_LIT>" , <EOL> "<STR_LIT:url>" : "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT:version>" : "<STR_LIT:1.0>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> class testPluginManager ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , methodName = '<STR_LIT>' ) : <EOL> super ( testPluginManager , self ) . __init__ ( methodName ) <EOL> logging . basicConfig ( level = logging . NOTSET , <EOL> format = '<STR_LIT>' , <EOL> filename = '<STR_LIT>' ) <EOL> def setUp ( self ) : <EOL> self . os_info_file = tempfile . NamedTemporaryFile ( mode = '<STR_LIT:w>' , suffix = '<STR_LIT>' , prefix = '<STR_LIT>' ) <EOL> json . dump ( INFO1 , self . os_info_file ) <EOL> self . os_info_file . flush ( ) <EOL> os . fsync ( self . os_info_file ) <EOL> self . os_plugin_name = os . path . basename ( self . os_info_file . name ) . partition ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] <EOL> os . mkdir ( os . path . join ( tempfile . gettempdir ( ) , self . os_plugin_name ) , <NUM_LIT:0> <NUM_LIT> ) <EOL> osclass = open ( os . path . join ( tempfile . gettempdir ( ) , self . os_plugin_name , self . os_plugin_name + '<STR_LIT>' ) , '<STR_LIT:w>' ) <EOL> osclass . write ( '<STR_LIT>' % self . os_plugin_name ) <EOL> osclass . close ( ) <EOL> osinit = open ( os . path . join ( tempfile . gettempdir ( ) , self . os_plugin_name , '<STR_LIT>' ) , '<STR_LIT:w>' ) <EOL> osinit . write ( '<STR_LIT>' % ( self . os_plugin_name , self . os_plugin_name ) ) <EOL> osinit . close ( ) <EOL> self . cloud_info_file = tempfile . NamedTemporaryFile ( mode = '<STR_LIT:w>' , suffix = '<STR_LIT>' , prefix = '<STR_LIT>' ) <EOL> json . dump ( INFO2 , self . cloud_info_file ) <EOL> self . cloud_info_file . flush ( ) <EOL> os . fsync ( self . cloud_info_file ) <EOL> self . cloud_plugin_name = os . path . basename ( self . cloud_info_file . name ) . partition ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] <EOL> os . mkdir ( os . path . join ( tempfile . gettempdir ( ) , self . cloud_plugin_name ) , <NUM_LIT:0> <NUM_LIT> ) <EOL> cloudclass = open ( os . path . join ( tempfile . gettempdir ( ) , self . cloud_plugin_name , self . cloud_plugin_name + '<STR_LIT>' ) , '<STR_LIT:w>' ) <EOL> cloudclass . write ( '<STR_LIT>' % self . cloud_plugin_name ) <EOL> cloudclass . close ( ) <EOL> cloudinit = open ( os . path . join ( tempfile . gettempdir ( ) , self . cloud_plugin_name , '<STR_LIT>' ) , '<STR_LIT:w>' ) <EOL> cloudinit . write ( '<STR_LIT>' % ( self . cloud_plugin_name , self . cloud_plugin_name ) ) <EOL> cloudinit . close ( ) <EOL> self . plugin_mgr = PluginManager ( plugin_path = tempfile . gettempdir ( ) ) <EOL> self . plugin_mgr . load ( ) <EOL> def tearDown ( self ) : <EOL> self . plugin_mgr = None <EOL> shutil . rmtree ( path = os . path . join ( tempfile . gettempdir ( ) , self . os_plugin_name ) , ignore_errors = True ) <EOL> shutil . rmtree ( path = os . path . join ( tempfile . gettempdir ( ) , self . cloud_plugin_name ) , ignore_errors = True ) <EOL> self . os_info_file . close ( ) <EOL> self . cloud_info_file . close ( ) <EOL> def testMetadataForPlugin ( self ) : <EOL> os_metadata = self . plugin_mgr . metadata_for_plugin ( self . os_plugin_name ) <EOL> self . assertDictEqual ( os_metadata , INFO1 ) <EOL> cloud_metadata = self . plugin_mgr . metadata_for_plugin ( self . cloud_plugin_name ) <EOL> self . assertDictEqual ( cloud_metadata , INFO2 ) <EOL> @ unittest . skip ( '<STR_LIT>' ) <EOL> def testPluginForTarget ( self ) : <EOL> os_plugin = self . plugin_mgr . plugin_for_target ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( os_plugin . __class__ . __name__ , self . os_plugin_name ) <EOL> cloud_plugin = self . plugin_mgr . plugin_for_target ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( cloud_plugin . __class__ . __name__ , self . cloud_plugin_name ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
