third_party/blink/web_tests/wpt_internal/bluetooth/generate.py
def GetGeneratedTests():
    """Yields a GeneratedTest for each call in templates in script-tests."""
    bluetooth_tests_dir = os.path.dirname(os.path.realpath(__file__))

    # Read Base Test Template.
    base_template_file_handle = open(
        os.path.join(bluetooth_tests_dir, TEMPLATES_DIR,
                     'base_test.html.template'))
    base_template_file_data = base_template_file_handle.read().decode('utf-8')
    base_template_file_handle.close()

    # Get Templates.

    template_path = os.path.join(bluetooth_tests_dir, TEMPLATES_DIR)

    available_templates = []
    for root, _, files in os.walk(template_path):
        for template in files:
            if template.endswith('.js'):
                available_templates.append(os.path.join(root, template))

    # Generate Test Files
    for template in available_templates:
        # Read template
        template_file_handle = open(template)
        template_file_data = template_file_handle.read().decode('utf-8')
        template_file_handle.close()

        template_name = os.path.splitext(os.path.basename(template))[0]

        # Find function names in multiline pattern: CALLS( [ function_name,function_name2[UUID] ])
        result = re.search(
            r'CALLS\(' +  # CALLS(
            r'[^\[]*' +  # Any characters not [, allowing for new lines.
            r'\[' +  # [
            r'(.*?)' +  # group matching: function_name(), function_name2[UUID]
            r'\]\)',  # adjacent closing characters: ])
            template_file_data,
            re.MULTILINE | re.DOTALL)

        if result is None:
            raise Exception('Template must contain \'CALLS\' tokens')

        new_test_file_data = base_template_file_data.replace(
            'TEST', template_file_data)
        # Replace CALLS([...]) with CALLS so that we don't have to replace the
        # CALLS([...]) for every new test file.
        new_test_file_data = new_test_file_data.replace(
            result.group(), 'CALLS')

        # Replace 'PREVIOUS_CALL' with 'CALLS' so that we can replace it while
        # replacing CALLS.
        new_test_file_data = new_test_file_data.replace(
            'PREVIOUS_CALL', 'CALLS')

        for call in result.group(1).split('|'):
            # Parse call
            call = call.strip()
            function_name, args, uuid_suffix = re.search(
                r'(.*?)\((.*)\)(\[UUID\])?', call).groups()

            # Replace template tokens
            call_test_file_data = new_test_file_data
            call_test_file_data = call_test_file_data.replace(
                'CALLS', '{}({})'.format(function_name, args))
            call_test_file_data = call_test_file_data.replace(
                'FUNCTION_NAME', function_name)

            # Get test file name
            group_dir = os.path.basename(
                os.path.abspath(os.path.join(template, os.pardir)))

            call_test_file_name = 'gen-{}{}.https.html'.format(
                template_name, '-with-uuid' if uuid_suffix else '')
            call_test_file_path = os.path.join(bluetooth_tests_dir, group_dir,
                                               function_name,
                                               call_test_file_name)

            yield GeneratedTest(call_test_file_data, call_test_file_path,
                                template)
Yields a GeneratedTest for each call in templates in script-tests.
Yields a GeneratedTest for each call in templates in script-tests.
Yields a GeneratedTest for each call in templates in script - tests .
def GetGeneratedTests():
    bluetooth_tests_dir = os.path.dirname(os.path.realpath(__file__))
    base_template_file_handle = open(
        os.path.join(bluetooth_tests_dir, TEMPLATES_DIR,
                     'base_test.html.template'))
    base_template_file_data = base_template_file_handle.read().decode('utf-8')
    base_template_file_handle.close()
    template_path = os.path.join(bluetooth_tests_dir, TEMPLATES_DIR)
    available_templates = []
    for root, _, files in os.walk(template_path):
        for template in files:
            if template.endswith('.js'):
                available_templates.append(os.path.join(root, template))
    for template in available_templates:
        template_file_handle = open(template)
        template_file_data = template_file_handle.read().decode('utf-8')
        template_file_handle.close()
        template_name = os.path.splitext(os.path.basename(template))[0]
        result = re.search(
            r'CALLS\(' +  
            r'[^\[]*' +  
            r'\[' +  
            r'(.*?)' +  
            r'\]\)',  
            template_file_data,
            re.MULTILINE | re.DOTALL)
        if result is None:
            raise Exception('Template must contain \'CALLS\' tokens')
        new_test_file_data = base_template_file_data.replace(
            'TEST', template_file_data)
        [...]) for every new test file.
        new_test_file_data = new_test_file_data.replace(
            result.group(), 'CALLS')
        new_test_file_data = new_test_file_data.replace(
            'PREVIOUS_CALL', 'CALLS')
        for call in result.group(1).split('|'):
            call = call.strip()
            function_name, args, uuid_suffix = re.search(
                r'(.*?)\((.*)\)(\[UUID\])?', call).groups()
            call_test_file_data = new_test_file_data
            call_test_file_data = call_test_file_data.replace(
                'CALLS', '{}({})'.format(function_name, args))
            call_test_file_data = call_test_file_data.replace(
                'FUNCTION_NAME', function_name)
            group_dir = os.path.basename(
                os.path.abspath(os.path.join(template, os.pardir)))
            call_test_file_name = 'gen-{}{}.https.html'.format(
                template_name, '-with-uuid' if uuid_suffix else '')
            call_test_file_path = os.path.join(bluetooth_tests_dir, group_dir,
                                               function_name,
                                               call_test_file_name)
            yield GeneratedTest(call_test_file_data, call_test_file_path,
                                template)
