def setUp(self):
     '''Call before test case.'''
     self.option_ats = ATSOptionParser('1.0.0', 'xyz', 'abc')
     self.option_ats.add_operation(ATSOptionTestCase.OPS[0],
                                   ATSOptionTestCase.OPS[1],
                                   dest='gen',
                                   help='simple operation')
     self.option_ats.add_operation(
         ATSOptionTestCase.OPS[2],
         ATSOptionTestCase.OPS[3],
         action='store_true',
         default=False,
         help='activate verbose mode for generation')
Example #2
0
    def __init__(self, informations_file, verbose=False):
        '''
            Initial constructor.

            :param informations_file: informations file path.
            :type informations_file: <str>
            :param verbose: enable/disable verbose option.
            :type verbose: <bool>
            :exceptions: ATSTypeError | ATSBadCallError
        '''
        checker, error, status = ATSChecker(), None, False
        error, status = checker.check_params([('str:informations_file',
                                               informations_file)])
        if status == ATSChecker.TYPE_ERROR:
            raise ATSTypeError(error)
        if status == ATSChecker.VALUE_ERROR:
            raise ATSBadCallError(error)
        self.__verbose = verbose
        informations = None
        self.tool_operational = False
        self.yaml2obj = Yaml2Object(informations_file, verbose=verbose)
        self.obj2yaml = Object2Yaml(informations_file, verbose=verbose)
        if all([self.yaml2obj, self.obj2yaml]):
            informations = self.yaml2obj.read_configuration(verbose=verbose)
        if informations:
            info = ATSInfo(informations, verbose=verbose)
            if info.ats_info_ok:
                self.option_parser = ATSOptionParser('{0} {1}'.format(
                    info.name, info.build_date),
                                                     info.version,
                                                     info.licence,
                                                     verbose=verbose)
                self.tool_operational = True
                verbose_message(YamlBase.VERBOSE, verbose,
                                'loaded ATS YAML base info')
class ATSOptionTestCase(unittest.TestCase):
    '''
        Defined class ATSOptionTestCase with attribute(s) and method(s).
        Created test cases for checking functionalities of option parser.
        It defines:

            :attributes:
                | OPS - defined options.
                | option_ats - API for option parser.
            :methods:
                | setUp - call before test case.
                | tearDown - call after test case.
                | test_option_parser_short - test short.
                | test_option_parser_long - test long.
                | test_option_parser_with_verbose_short - test verbose short.
                | test_option_parser_with_verbose_long - test verbose long.
                | test_option_parser_all_short - test all short.
                | test_option_parser_all_long - test all long.
    '''

    OPS = ['-g', '--gen', '-vv', '--verbose']

    def setUp(self):
        '''Call before test case.'''
        self.option_ats = ATSOptionParser('1.0.0', 'xyz', 'abc')
        self.option_ats.add_operation(ATSOptionTestCase.OPS[0],
                                      ATSOptionTestCase.OPS[1],
                                      dest='gen',
                                      help='simple operation')
        self.option_ats.add_operation(
            ATSOptionTestCase.OPS[2],
            ATSOptionTestCase.OPS[3],
            action='store_true',
            default=False,
            help='activate verbose mode for generation')

    def tearDown(self):
        '''Call after test case.'''
        self.option_ats = None

    def test_option_parser_short(self):
        '''Test option parser short.'''
        arguments = ['-g', 'Test']
        args = self.option_ats.parse_args(arguments)

    def test_option_parser_long(self):
        '''Test option parser long.'''
        arguments = ['--gen', 'Test']
        args = self.option_ats.parse_args(arguments)

    def test_option_parser_with_verbose_short(self):
        '''Test option parser with verbose short.'''
        arguments = ['-vv']
        args = self.option_ats.parse_args(arguments)

    def test_option_parser_with_verbose_long(self):
        '''Test option parser with verbose long.'''
        arguments = ['--verbose']
        args = self.option_ats.parse_args(arguments)

    def test_option_parser_all_short(self):
        '''Test all combined short options.'''
        arguments = ['-g', 'Test', '-vv']
        args = self.option_ats.parse_args(arguments)

    def test_option_parser_all_long(self):
        '''Test all combined long options.'''
        arguments = ['--gen', 'Test', '--verbose']
        args = self.option_ats.parse_args(arguments)