Beispiel #1
0
  def test_log(self):
    log= Log(self.log_file)
    log_prefix= 'test_log'
    # default verbosity is ERROR
    self.assertEqual(log.log_debug(log_prefix, 'no'), False)
    self.assertEqual(log.log_info(log_prefix, 'no'), False)
    self.assertEqual(log.log_warning(log_prefix, 'no'), False)
    self.assertEqual(log.log_error(log_prefix, 'yes'), True)

    log.set_verbosity(ERROR)
    self.assertEqual(log.log_debug(log_prefix, 'no'), False)
    self.assertEqual(log.log_info(log_prefix, 'no'), False)
    self.assertEqual(log.log_warning(log_prefix, 'no'), False)
    self.assertEqual(log.log_error(log_prefix, 'yes'), True)

    log.set_verbosity(WARNING)
    self.assertEqual(log.log_debug(log_prefix, 'no'), False)
    self.assertEqual(log.log_info(log_prefix, 'no'), False)
    self.assertEqual(log.log_warning(log_prefix, 'yes'), True)
    self.assertEqual(log.log_error(log_prefix, 'yes'), True)

    log.set_verbosity(INFO)
    self.assertEqual(log.log_debug(log_prefix, 'no'), False)
    self.assertEqual(log.log_info(log_prefix, 'yes'), True)
    self.assertEqual(log.log_warning(log_prefix, 'yes'), True)
    self.assertEqual(log.log_error(log_prefix, 'yes'), True)

    log.set_verbosity(DEBUG)
    self.assertEqual(log.log_debug(log_prefix, 'yes'), True)
    self.assertEqual(log.log_info(log_prefix, 'yes'), True)
    self.assertEqual(log.log_warning(log_prefix, 'yes'), True)
    self.assertEqual(log.log_error(log_prefix, 'yes'), True)
Beispiel #2
0
  def test_config(self):
    nr_of_sections= 10
    nr_of_options= 100
    log_prefix= 'test_config'

    log= Log(self.log_file)
    log.set_verbosity(DEBUG)
    log.set_filename(self.log_file)
    new_config= Config(self.config_file, log)
    for i in range(nr_of_sections):
      for j in range(nr_of_options):
        new_config.set('section%d' % i, 'option%d' % j, 'value%d' % j)

    new_config.write()

    config= Config(self.config_file, log)
    for i in range(nr_of_sections):
      for j in range(nr_of_options):
        self.assertEqual(config.get('section%d' % i, 'option%d' % j), 'value%d' % j)