'Perform tests against _format_flavor.'

def test_format_flavor(self):

    lpar_attrs = {'memory': 2048, 'name': self.san_lpar_name.return_value, 'uuid': pvm_uuid.convert_uuid_to_pvm(self.inst.uuid).upper(), 'vcpu': 1, 'srr_capability': True}
    self.inst.flavor.extra_specs = {'powervm:dedicated_proc': 'true'}
    test_attrs = dict(lpar_attrs, dedicated_proc='true')
    self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
    self.san_lpar_name.assert_called_with(self.inst.name)
    self.san_lpar_name.reset_mock()
    self.inst.flavor.extra_specs = {'powervm:dedicated_proc': 'true', 'powervm:dedicated_sharing_mode': 'share_idle_procs_active', 'powervm:min_vcpu': '1', 'powervm:max_vcpu': '3'}
    test_attrs = dict(lpar_attrs, dedicated_proc='true', sharing_mode='sre    idle    procs    active', min_vcpu='1', max_vcpu='3')
    self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
    self.san_lpar_name.assert_called_with(self.inst.name)
    self.san_lpar_name.reset_mock()
    self.inst.flavor.extra_specs = {'powervm:uncapped': 'true'}
    test_attrs = dict(lpar_attrs, sharing_mode='uncapped')
    self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
    self.san_lpar_name.assert_called_with(self.inst.name)
    self.san_lpar_name.reset_mock()
    self.inst.flavor.extra_specs = {'powervm:availability_priority': '150'}
    test_attrs = dict(lpar_attrs, avail_priority='150')
    self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
    self.san_lpar_name.assert_called_with(self.inst.name)
    self.san_lpar_name.reset_mock()
    self.inst.flavor.extra_specs = {'powervm:processor_compatibility': 'POWER8'}
    test_attrs = dict(lpar_attrs, processor_compatibility='POWER8')
    self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
    self.san_lpar_name.assert_called_with(self.inst.name)
    self.san_lpar_name.reset_mock()
    self.inst.flavor.extra_specs = {'powervm:min_proc_units': '0.5', 'powervm:max_proc_units': '2.0'}
    test_attrs = dict(lpar_attrs, min_proc_units='0.5', max_proc_units='2.0')
    self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
    self.san_lpar_name.assert_called_with(self.inst.name)
    self.san_lpar_name.reset_mock()
    self.inst.flavor.extra_specs = {'powervm:min_mem': '1024', 'powervm:max_mem': '4096'}
    test_attrs = dict(lpar_attrs, min_mem='1024', max_mem='4096')
    self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
    self.san_lpar_name.assert_called_with(self.inst.name)
    self.san_lpar_name.reset_mock()
    self.inst.flavor.extra_specs = {'powervm:srr_capability': 'false'}
    test_attrs = dict(lpar_attrs, srr_capability=False)
    self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
    self.inst.flavor.extra_specs = {'powervm:srr_capability': 'false', 'powervm:something_new': 'foo'}
    test_attrs = dict(lpar_attrs, srr_capability=False)
    self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
    with mock.patch.object(self.lpar_b, '_is_pvm_valid_key', return_value=True):
        self.inst.flavor.extra_specs = {'powervm:srr_capability': 'false', 'powervm:something_new': 'foo'}
        self.assertRaises(KeyError, self.lpar_b._format_flavor, self.inst)
