示例#1
0
    def test_typed(self):
        my_option = options.option('my_option', [('value', str)])
        self.assertEqual(my_option('foo').value, 'foo')
        self.assertRaises(TypeError, my_option, 1)

        my_option = options.option('my_option', [('value', (str, int))])
        self.assertEqual(my_option('foo').value, 'foo')
        self.assertEqual(my_option(1).value, 1)
        self.assertRaises(TypeError, my_option, 1.2)
示例#2
0
    def test_matches(self):
        my_option = options.option('my_option', ['value'])
        o1 = my_option('foo')
        o2 = my_option('foo')
        o3 = my_option('bar')

        self.assertTrue(o1.matches(o2))
        self.assertFalse(o1.matches(o3))
示例#3
0
    def test_enum(self):
        Value = options.OptionEnum('Value', ['foo', 'bar'])
        my_option = options.option('my_option', [('value', Value)])

        self.assertEqual(my_option(Value.foo).value, Value.foo)
        self.assertEqual(my_option('foo').value, Value.foo)
        self.assertRaises(TypeError, my_option, 1)
        self.assertRaises(ValueError, my_option, 'unknown')
示例#4
0
    def test_eq(self):
        my_option = options.option('my_option', ['value'])
        o1 = my_option('foo')
        o2 = my_option('foo')
        o3 = my_option('bar')

        self.assertTrue(o1 == o2)
        self.assertFalse(o1 != o2)
        self.assertFalse(o1 == o3)
        self.assertTrue(o1 != o3)
示例#5
0
    def test_create(self):
        my_option = options.option('my_option', ['value'])

        o = my_option('foo')
        self.assertEqual(type(o), my_option)
        self.assertEqual(o.value, 'foo')

        o = my_option(value='foo')
        self.assertEqual(type(o), my_option)
        self.assertEqual(o.value, 'foo')
示例#6
0
    def test_multiple_values(self):
        my_option = options.option('my_option', ['name', 'value'])

        o = my_option('foo', 'bar')
        self.assertEqual(type(o), my_option)
        self.assertEqual(o.name, 'foo')
        self.assertEqual(o.value, 'bar')

        o = my_option(name='foo', value='bar')
        self.assertEqual(type(o), my_option)
        self.assertEqual(o.name, 'foo')
        self.assertEqual(o.value, 'bar')