test_flag.py (1625B)
1 # standard imports 2 import unittest 3 4 # local imports 5 from aiee.arg import ArgFlag 6 7 8 class TestAieeFlag(unittest.TestCase): 9 10 def test_basic_flag(self): 11 arg = ArgFlag() 12 arg.add('foo') 13 arg.add('bar') 14 15 self.assertEqual(arg.FOO, 1) 16 self.assertEqual(arg.BAR, 2) 17 18 self.assertEqual(arg.get('foo'), arg.FOO) 19 self.assertEqual(arg.get('bar'), arg.BAR) 20 21 arg.alias('baz', arg.FOO, arg.BAR) 22 self.assertEqual(arg.BAZ, 3) 23 24 arg.alias('barbarbar', 'foo', arg.BAR) 25 self.assertEqual(arg.BARBARBAR, 3) 26 27 self.assertTrue(arg.match('foo', arg.FOO)) 28 self.assertFalse(arg.match('foo', arg.BAR)) 29 self.assertTrue(arg.match('foo', arg.BAZ)) 30 31 with self.assertRaises(ValueError): 32 arg.add('foo') 33 34 with self.assertRaises(ValueError): 35 arg.alias('xyzzy', 5) 36 37 self.assertEqual(arg.val('foo'), arg.FOO) 38 self.assertEqual(arg.val(arg.FOO), arg.FOO) 39 self.assertEqual(arg.val(arg.BAZ), arg.BAZ) 40 with self.assertRaises(ValueError): 41 arg.val(4) 42 43 44 def test_name_set(self): 45 arg = ArgFlag() 46 arg.add('foo') 47 arg.add('bar') 48 arg.alias('baz', arg.FOO, arg.BAR) 49 50 self.assertEqual(arg.less('baz', arg.FOO), arg.BAR) 51 self.assertEqual(arg.more('foo', arg.BAR), arg.BAZ) 52 53 54 def test_name_flag(self): 55 arg = ArgFlag() 56 arg.add('foo') 57 arg.add('bar') 58 arg.alias('baz', arg.FOO, arg.BAR) 59 60 self.assertListEqual(arg.names(arg.BAZ), ['FOO', 'BAR']) 61 62 63 if __name__ == '__main__': 64 unittest.main()