Пример #1
0
def conf_handler(key, value):
    if key == "features.connection.listingType":
        return conf.parse_enum(key, value, Listing)
    elif key == "features.connection.refreshRate":
        return max(1, value)
    elif key == "features.connection.order":
        return conf.parse_enum_csv(key, value[0], entries.SortAttr, 3)
Пример #2
0
def conf_handler(key, value):
  if key == "features.connection.listingType":
    return conf.parse_enum(key, value, Listing)
  elif key == "features.connection.refreshRate":
    return max(1, value)
  elif key == "features.connection.order":
    return conf.parse_enum_csv(key, value[0], entries.SortAttr, 3)
Пример #3
0
def conf_handler(key, value):
  if key == "features.config.selectionDetails.height":
    return max(0, value)
  elif key == "features.config.state.colWidth.option":
    return max(5, value)
  elif key == "features.config.state.colWidth.value":
    return max(5, value)
  elif key == "features.config.order":
    return conf.parse_enum_csv(key, value[0], Field, 3)
Пример #4
0
def conf_handler(key, value):
    if key == "features.config.selectionDetails.height":
        return max(0, value)
    elif key == "features.config.state.colWidth.option":
        return max(5, value)
    elif key == "features.config.state.colWidth.value":
        return max(5, value)
    elif key == "features.config.order":
        return conf.parse_enum_csv(key, value[0], Field, 3)
Пример #5
0
    def test_parse_enum_csv(self):
        """
    Tests the parse_enum_csv function.
    """

        Insects = stem.util.enum.Enum('BUTTERFLY', 'LADYBUG', 'CRICKET')

        # check the case insensitivity

        self.assertEqual([Insects.LADYBUG],
                         parse_enum_csv('my_option', 'ladybug', Insects))
        self.assertEqual([Insects.LADYBUG],
                         parse_enum_csv('my_option', 'Ladybug', Insects))
        self.assertEqual([Insects.LADYBUG],
                         parse_enum_csv('my_option', 'LaDyBuG', Insects))
        self.assertEqual([Insects.LADYBUG],
                         parse_enum_csv('my_option', 'LADYBUG', Insects))

        # various number of values

        self.assertEqual([], parse_enum_csv('my_option', '', Insects))
        self.assertEqual([Insects.LADYBUG],
                         parse_enum_csv('my_option', 'ladybug', Insects))

        self.assertEqual([Insects.LADYBUG, Insects.BUTTERFLY],
                         parse_enum_csv('my_option', 'ladybug, butterfly',
                                        Insects))

        self.assertEqual([Insects.LADYBUG, Insects.BUTTERFLY, Insects.CRICKET],
                         parse_enum_csv('my_option',
                                        'ladybug, butterfly, cricket',
                                        Insects))

        # edge cases for count argument where things are ok

        self.assertEqual([Insects.LADYBUG, Insects.BUTTERFLY],
                         parse_enum_csv('my_option', 'ladybug, butterfly',
                                        Insects, 2))

        self.assertEqual([Insects.LADYBUG, Insects.BUTTERFLY],
                         parse_enum_csv('my_option', 'ladybug, butterfly',
                                        Insects, (1, 2)))

        self.assertEqual([Insects.LADYBUG, Insects.BUTTERFLY],
                         parse_enum_csv('my_option', 'ladybug, butterfly',
                                        Insects, (2, 3)))

        self.assertEqual([Insects.LADYBUG, Insects.BUTTERFLY],
                         parse_enum_csv('my_option', 'ladybug, butterfly',
                                        Insects, (2, 2)))

        # failure cases

        self.assertRaises(ValueError, parse_enum_csv, 'my_option', 'ugabuga',
                          Insects)
        self.assertRaises(ValueError, parse_enum_csv, 'my_option',
                          'ladybug, ugabuga', Insects)
        self.assertRaises(ValueError, parse_enum_csv, 'my_option',
                          'ladybug butterfly', Insects)  # no comma
        self.assertRaises(ValueError, parse_enum_csv, 'my_option', 'ladybug',
                          Insects, 2)
        self.assertRaises(ValueError, parse_enum_csv, 'my_option', 'ladybug',
                          Insects, (2, 3))
Пример #6
0
def conf_handler(key, value):
    if key == 'connection_order':
        return conf.parse_enum_csv(key, value[0], SortAttr, 3)
Пример #7
0
def conf_handler(key, value):
    if key == 'features.config.order':
        return conf.parse_enum_csv(key, value[0], SortAttr, 3)
Пример #8
0
def conf_handler(key, value):
  if key == 'features.connection.order':
    return conf.parse_enum_csv(key, value[0], SortAttr, 3)
Пример #9
0
  def test_parse_enum_csv(self):
    """
    Tests the parse_enum_csv function.
    """

    Insects = stem.util.enum.Enum('BUTTERFLY', 'LADYBUG', 'CRICKET')

    # check the case insensitivity

    self.assertEqual([Insects.LADYBUG], parse_enum_csv('my_option', 'ladybug', Insects))
    self.assertEqual([Insects.LADYBUG], parse_enum_csv('my_option', 'Ladybug', Insects))
    self.assertEqual([Insects.LADYBUG], parse_enum_csv('my_option', 'LaDyBuG', Insects))
    self.assertEqual([Insects.LADYBUG], parse_enum_csv('my_option', 'LADYBUG', Insects))

    # various number of values

    self.assertEqual([], parse_enum_csv('my_option', '', Insects))
    self.assertEqual([Insects.LADYBUG], parse_enum_csv('my_option', 'ladybug', Insects))

    self.assertEqual(
      [Insects.LADYBUG, Insects.BUTTERFLY],
      parse_enum_csv('my_option', 'ladybug, butterfly', Insects)
    )

    self.assertEqual(
      [Insects.LADYBUG, Insects.BUTTERFLY, Insects.CRICKET],
      parse_enum_csv('my_option', 'ladybug, butterfly, cricket', Insects)
    )

    # edge cases for count argument where things are ok

    self.assertEqual(
      [Insects.LADYBUG, Insects.BUTTERFLY],
      parse_enum_csv('my_option', 'ladybug, butterfly', Insects, 2)
    )

    self.assertEqual(
      [Insects.LADYBUG, Insects.BUTTERFLY],
      parse_enum_csv('my_option', 'ladybug, butterfly', Insects, (1, 2))
    )

    self.assertEqual(
      [Insects.LADYBUG, Insects.BUTTERFLY],
      parse_enum_csv('my_option', 'ladybug, butterfly', Insects, (2, 3))
    )

    self.assertEqual(
      [Insects.LADYBUG, Insects.BUTTERFLY],
      parse_enum_csv('my_option', 'ladybug, butterfly', Insects, (2, 2))
    )

    # failure cases

    self.assertRaises(ValueError, parse_enum_csv, 'my_option', 'ugabuga', Insects)
    self.assertRaises(ValueError, parse_enum_csv, 'my_option', 'ladybug, ugabuga', Insects)
    self.assertRaises(ValueError, parse_enum_csv, 'my_option', 'ladybug butterfly', Insects)  # no comma
    self.assertRaises(ValueError, parse_enum_csv, 'my_option', 'ladybug', Insects, 2)
    self.assertRaises(ValueError, parse_enum_csv, 'my_option', 'ladybug', Insects, (2, 3))