示例#1
0
  def test_inherit(self):
    parent_settings = settings_factory.SettingsFactory().GetSettings(
        'global', 'global')
    label_settings = settings_factory.SettingsFactory().GetSettings(
        'label', 'label')
    self.assertEqual(parent_settings.GetField('chromeos_root'), '')
    self.assertEqual(label_settings.GetField('chromeos_root'), '')
    self.assertIsNone(label_settings.parent)

    parent_settings.SetField('chromeos_root', '/tmp/chromeos')
    label_settings.SetParentSettings(parent_settings)
    self.assertEqual(parent_settings.GetField('chromeos_root'), '/tmp/chromeos')
    self.assertEqual(label_settings.GetField('chromeos_root'), '')
    label_settings.Inherit()
    self.assertEqual(label_settings.GetField('chromeos_root'), '/tmp/chromeos')
  def test_get_settings(self):
    self.assertRaises(Exception, settings_factory.SettingsFactory.GetSettings,
                      'global', 'bad_type')

    l_settings = settings_factory.SettingsFactory().GetSettings(
        'label', 'label')
    self.assertIsInstance(l_settings, settings_factory.LabelSettings)
    self.assertEqual(len(l_settings.fields), 9)

    b_settings = settings_factory.SettingsFactory().GetSettings(
        'benchmark', 'benchmark')
    self.assertIsInstance(b_settings, settings_factory.BenchmarkSettings)
    self.assertEqual(len(b_settings.fields), 6)

    g_settings = settings_factory.SettingsFactory().GetSettings(
        'global', 'global')
    self.assertIsInstance(g_settings, settings_factory.GlobalSettings)
    self.assertEqual(len(g_settings.fields), 25)
    def test_override(self):
        self.settings.AddField(
            ListField('email',
                      default=[],
                      description='Space-seperated'
                      'list of email addresses to send '
                      'email to.'))

        global_settings = settings_factory.SettingsFactory().GetSettings(
            'global', 'global')

        global_settings.SetField('email', '*****@*****.**', append=True)
        global_settings.SetField('email', '*****@*****.**', append=True)

        res = self.settings.GetField('email')
        self.assertEqual(res, [])

        self.settings.Override(global_settings)
        res = self.settings.GetField('email')
        self.assertEqual(res, ['*****@*****.**', '*****@*****.**'])