예제 #1
0
    def setUp(self):
        a = argv
        a.clear()
        a.append('decoCLI.py')
        CLI.clear()
        CLI.set_param('--name', 'name', 1)

        @CLI.set_cmd('version')
        def version(**kwargs):
            return 'Version 0.01'

        @CLI.set_cmd('printing')
        def print_name(**kwargs):
            return kwargs['name']
예제 #2
0
    def test_class_cli_api3(self):
        a = argv
        a.append('num')
        CLI.clear()

        @cli_class
        class A:
            def __init__(self):
                self.num = 3

            def num(self):
                return self.num

        result = CLI.exec()
        self.assertEqual(3, result, 'Class CLI TEST')
예제 #3
0
    def test_class_cli_api2(self):
        a = argv
        a.append('two')
        CLI.clear()

        @cli_class
        class A:
            def one(self):
                return 1

            def two(self):
                return 2

        result = CLI.exec()
        self.assertEqual(2, result, 'Class CLI TEST')
예제 #4
0
    def test_params(self):
        a = argv
        a.append('printing')
        a.append('--name')
        a.append('decoCLI')
        result = CLI.exec()

        self.assertEqual('decoCLI', result, 'Command with Param Test')
예제 #5
0
    def test_list_namespace_command1(self):
        a = argv
        a.append('get')
        a.append('one')
        get = SubCLI('get')

        @get.set_cmd('one')
        def one():
            return 1

        @get.set_cmd('two')
        def two():
            return 2

        CLI.add_sub_cli(get)
        result = CLI.exec()

        self.assertEqual(1, result, 'List Namespace command Test1')
예제 #6
0
    def test_class_cli_api4(self):
        a = argv
        a.append('add')
        a.append('num')
        CLI.clear()

        @cli_class
        class A:
            def __init__(self):
                self.num = 3

            def add(self):
                self.num += 1

            def num(self):
                return self.num

        result = CLI.exec_seq()
        self.assertEqual(4, result, 'Class CLI TEST')
예제 #7
0
    def test_no_arg_command(self):
        a = argv
        a.append('one')

        @CLI.set_cmd
        def one():
            return 1

        result = CLI.exec()

        self.assertEqual(1, result, 'No name command Test')
예제 #8
0
파일: api.py 프로젝트: HyeockJinKim/DecoCLI
def cli_class(cls):
    """
    Set CLI class
    """
    for name in cls.__dict__.keys():
        if name.startswith('_'):
            continue

        func = cls.__dict__[name]
        params = func.__code__.co_varnames
        default = None
        length = len(params)

        if length > 0:
            default = {params[0]: cls()}
            for i in range(1, length):
                CLI.set_param('--' + params[i], params[i], 1)

        CLI.set_cmd(func, default)

    return cls
예제 #9
0
    def test_class_cli_api5(self):
        a = argv
        CLI.clear()

        a.append('get')
        a.append('--n')
        a.append('2')
        a.append('num')

        @cli_class
        class A:
            def __init__(self):
                self.num = 3

            def get(self, n):
                self.num = int(n)

            def num(self):
                return self.num

        result = CLI.exec_seq()
        self.assertEqual(2, result, 'Class CLI params TEST')
예제 #10
0
    def test_class_cli(self):
        a = argv
        a.append('setup')
        a.append('--name')
        a.append('decoCLI')

        class API:
            def __init__(self, name):
                self._name = name

            @CLI.set_cmd('name')
            def name(self):
                return self._name

        @CLI.set_cmd('setup')
        def setup(**kwargs):
            print(kwargs)
            api = API(kwargs['name'])
            return api.name()

        result = CLI.exec()

        self.assertEqual('decoCLI', result, 'Class CLI Test')
예제 #11
0
    def test_exec(self):
        a = argv
        a.append('version')
        result = CLI.exec()

        self.assertEqual('Version 0.01', result, 'Exec Test')