Ejemplo n.º 1
0
    def test_b_field_priority(self):
        '''test_b_field_priority

        argv > config > get_opt default > default
        '''
        sys.argv.append('--a=3333')
        sys.argv.append('--newname=zzzz')
        sys.argv.append('--config=file://./tests/test.ini')
        opts.define('a.a', 'string', 'a.a', '1111')
        opts.define('a.b', 'string', 'a.b', '2222')
        opts.define('a.c', 'string', 'a.c', '5555')
        opts.define('a.x', 'string', 'a.x', '5555', opt_name='--newname')

        try:
            ex2 = None
            opts.define('a.z', 'string', 'a.x', '5555', opt_name='newname')
        except FeildInVaildError as ex:
            ex2 = ex

        self.assertIsInstance(ex2, FeildInVaildError, 'must except')

        opts.parse_opts('appname')
        self.assertEqual(opts.get_opt('a.a'), '3333')
        self.assertEqual(opts.get_opt('a.b'), '4444')
        self.assertEqual(opts.get_opt('a.c', '7777'), '7777')
        self.assertEqual(opts.get_opt('a.c'), '5555')
        self.assertEqual(opts.get_opt('a.x'), 'zzzz')
Ejemplo n.º 2
0
 def test_a_same_fields(self):
     opts.define('a.a', 'string', 'a.a', '1111')
     try:
         ex2 = None
         opts.define('c.a', 'int', 'a.b', 2222)
     except FeildInVaildError as ex:
         ex2 = ex
     self.assertIsInstance(ex2, FeildInVaildError, 'must except')
Ejemplo n.º 3
0
    def test_c_field_typecheck2(self):
        sys.argv.append('--config=file://./tests/test.ini')
        ex2 = None
        opts.define('a.f', 'string', 'a.f', '55', maxlen=3)
        try:
            opts.parse_opts('appname')
        except FeildInVaildError as ex:
            ex2 = ex

        self.assertIsInstance(ex2, FeildInVaildError, 'must except')
Ejemplo n.º 4
0
def main():
    opts.define('{pname}.cc', 'string', 'a', '1111', help_desc='a desc')
    opts.define('a.a', 'string', 'a', '1111', help_desc='a desc')
    opts.define('a.b', 'int', 'b', 2222, help_desc='b desc')
    opts.define('a.c', 'int', 'c', 2222, help_desc='c desc')
    opts.define('d.f', 'int', 'f', 3333, help_desc='f desc')
    opts.parse_opts('appname')
    assert opts.get_opt('{pname}.cc') == '456456'
    assert opts.get_opt('a.a') == '1111'
    assert opts.get_opt('a.b') == 2222
    assert opts.get_opt('a.c') == 9
    assert opts.get_opt('d.f') == 22222222
Ejemplo n.º 5
0
 def test_a_default_value(self):
     opts.define('a.a', 'string', 'a.a', '1111')
     opts.define('a.b', 'int', 'a.b', 2222)
     opts.parse_opts('appname')
     self.assertEqual(opts.get_opt('a.a'), '1111')
     self.assertEqual(opts.get_opt('a.b'), 2222)