def GetGeneratedTests ( ) : bluetooth_tests_dir = os . path . dirname ( os . path . realpath ( __file__ ) ) base_template_file_handle = open ( os . path . join ( bluetooth_tests_dir , TEMPLATES_DIR , 'base_test.html.template' ) ) base_template_file_data = base_template_file_handle . read ( ) . decode ( 'utf-8' ) base_template_file_handle . close ( ) template_path = os . path . join ( bluetooth_tests_dir , TEMPLATES_DIR ) available_templates = [ ] for root , _ , files in os . walk ( template_path ) : for template in files : if template . endswith ( '.js' ) : available_templates . append ( os . path . join ( root , template ) ) for template in available_templates : template_file_handle = open ( template ) template_file_data = template_file_handle . read ( ) . decode ( 'utf-8' ) template_file_handle . close ( ) template_name = os . path . splitext ( os . path . basename ( template ) ) [ 0 ] result = re . search ( r'CALLS\(' + r'[^\[]*' + r'\[' + r'(.*?)' + r'\]\)' , template_file_data , re . MULTILINE | re . DOTALL ) if result is None : raise Exception ( 'Template must contain \'CALLS\' tokens' ) new_test_file_data = base_template_file_data . replace ( 'TEST' , template_file_data ) new_test_file_data = new_test_file_data . replace ( result . group ( ) , 'CALLS' ) new_test_file_data = new_test_file_data . replace ( 'PREVIOUS_CALL' , 'CALLS' ) for call in result . group ( 1 ) . split ( '|' ) : call = call . strip ( ) function_name , args , uuid_suffix = re . search ( r'(.*?)\((.*)\)(\[UUID\])?' , call ) . groups ( ) call_test_file_data = new_test_file_data call_test_file_data = call_test_file_data . replace ( 'CALLS' , '{}({})' . format ( function_name , args ) ) call_test_file_data = call_test_file_data . replace ( 'FUNCTION_NAME' , function_name ) group_dir = os . path . basename ( os . path . abspath ( os . path . join ( template , os . pardir ) ) ) call_test_file_name = 'gen-{}{}.https.html' . format ( template_name , '-with-uuid' if uuid_suffix else '' ) call_test_file_path = os . path . join ( bluetooth_tests_dir , group_dir , function_name , call_test_file_name ) yield GeneratedTest ( call_test_file_data , call_test_file_path , template )
Yields a GeneratedTest for each call in templates in script-tests.
Yields a GeneratedTest for each call in templates in script - tests .
"""Yields a GeneratedTest for each call in templates in script-tests.""" # Read Base Test Template. # Get Templates. # Generate Test Files # Read template # Find function names in multiline pattern: CALLS( [ function_name,function_name2[UUID] ]) # CALLS( # Any characters not [, allowing for new lines. # [ # group matching: function_name(), function_name2[UUID] # adjacent closing characters: ]) # Replace CALLS([...]) with CALLS so that we don't have to replace the # CALLS([...]) for every new test file. # Replace 'PREVIOUS_CALL' with 'CALLS' so that we can replace it while # replacing CALLS. # Parse call # Replace template tokens # Get test file name