<s> import copy <EOL> from nova import objects <EOL> from nova . objects import pci_device_pool <EOL> from nova import test <EOL> from nova . tests . unit import fake_pci_device_pools as fake_pci <EOL> from nova . tests . unit . objects import test_objects <EOL> class _TestPciDevicePoolObject ( object ) : <EOL> def test_pci_pool_from_dict_not_distructive ( self ) : <EOL> test_dict = copy . copy ( fake_pci . fake_pool_dict ) <EOL> objects . PciDevicePool . from_dict ( test_dict ) <EOL> self . assertEqual ( fake_pci . fake_pool_dict , test_dict ) <EOL> def test_pci_pool_from_dict ( self ) : <EOL> pool_obj = objects . PciDevicePool . from_dict ( fake_pci . fake_pool_dict ) <EOL> self . assertEqual ( pool_obj . product_id , '<STR_LIT>' ) <EOL> self . assertEqual ( pool_obj . vendor_id , '<STR_LIT>' ) <EOL> self . assertEqual ( pool_obj . numa_node , <NUM_LIT:1> ) <EOL> self . assertEqual ( pool_obj . tags , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( pool_obj . count , <NUM_LIT:2> ) <EOL> def test_pci_pool_from_dict_bad_tags ( self ) : <EOL> bad_dict = copy . deepcopy ( fake_pci . fake_pool_dict ) <EOL> bad_dict [ '<STR_LIT>' ] = { '<STR_LIT:foo>' : '<STR_LIT:bar>' } <EOL> self . assertRaises ( ValueError , <EOL> objects . PciDevicePool . from_dict , <EOL> value = bad_dict ) <EOL> def test_pci_pool_from_dict_no_tags ( self ) : <EOL> dict_notag = copy . copy ( fake_pci . fake_pool_dict ) <EOL> dict_notag . pop ( '<STR_LIT>' ) <EOL> dict_notag . pop ( '<STR_LIT>' ) <EOL> pool_obj = objects . PciDevicePool . from_dict ( dict_notag ) <EOL> self . assertEqual ( pool_obj . tags , { } ) <EOL> def test_pci_pool_to_dict ( self ) : <EOL> tags = { '<STR_LIT>' : '<STR_LIT:foo>' , '<STR_LIT>' : '<STR_LIT:bar>' } <EOL> pool_obj = objects . PciDevicePool ( product_id = '<STR_LIT>' , tags = tags ) <EOL> pool_dict = pool_obj . to_dict ( ) <EOL> self . assertEqual ( { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT:bar>' } , pool_dict ) <EOL> def test_pci_pool_to_dict_no_tags ( self ) : <EOL> pool_obj = objects . PciDevicePool ( product_id = '<STR_LIT>' , tags = { } ) <EOL> pool_dict = pool_obj . to_dict ( ) <EOL> self . assertEqual ( { '<STR_LIT>' : '<STR_LIT>' } , pool_dict ) <EOL> def test_pci_pool_to_dict_with_tags_unset ( self ) : <EOL> pool_obj = objects . PciDevicePool ( product_id = '<STR_LIT>' ) <EOL> pool_dict = pool_obj . to_dict ( ) <EOL> self . assertEqual ( { '<STR_LIT>' : '<STR_LIT>' } , pool_dict ) <EOL> def test_obj_make_compatible ( self ) : <EOL> pool_obj = objects . PciDevicePool ( product_id = '<STR_LIT>' , numa_node = <NUM_LIT:1> ) <EOL> primitive = pool_obj . obj_to_primitive ( ) <EOL> self . assertIn ( '<STR_LIT>' , primitive [ '<STR_LIT>' ] ) <EOL> pool_obj . obj_make_compatible ( primitive [ '<STR_LIT>' ] , '<STR_LIT:1.0>' ) <EOL> self . assertNotIn ( '<STR_LIT>' , primitive [ '<STR_LIT>' ] ) <EOL> class TestPciDevicePoolObject ( test_objects . _LocalTest , <EOL> _TestPciDevicePoolObject ) : <EOL> pass <EOL> class TestRemotePciDevicePoolObject ( test_objects . _RemoteTest , <EOL> _TestPciDevicePoolObject ) : <EOL> pass <EOL> class TestConvertPciStats ( test . NoDBTestCase ) : <EOL> def test_from_pci_stats_obj ( self ) : <EOL> prim = fake_pci . fake_pool_list_primitive <EOL> pools = pci_device_pool . from_pci_stats ( prim ) <EOL> self . assertIsInstance ( pools , pci_device_pool . PciDevicePoolList ) <EOL> self . assertEqual ( len ( pools ) , <NUM_LIT:1> ) <EOL> def test_from_pci_stats_dict ( self ) : <EOL> prim = fake_pci . fake_pool_dict <EOL> pools = pci_device_pool . from_pci_stats ( prim ) <EOL> self . assertIsInstance ( pools , pci_device_pool . PciDevicePoolList ) <EOL> self . assertEqual ( len ( pools ) , <NUM_LIT:1> ) <EOL> def test_from_pci_stats_list_of_dicts ( self ) : <EOL> prim = fake_pci . fake_pool_dict <EOL> pools = pci_device_pool . from_pci_stats ( [ prim , prim ] ) <EOL> self . assertIsInstance ( pools , pci_device_pool . PciDevicePoolList ) <EOL> self . assertEqual ( len ( pools ) , <NUM_LIT:2> ) <EOL> def test_from_pci_stats_bad ( self ) : <EOL> prim = "<STR_LIT>" <EOL> pools = pci_device_pool . from_pci_stats ( prim ) <EOL> self . assertEqual ( len ( pools ) , <NUM_LIT:0> ) </s>
