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)
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))
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')
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)
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')
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')