def testWithParserLib(test_file, test_case, pre_edit_file, post_edit_file,
                      after_roundtrip_file, swiftsyntax_lit_test_helper):
    # =========================================================================
    # First generate the pre-edit and post-edit Swift file and gather the edits
    # and expected reparse regions. This is the parser for the special edit
    # markup for testing incremental parsing
    # =========================================================================

    # Gather command line arguments for swift-syntax-test specifiying the
    # performed edits in this list
    incremental_edit_args = []
    reparse_args = []
    try:
        prepareForIncrParse(test_file=test_file, test_case=test_case,
                            pre_edit_file=pre_edit_file,
                            post_edit_file=post_edit_file,
                            incremental_edit_args=incremental_edit_args,
                            reparse_args=reparse_args)
    except TestFailedError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file),
              file=sys.stderr)
        print(e.message, file=sys.stderr)
        sys.exit(1)

    try:
        run_command([swiftsyntax_lit_test_helper, '-parse-incremental'] +
                    ['-old-source-file', pre_edit_file] +
                    ['-source-file', post_edit_file] +
                    incremental_edit_args + reparse_args +
                    ['-out', after_roundtrip_file])
    except subprocess.CalledProcessError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file),
              file=sys.stderr)
        print('Parsing the swift file failed:\n', file=sys.stderr)
        print(e.output, file=sys.stderr)
        sys.exit(1)

    # Check if the two syntax trees are the same
    try:
        run_command(
            [
                'diff', '-u',
                post_edit_file,
                after_roundtrip_file
            ])
    except subprocess.CalledProcessError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file),
              file=sys.stderr)
        print('Source file after incrementally parsing '
              'does not match post-edit source file:\n\n',
              file=sys.stderr)
        print(e.output, file=sys.stderr)
        sys.exit(1)
Beispiel #2
0
def testWithParserLib(test_file, test_case, pre_edit_file, post_edit_file,
                      after_roundtrip_file, swiftsyntax_lit_test_helper):
    # =========================================================================
    # First generate the pre-edit and post-edit Swift file and gather the edits
    # and expected reparse regions. This is the parser for the special edit
    # markup for testing incremental parsing
    # =========================================================================

    # Gather command line arguments for swift-syntax-test specifiying the
    # performed edits in this list
    incremental_edit_args = []
    reparse_args = []
    try:
        prepareForIncrParse(test_file=test_file, test_case=test_case,
                            pre_edit_file=pre_edit_file,
                            post_edit_file=post_edit_file,
                            incremental_edit_args=incremental_edit_args,
                            reparse_args=reparse_args)
    except TestFailedError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file),
              file=sys.stderr)
        print(e.message, file=sys.stderr)
        sys.exit(1)

    try:
        run_command([swiftsyntax_lit_test_helper, '-parse-incremental'] +
                    ['-old-source-file', pre_edit_file] +
                    ['-source-file', post_edit_file] +
                    incremental_edit_args + reparse_args +
                    ['-out', after_roundtrip_file])
    except subprocess.CalledProcessError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file),
              file=sys.stderr)
        print('Parsing the swift file failed:\n', file=sys.stderr)
        print(e.output, file=sys.stderr)
        sys.exit(1)

    # Check if the two syntax trees are the same
    try:
        run_command(
            [
                'diff', '-u',
                post_edit_file,
                after_roundtrip_file
            ])
    except subprocess.CalledProcessError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file),
              file=sys.stderr)
        print('Source file after incrementally parsing '
              'does not match post-edit source file:\n\n',
              file=sys.stderr)
        print(e.output, file=sys.stderr)
        sys.exit(1)
    def _create_sample_worksheet(self):
        # Write out the contents to a temporary file
        with open(SampleWorksheet._FILE_NAME, 'w') as file:
            file.write('\n'.join(self._content))

        # Create the main worksheet used for stress testing the frontend
        title = '{} Worksheet'.format(self._description[0].upper() + self._description[1:])
        self._create_tagged_worksheet(self._worksheet_name, title)

        # Replace the content of the current worksheet with the temporary file's content. Delete the temp file after.
        run_command([self._cl, 'wedit', '--file=' + SampleWorksheet._FILE_NAME])
        os.remove(SampleWorksheet._FILE_NAME)
        print('Deleted file {}.'.format(SampleWorksheet._FILE_NAME))
Beispiel #4
0
def test_issue_98(venv):
    # Start the process and wait for its output
    custom_test_loader = os.path.join(get_teamcity_messages_root(), 'tests',
                                      'guinea-pigs', 'nose', 'issue_98',
                                      'custom_test_loader.py')
    command = os.path.join(venv.bin, 'python') + " " + custom_test_loader
    output = run_command(command)

    test_name = 'simple_tests.SimpleTests.test_two'
    assert_service_messages(
        output, [
            ServiceMessage('testStarted', {
                'name': test_name,
                'flowId': test_name
            }),
            ServiceMessage(
                'testIgnored', {
                    'name': test_name,
                    'message': 'Skipped: Skipping',
                    'flowId': test_name
                }),
            ServiceMessage('testFinished', {
                'name': test_name,
                'flowId': test_name
            }),
        ],
        actual_messages_predicate=lambda ms: ms.name != "testCount")
Beispiel #5
0
def run(venv, file_name, test=None, options='', set_tc_version=True):
    if test is not None:
        test_suffix = "::" + test
    else:
        test_suffix = ""

    command = os.path.join(venv.bin, 'py.test') + " " + options + " " + \
        os.path.join('tests', 'guinea-pigs', 'pytest', file_name) + test_suffix
    return run_command(command, set_tc_version=set_tc_version)
Beispiel #6
0
def run(venv, options="", arguments="", lang_dir="eng"):
    cwd = os.path.join(get_teamcity_messages_root(), "tests", "guinea-pigs",
                       "behave", lang_dir)
    behave = " ".join([
        os.path.join(venv.bin, "python"),
        os.path.join(os.path.dirname(cwd), "_behave_runner.py"), options,
        arguments
    ])
    return run_command(behave, cwd=cwd)
def run(venv, file_names, test=None, options='', set_tc_version=True):
    if test is not None:
        test_suffix = "::" + test
    else:
        test_suffix = ""

    if not isinstance(file_names, list):
        file_names = [file_names]

    command = os.path.join(venv.bin, 'py.test') + " " + options + " "
    command += ' '.join(os.path.join('tests', 'guinea-pigs', 'pytest', file_name) + test_suffix
                        for file_name in file_names)
    return run_command(command, set_tc_version=set_tc_version)
Beispiel #8
0
def run(venv, filename):
    """Execute PyLint with the TeamCityReporter.

    :param VirtualEnvDescription venv: virtual environment to run the test in
    :param filename: filename to inspect
    :rtype: str
    :return: captured STDOUT
    """
    command = ' '.join([
        os.path.join(venv.bin, 'pylint'), '--output-format',
        'teamcity.pylint_reporter.TeamCityReporter', filename
    ])

    return run_command(command)
Beispiel #9
0
def run(venv, file_names, test=None, options='', set_tc_version=True):
    if test is not None:
        test_suffix = "::" + test
    else:
        test_suffix = ""

    if not isinstance(file_names, list):
        file_names = [file_names]

    command = os.path.join(venv.bin, 'py.test') + " " + options + " "
    command += ' '.join(
        os.path.join('tests', 'guinea-pigs', 'pytest', file_name) + test_suffix
        for file_name in file_names)
    return run_command(command, set_tc_version=set_tc_version)
    def _create_dependencies(self):
        if self._preview_mode:
            # When in preview mode, search for existing bundles and worksheets instead of creating new ones
            random_worksheets = run_command(
                [self._cl, 'wsearch', '.limit=%d' % self._entities_count, '--uuid-only']
            ).split('\n')
            self._valid_worksheets = random_worksheets
            self._private_worksheets = random_worksheets
            random_bundles = run_command(
                [
                    self._cl,
                    'search',
                    'state=ready',
                    '.limit=%d' % self._entities_count,
                    '--uuid-only',
                ]
            ).split('\n')
            self._valid_bundles = random_bundles
            self._private_bundles = random_bundles
            return

        self._valid_worksheets = []
        self._private_worksheets = []
        self._valid_bundles = []
        self._private_bundles = []
        for _ in range(self._entities_count):
            # Create valid worksheets with a bundle each for the sample worksheet to reference
            id = self._random_id()
            name = 'valid_worksheet_%s' % id
            title = 'Other Worksheet %s' % id
            self._valid_worksheets.append(self._create_tagged_worksheet(name, title))
            self._valid_bundles.append(
                run_command(
                    [self._cl, 'run', 'echo codalab rules!', '--tags=%s' % SampleWorksheet.TAG]
                )
            )
            # Create a valid private worksheet and a bundle each
            name = 'valid_private_worksheet_%s' % id
            title = 'Other Private Worksheet %s' % id
            uuid = self._create_tagged_worksheet(name, title)
            run_command([self._cl, 'wperm', uuid, 'public', 'none'])
            self._private_worksheets.append(uuid)
            uuid = run_command(
                [self._cl, 'run', 'echo private run', '--tags=%s' % SampleWorksheet.TAG]
            )
            run_command([self._cl, 'perm', uuid, 'public', 'none'])
            self._private_bundles.append(uuid)
Beispiel #11
0
def run(venv, file, clazz=None, test=None, print_output=True, options=""):
    if clazz:
        clazz_arg = ":" + clazz
    else:
        clazz_arg = ""

    if test:
        test_arg = "." + test
    else:
        test_arg = ""

    command = os.path.join(venv.bin, 'nosetests') + \
        " -v " + options + " " + \
        os.path.join('tests', 'guinea-pigs', 'nose', file) + clazz_arg + test_arg
    return run_command(command, print_output=print_output)
    def _search_bundles(self, query):
        if self._preview_mode:
            # When in preview mode, just return the cached UUIDs of valid bundles instead of performing a new search
            return self._valid_bundles

        return run_command(
            [
                self._cl,
                'search',
                query,
                '.limit=%d' % self._entities_count,
                'created=.sort-',
                '--uuid-only',
            ]
        ).split('\n')
def run(venv, file, clazz=None, test=None, print_output=True, options=""):
    if clazz:
        clazz_arg = ":" + clazz
    else:
        clazz_arg = ""

    if test:
        test_arg = "." + test
    else:
        test_arg = ""

    command = os.path.join(venv.bin, 'nosetests') + \
        " -v " + options + " " + \
        os.path.join('tests', 'guinea-pigs', 'nose', file) + clazz_arg + test_arg
    return run_command(command, print_output=print_output)
def test_issue_98(venv):
    # Start the process and wait for its output
    custom_test_loader = os.path.join(get_teamcity_messages_root(), 'tests', 'guinea-pigs', 'nose', 'issue_98', 'custom_test_loader.py')
    command = os.path.join(venv.bin, 'python') + " " + custom_test_loader
    output = run_command(command)

    test_name = 'simple_tests.SimpleTests.test_two'
    assert_service_messages(
        output,
        [
            ServiceMessage('testStarted', {'name': test_name, 'flowId': test_name}),
            ServiceMessage('testIgnored', {'name': test_name, 'message': 'Skipped: Skipping', 'flowId': test_name}),
            ServiceMessage('testFinished', {'name': test_name, 'flowId': test_name}),
        ],
        actual_messages_predicate=lambda ms: ms.name != "testCount"
    )
Beispiel #15
0
def run(venv, file, clazz=None, test=None, print_output=True, options=""):
    if sys.version_info > (3, 8):
        pytest.skip("nose is outdated and doesn't support 3.8")
    if clazz:
        clazz_arg = ":" + clazz
    else:
        clazz_arg = ""

    if test:
        test_arg = "." + test
    else:
        test_arg = ""

    command = os.path.join(venv.bin, 'nosetests') + \
        " -v " + options + " " + \
        os.path.join('tests', 'guinea-pigs', 'nose', file) + clazz_arg + test_arg
    return run_command(command, print_output=print_output)
Beispiel #16
0
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description='Utility for testing incremental syntax tree transfer',
        epilog='''
    Based of a single template the utility generates a pre-edit and a post-edit 
    file. It then verifies that the incrementally transferred syntax tree 
    matches the syntax tree passed as --expected-incremental-syntax-tree.

    To generate the pre-edit and the post-edit file from the template, it 
    operates on markers of the form:

        <<test_case<pre|||post>>>

    These placeholders are replaced by:
      - 'pre' if a different test case than 'test_case' is run
      - 'pre' for the pre-edit version of 'test_case'
      - 'post' for the post-edit version of 'test_case'
    ''')
    parser.add_argument('file',
                        type=argparse.FileType(),
                        help='The template file to test')
    parser.add_argument(
        '--test-case',
        default='',
        help='The test case to execute. If no test case is specified all '
        'unnamed substitutions are applied')
    parser.add_argument(
        '--temp-dir',
        required=True,
        help='A temporary directory where pre-edit and post-edit files can be '
        'saved')
    parser.add_argument('--swift-syntax-test',
                        required=True,
                        help='The path to swift-syntax-test')
    parser.add_argument(
        '--expected-incremental-syntax-tree',
        required=True,
        help='The path to a file that contains the expected incrementally '
        'transferred syntax tree')

    args = parser.parse_args(sys.argv[1:])

    test_file = args.file.name
    test_file_name = os.path.basename(test_file)
    test_case = args.test_case
    temp_dir = args.temp_dir
    swift_syntax_test = args.swift_syntax_test
    expected_syntax_tree_file = args.expected_incremental_syntax_tree

    if not os.path.exists(temp_dir):
        os.makedirs(temp_dir)

    incremental_serialized_file = temp_dir + '/' + test_file_name + '.' \
        + test_case + '.incr.json'

    try:
        serializeIncrParseMarkupFile(test_file=test_file,
                                     test_case=test_case,
                                     mode='incremental',
                                     serialization_mode='incremental',
                                     omit_node_ids=False,
                                     output_file=incremental_serialized_file,
                                     temp_dir=temp_dir + '/temp',
                                     swift_syntax_test=swift_syntax_test,
                                     print_visual_reuse_info=False)
    except TestFailedError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file),
              file=sys.stderr)
        print(e.message, file=sys.stderr)
        sys.exit(1)

    # Check if the two syntax trees are the same
    try:
        run_command([
            'diff', '-u', incremental_serialized_file,
            expected_syntax_tree_file
        ])
    except subprocess.CalledProcessError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file),
              file=sys.stderr)
        print(
            'Syntax tree of incremental parsing does not match expected '
            'incrementally transfer syntax tree:\n\n',
            file=sys.stderr)
        print(e.output, file=sys.stderr)
        sys.exit(1)
 def _create_tagged_worksheet(self, name, title):
     uuid = run_command([self._cl, 'new', name])
     run_command([self._cl, 'work', name])
     run_command([self._cl, 'wedit', '--tag=%s' % SampleWorksheet.TAG, '--title=%s' % title])
     return uuid
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description='Utility for testing incremental syntax parsing',
        epilog='''
    Based of a single template the utility generates a pre-edit and a post-edit 
    file. It then verifies that incrementally parsing the post-edit file base 
    on the pre-edit file results in the same syntax tree as reparsing the 
    post-edit file from scratch.

    To generate the pre-edit and the post-edit file from the template, it 
    operates on markers of the form:

        <<test_case<pre|||post>>>

    These placeholders are replaced by:
      - 'pre' if a different test case than 'test_case' is run
      - 'pre' for the pre-edit version of 'test_case'
      - 'post' for the post-edit version of 'test_case'
    ''')
    parser.add_argument(
        'file', type=argparse.FileType(),
        help='The template file to test')
    parser.add_argument(
        '--test-case', default='',
        help='The test case to execute. If no test case is specified all \
              unnamed substitutions are applied')
    parser.add_argument(
        '--temp-dir', required=True,
        help='A temporary directory where pre-edit and post-edit files can be \
              saved')
    parser.add_argument(
        '--swift-syntax-test', required=True,
        help='The path to swift-syntax-test')
    parser.add_argument(
        '--swift-swiftsyntax-test', required=True,
        help='The path to swift-swiftsyntax-test')

    args = parser.parse_args(sys.argv[1:])

    test_file = args.file.name
    test_file_name = os.path.basename(test_file)
    test_case = args.test_case
    temp_dir = args.temp_dir
    swift_syntax_test = args.swift_syntax_test
    swift_swiftsyntax_test = args.swift_swiftsyntax_test

    if not os.path.exists(temp_dir):
        os.makedirs(temp_dir)

    pre_edit_tree_file = temp_dir + '/' + test_file_name + '.' \
        + test_case + '.pre.json'
    incremental_tree_file = temp_dir + '/' + test_file_name + '.' \
        + test_case + '.incr.json'
    post_edit_source_file = temp_dir + '/' + test_file_name + '.' \
        + test_case + '.post.swift'
    after_roundtrip_source_file = temp_dir + '/' + test_file_name + '.' \
        + test_case + '.post_after_roundtrip.swift'

    # Generate the syntax tree once incrementally and once from scratch
    try:
        serializeIncrParseMarkupFile(test_file=test_file, 
                                     test_case=test_case, 
                                     mode='pre-edit', 
                                     serialization_mode='full',
                                     omit_node_ids=False,
                                     output_file=pre_edit_tree_file, 
                                     temp_dir=temp_dir, 
                                     swift_syntax_test=swift_syntax_test, 
                                     print_visual_reuse_info=False)

        serializeIncrParseMarkupFile(test_file=test_file, 
                                     test_case=test_case, 
                                     mode='incremental', 
                                     serialization_mode='incremental',
                                     omit_node_ids=False,
                                     output_file=incremental_tree_file, 
                                     temp_dir=temp_dir, 
                                     swift_syntax_test=swift_syntax_test, 
                                     print_visual_reuse_info=False)
    except TestFailedError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file), 
              file=sys.stderr)
        print(e.message, file=sys.stderr)
        sys.exit(1)

    try:
        run_command([swift_swiftsyntax_test, '--deserialize-incremental'] + 
                    ['--pre-edit-tree', pre_edit_tree_file] +
                    ['--incr-tree', incremental_tree_file] + 
                    ['--out', after_roundtrip_source_file])
    except subprocess.CalledProcessError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file), 
              file=sys.stderr)
        print('Deserializing the swift file failed:\n', file=sys.stderr)
        print(e.output, file=sys.stderr)
        sys.exit(1)

    # Check if the two syntax trees are the same
    try:
        run_command(
            [
                'diff', '-u',
                post_edit_source_file,
                after_roundtrip_source_file
            ])
    except subprocess.CalledProcessError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file), 
              file=sys.stderr)
        print('Source file after incrementally transferring the syntax tree '
              'to swiftSyntax does not match post-edit source file:\n\n', 
              file=sys.stderr)
        print(e.output, file=sys.stderr)
        sys.exit(1)
Beispiel #19
0
def run_directly(venv, file):
    command = os.path.join(venv.bin, 'python') + " " + os.path.join(
        'tests', 'guinea-pigs', 'unittest', file)
    return run_command(command)
Beispiel #20
0
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description='Utility for testing incremental syntax parsing',
        epilog='''
    Based of a single template the utility generates a pre-edit and a post-edit 
    file. It then verifies that incrementally parsing the post-edit file base 
    on the pre-edit file results in the same syntax tree as reparsing the 
    post-edit file from scratch.

    To generate the pre-edit and the post-edit file from the template, it 
    operates on markers of the form:

        <<test_case<pre|||post>>>

    These placeholders are replaced by:
      - 'pre' if a different test case than 'test_case' is run
      - 'pre' for the pre-edit version of 'test_case'
      - 'post' for the post-edit version of 'test_case'
    ''')
    parser.add_argument(
        'file', type=argparse.FileType(),
        help='The template file to test')
    parser.add_argument(
        '--test-case', default='',
        help='The test case to execute. If no test case is specified all \
              unnamed substitutions are applied')
    parser.add_argument(
        '--temp-dir', required=True,
        help='A temporary directory where pre-edit and post-edit files can be \
              saved')
    parser.add_argument(
        '--swift-syntax-test', required=True,
        help='The path to swift-syntax-test')
    parser.add_argument(
        '--print-visual-reuse-info', default=False, action='store_true',
        help='Print visual reuse information about the incremental parse \
              instead of diffing the syntax trees. This option is intended \
              for debug purposes only.')

    args = parser.parse_args(sys.argv[1:])

    test_file = args.file.name
    test_file_name = os.path.basename(test_file)
    test_case = args.test_case
    temp_dir = args.temp_dir
    swift_syntax_test = args.swift_syntax_test
    visual_reuse_info = args.print_visual_reuse_info

    if not os.path.exists(temp_dir):
        os.makedirs(temp_dir)

    incremental_serialized_file = temp_dir + '/' + test_file_name + '.' \
        + test_case + '.postViaIncr.json'
    post_edit_serialized_file = temp_dir + '/' + test_file_name + '.' \
        + test_case + '.post.json'

    # Generate the syntax tree once incrementally and once from scratch
    try:
        serializeIncrParseMarkupFile(test_file=test_file, 
                                     test_case=test_case, 
                                     mode='incremental', 
                                     serialization_mode='full',
                                     omit_node_ids=True,
                                     output_file=incremental_serialized_file, 
                                     temp_dir=temp_dir + '/temp', 
                                     swift_syntax_test=swift_syntax_test, 
                                     print_visual_reuse_info=visual_reuse_info)
        if visual_reuse_info:
            # If we just want the reuse info, we don't need to parse the file 
            # from scratch or validate it
            sys.exit(0)

        serializeIncrParseMarkupFile(test_file=test_file, 
                                     test_case=test_case, 
                                     mode='post-edit', 
                                     serialization_mode='full',
                                     omit_node_ids=True,
                                     output_file=post_edit_serialized_file, 
                                     temp_dir=temp_dir + '/temp', 
                                     swift_syntax_test=swift_syntax_test, 
                                     print_visual_reuse_info=visual_reuse_info)
    except TestFailedError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file), 
              file=sys.stderr)
        print(e.message, file=sys.stderr)
        sys.exit(1)

    # Check if the two syntax trees are the same
    try:
        run_command(
            [
                'diff', '-u',
                incremental_serialized_file,
                post_edit_serialized_file
            ])
    except subprocess.CalledProcessError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file), 
              file=sys.stderr)
        print('Syntax tree of incremental parsing does not match '
              'from-scratch parsing of post-edit file:\n\n', file=sys.stderr)
        print(e.output, file=sys.stderr)
        sys.exit(1)
def run_directly(venv, file):
    command = os.path.join(venv.bin, 'python') + " " + os.path.join('tests', 'guinea-pigs', 'unittest', file)
    return run_command(command)
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description='Utility for testing incremental syntax parsing',
        epilog='''
    Based of a single template the utility generates a pre-edit and a post-edit
    file. It then verifies that incrementally parsing the post-edit file base
    on the pre-edit file results in the same syntax tree as reparsing the
    post-edit file from scratch.

    To generate the pre-edit and the post-edit file from the template, it
    operates on markers of the form:

        <<test_case<pre|||post>>>

    These placeholders are replaced by:
      - 'pre' if a different test case than 'test_case' is run
      - 'pre' for the pre-edit version of 'test_case'
      - 'post' for the post-edit version of 'test_case'
    ''')
    parser.add_argument(
        'file', type=argparse.FileType(),
        help='The template file to test')
    parser.add_argument(
        '--test-case', default='',
        help='The test case to execute. If no test case is specified all \
              unnamed substitutions are applied')
    parser.add_argument(
        '--temp-dir', required=True,
        help='A temporary directory where pre-edit and post-edit files can be \
              saved')
    parser.add_argument(
        '--swift-syntax-test', required=True,
        help='The path to swift-syntax-test')
    parser.add_argument(
        '--swiftsyntax-lit-test-helper', required=True,
        help='The path to the lit-test-helper binary of SwiftSyntax')
    parser.add_argument(
        '--serialization-format', choices=['json', 'byteTree'],
        default='json', help='''
    The format that shall be used to transfer the syntax tree
    ''')

    args = parser.parse_args(sys.argv[1:])

    test_file = args.file.name
    test_file_name = os.path.basename(test_file)
    test_case = args.test_case
    temp_dir = args.temp_dir
    swift_syntax_test = args.swift_syntax_test
    swiftsyntax_lit_test_helper = args.swiftsyntax_lit_test_helper
    serialization_format = args.serialization_format

    if not os.path.exists(temp_dir):
        os.makedirs(temp_dir)

    treeFileExtension = serialization_format

    pre_edit_tree_file = temp_dir + '/' + test_file_name + '.' \
        + test_case + '.pre.' + treeFileExtension
    incremental_tree_file = temp_dir + '/' + test_file_name + '.' \
        + test_case + '.incr.' + treeFileExtension
    post_edit_source_file = temp_dir + '/' + test_file_name + '.' \
        + test_case + '.post.swift'
    after_roundtrip_source_file = temp_dir + '/' + test_file_name + '.' \
        + test_case + '.post_after_roundtrip.swift'

    # Generate the syntax tree once incrementally and once from scratch
    try:
        serializeIncrParseMarkupFile(test_file=test_file,
                                     test_case=test_case,
                                     mode='pre-edit',
                                     serialization_mode='full',
                                     serialization_format=serialization_format,
                                     omit_node_ids=False,
                                     output_file=pre_edit_tree_file,
                                     temp_dir=temp_dir,
                                     swift_syntax_test=swift_syntax_test,
                                     print_visual_reuse_info=False)

        serializeIncrParseMarkupFile(test_file=test_file,
                                     test_case=test_case,
                                     mode='incremental',
                                     serialization_mode='incremental',
                                     serialization_format=serialization_format,
                                     omit_node_ids=False,
                                     output_file=incremental_tree_file,
                                     temp_dir=temp_dir,
                                     swift_syntax_test=swift_syntax_test,
                                     print_visual_reuse_info=False)
    except TestFailedError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file),
              file=sys.stderr)
        print(e.message, file=sys.stderr)
        sys.exit(1)

    try:
        run_command([swiftsyntax_lit_test_helper, '-deserialize-incremental'] +
                    ['-serialization-format', serialization_format] +
                    ['-pre-edit-tree', pre_edit_tree_file] +
                    ['-incr-tree', incremental_tree_file] +
                    ['-out', after_roundtrip_source_file])
    except subprocess.CalledProcessError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file),
              file=sys.stderr)
        print('Deserializing the swift file failed:\n', file=sys.stderr)
        print(e.output, file=sys.stderr)
        sys.exit(1)

    # Check if the two syntax trees are the same
    try:
        run_command(
            [
                'diff', '-u',
                post_edit_source_file,
                after_roundtrip_source_file
            ])
    except subprocess.CalledProcessError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file),
              file=sys.stderr)
        print('Source file after incrementally transferring the syntax tree '
              'to swiftSyntax does not match post-edit source file:\n\n',
              file=sys.stderr)
        print(e.output, file=sys.stderr)
        sys.exit(1)
Beispiel #23
0
def run(venv, project_root):
    command = os.path.join(venv.bin, 'python') + " manage.py test"
    return run_command(command, cwd=project_root)
Beispiel #24
0
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description='Utility for testing incremental syntax parsing',
        epilog='''
    Based of a single template the utility generates a pre-edit and a post-edit
    file. It then verifies that incrementally parsing the post-edit file base
    on the pre-edit file results in the same syntax tree as reparsing the
    post-edit file from scratch.

    To generate the pre-edit and the post-edit file from the template, it
    operates on markers of the form:

        <<test_case<pre|||post>>>

    These placeholders are replaced by:
      - 'pre' if a different test case than 'test_case' is run
      - 'pre' for the pre-edit version of 'test_case'
      - 'post' for the post-edit version of 'test_case'
    ''')
    parser.add_argument('file',
                        type=argparse.FileType(),
                        help='The template file to test')
    parser.add_argument(
        '--test-case',
        default='',
        help='The test case to execute. If no test case is specified all \
              unnamed substitutions are applied')
    parser.add_argument(
        '--temp-dir',
        required=True,
        help='A temporary directory where pre-edit and post-edit files can be \
              saved')
    parser.add_argument(
        '--swiftsyntax-lit-test-helper',
        required=True,
        help='The path to the lit-test-helper binary of SwiftSyntax')

    args = parser.parse_args(sys.argv[1:])

    test_file = args.file.name
    test_file_name = os.path.basename(test_file)
    test_case = args.test_case
    temp_dir = args.temp_dir
    swiftsyntax_lit_test_helper = args.swiftsyntax_lit_test_helper

    if not os.path.exists(temp_dir):
        os.makedirs(temp_dir)

    pre_edit_file = temp_dir + '/' + test_file_name + '.' + test_case + \
        '.pre.swift'
    post_edit_file = temp_dir + '/' + test_file_name + '.' + test_case + \
        '.post.swift'
    after_roundtrip_file = temp_dir + '/' + test_file_name + '.' \
        + test_case + '.post_after_roundtrip.swift'

    # =========================================================================
    # First generate the pre-edit and post-edit Swift file and gather the edits
    # and expected reparse regions. This is the parser for the special edit
    # markup for testing incremental parsing
    # =========================================================================

    # Gather command line arguments for swift-syntax-test specifiying the
    # performed edits in this list
    incremental_edit_args = []
    reparse_args = []
    try:
        prepareForIncrParse(test_file=test_file,
                            test_case=test_case,
                            pre_edit_file=pre_edit_file,
                            post_edit_file=post_edit_file,
                            incremental_edit_args=incremental_edit_args,
                            reparse_args=reparse_args)
    except TestFailedError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file),
              file=sys.stderr)
        print(e.message, file=sys.stderr)
        sys.exit(1)

    try:
        run_command([swiftsyntax_lit_test_helper, '-parse-incremental'] +
                    ['-old-source-file', pre_edit_file] +
                    ['-source-file', post_edit_file] + incremental_edit_args +
                    reparse_args + ['-out', after_roundtrip_file])
    except subprocess.CalledProcessError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file),
              file=sys.stderr)
        print('Parsing the swift file failed:\n', file=sys.stderr)
        print(e.output, file=sys.stderr)
        sys.exit(1)

    # Check if the two syntax trees are the same
    try:
        run_command(['diff', '-u', post_edit_file, after_roundtrip_file])
    except subprocess.CalledProcessError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file),
              file=sys.stderr)
        print(
            'Source file after incrementally parsing '
            'does not match post-edit source file:\n\n',
            file=sys.stderr)
        print(e.output, file=sys.stderr)
        sys.exit(1)
Beispiel #25
0
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description='Utility for testing incremental syntax tree transfer',
        epilog='''
    Based of a single template the utility generates a pre-edit and a post-edit 
    file. It then verifies that the incrementally transferred syntax tree 
    matches the syntax tree passed as --expected-incremental-syntax-tree.

    To generate the pre-edit and the post-edit file from the template, it 
    operates on markers of the form:

        <<test_case<pre|||post>>>

    These placeholders are replaced by:
      - 'pre' if a different test case than 'test_case' is run
      - 'pre' for the pre-edit version of 'test_case'
      - 'post' for the post-edit version of 'test_case'
    ''')
    parser.add_argument(
        'file', type=argparse.FileType(),
        help='The template file to test')
    parser.add_argument(
        '--test-case', default='',
        help='The test case to execute. If no test case is specified all '
             'unnamed substitutions are applied')
    parser.add_argument(
        '--temp-dir', required=True,
        help='A temporary directory where pre-edit and post-edit files can be '
             'saved')
    parser.add_argument(
        '--swift-syntax-test', required=True,
        help='The path to swift-syntax-test')
    parser.add_argument(
        '--expected-incremental-syntax-tree', required=True,
        help='The path to a file that contains the expected incrementally '
             'transferred syntax tree')

    args = parser.parse_args(sys.argv[1:])

    test_file = args.file.name
    test_file_name = os.path.basename(test_file)
    test_case = args.test_case
    temp_dir = args.temp_dir
    swift_syntax_test = args.swift_syntax_test
    expected_syntax_tree_file = args.expected_incremental_syntax_tree

    if not os.path.exists(temp_dir):
        os.makedirs(temp_dir)

    incremental_serialized_file = temp_dir + '/' + test_file_name + '.' \
        + test_case + '.incr.json'

    try:
        serializeIncrParseMarkupFile(test_file=test_file, 
                                     test_case=test_case, 
                                     mode='incremental', 
                                     serialization_mode='incremental',
                                     serialization_format='json',
                                     omit_node_ids=False,
                                     output_file=incremental_serialized_file, 
                                     temp_dir=temp_dir + '/temp', 
                                     swift_syntax_test=swift_syntax_test, 
                                     print_visual_reuse_info=False)
    except TestFailedError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file), 
              file=sys.stderr)
        print(e.message, file=sys.stderr)
        sys.exit(1)

    # Check if the two syntax trees are the same
    try:
        run_command(
            [
                'diff', '-u',
                incremental_serialized_file,
                expected_syntax_tree_file
            ])
    except subprocess.CalledProcessError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file), 
              file=sys.stderr)
        print('Syntax tree of incremental parsing does not match expected '
              'incrementally transfer syntax tree:\n\n', file=sys.stderr)
        print(e.output, file=sys.stderr)
        sys.exit(1)
def run(venv, project_root):
    command = os.path.join(venv.bin, 'python') + " manage.py test"
    return run_command(command, cwd=project_root)
def run(venv, options="", arguments="", lang_dir="eng"):
    cwd = os.path.join(get_teamcity_messages_root(), "tests", "guinea-pigs", "behave", lang_dir)
    behave = " ".join([os.path.join(venv.bin, "python"), os.path.join(os.path.dirname(cwd), "_behave_runner.py"), options, arguments])
    return run_command(behave, cwd=cwd)
Beispiel #28
0
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description='Utility for testing incremental syntax parsing',
        epilog='''
    Based of a single template the utility generates a pre-edit and a post-edit
    file. It then verifies that incrementally parsing the post-edit file base
    on the pre-edit file results in the same syntax tree as reparsing the
    post-edit file from scratch.

    To generate the pre-edit and the post-edit file from the template, it
    operates on markers of the form:

        <<test_case<pre|||post>>>

    These placeholders are replaced by:
      - 'pre' if a different test case than 'test_case' is run
      - 'pre' for the pre-edit version of 'test_case'
      - 'post' for the post-edit version of 'test_case'
    ''')
    parser.add_argument(
        'file', type=argparse.FileType(),
        help='The template file to test')
    parser.add_argument(
        '--test-case', default='',
        help='The test case to execute. If no test case is specified all \
              unnamed substitutions are applied')
    parser.add_argument(
        '--temp-dir', required=True,
        help='A temporary directory where pre-edit and post-edit files can be \
              saved')
    parser.add_argument(
        '--swift-syntax-test', required=False,
        help='The path to swift-syntax-test')
    parser.add_argument(
        '--swiftsyntax-lit-test-helper', required=True,
        help='The path to the lit-test-helper binary of SwiftSyntax')
    parser.add_argument(
        '--serialization-format', choices=['json', 'byteTree'],
        default='json', help='''
    The format that shall be used to transfer the syntax tree
    ''')

    args = parser.parse_args(sys.argv[1:])

    test_file = args.file.name
    test_file_name = os.path.basename(test_file)
    test_case = args.test_case
    temp_dir = args.temp_dir
    swift_syntax_test = args.swift_syntax_test
    swiftsyntax_lit_test_helper = args.swiftsyntax_lit_test_helper
    serialization_format = args.serialization_format

    if not os.path.exists(temp_dir):
        os.makedirs(temp_dir)

    # FIXME: This check is transitional, once SwiftSyntax starts using the
    # parser library it will become self-contained and not need
    # swift-syntax-test for its lit tests. Contents of testWithParserLib()
    # function will move here and replace what comes below.
    if not swift_syntax_test:
        pre_edit_file = temp_dir + '/' + test_file_name + '.' + test_case + \
            '.pre.swift'
        post_edit_file = temp_dir + '/' + test_file_name + '.' + test_case + \
            '.post.swift'
        after_roundtrip_file = temp_dir + '/' + test_file_name + '.' \
            + test_case + '.post_after_roundtrip.swift'
        return testWithParserLib(
            test_file=test_file,
            test_case=test_case,
            pre_edit_file=pre_edit_file,
            post_edit_file=post_edit_file,
            after_roundtrip_file=after_roundtrip_file,
            swiftsyntax_lit_test_helper=swiftsyntax_lit_test_helper)

    treeFileExtension = serialization_format

    pre_edit_tree_file = temp_dir + '/' + test_file_name + '.' \
        + test_case + '.pre.' + treeFileExtension
    incremental_tree_file = temp_dir + '/' + test_file_name + '.' \
        + test_case + '.incr.' + treeFileExtension
    post_edit_source_file = temp_dir + '/' + test_file_name + '.' \
        + test_case + '.post.swift'
    after_roundtrip_source_file = temp_dir + '/' + test_file_name + '.' \
        + test_case + '.post_after_roundtrip.swift'

    # Generate the syntax tree once incrementally and once from scratch
    try:
        serializeIncrParseMarkupFile(test_file=test_file,
                                     test_case=test_case,
                                     mode='pre-edit',
                                     serialization_mode='full',
                                     serialization_format=serialization_format,
                                     omit_node_ids=False,
                                     output_file=pre_edit_tree_file,
                                     diags_output_file=None,
                                     temp_dir=temp_dir,
                                     swift_syntax_test=swift_syntax_test,
                                     print_visual_reuse_info=False)

        serializeIncrParseMarkupFile(test_file=test_file,
                                     test_case=test_case,
                                     mode='incremental',
                                     serialization_mode='incremental',
                                     serialization_format=serialization_format,
                                     omit_node_ids=False,
                                     output_file=incremental_tree_file,
                                     diags_output_file=None,
                                     temp_dir=temp_dir,
                                     swift_syntax_test=swift_syntax_test,
                                     print_visual_reuse_info=False)
    except TestFailedError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file),
              file=sys.stderr)
        print(e.message, file=sys.stderr)
        sys.exit(1)

    try:
        run_command([swiftsyntax_lit_test_helper, '-deserialize-incremental'] +
                    ['-serialization-format', serialization_format] +
                    ['-pre-edit-tree', pre_edit_tree_file] +
                    ['-incr-tree', incremental_tree_file] +
                    ['-out', after_roundtrip_source_file])
    except subprocess.CalledProcessError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file),
              file=sys.stderr)
        print('Deserializing the swift file failed:\n', file=sys.stderr)
        print(e.output, file=sys.stderr)
        sys.exit(1)

    # Check if the two syntax trees are the same
    try:
        run_command(
            [
                'diff', '-u',
                post_edit_source_file,
                after_roundtrip_source_file
            ])
    except subprocess.CalledProcessError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file),
              file=sys.stderr)
        print('Source file after incrementally transferring the syntax tree '
              'to swiftSyntax does not match post-edit source file:\n\n',
              file=sys.stderr)
        print(e.output, file=sys.stderr)
        sys.exit(1)
Beispiel #29
0
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description='Utility for testing incremental syntax parsing',
        epilog='''
    Based of a single template the utility generates a pre-edit and a post-edit
    file. It then verifies that incrementally parsing the post-edit file base
    on the pre-edit file results in the same syntax tree as reparsing the
    post-edit file from scratch.

    To generate the pre-edit and the post-edit file from the template, it
    operates on markers of the form:

        <<test_case<pre|||post>>>

    These placeholders are replaced by:
      - 'pre' if a different test case than 'test_case' is run
      - 'pre' for the pre-edit version of 'test_case'
      - 'post' for the post-edit version of 'test_case'
    ''')
    parser.add_argument('file',
                        type=argparse.FileType(),
                        help='The template file to test')
    parser.add_argument(
        '--test-case',
        default='',
        help='The test case to execute. If no test case is specified all \
              unnamed substitutions are applied')
    parser.add_argument(
        '--temp-dir',
        required=True,
        help='A temporary directory where pre-edit and post-edit files can be \
              saved')
    parser.add_argument('--swift-syntax-test',
                        required=True,
                        help='The path to swift-syntax-test')
    parser.add_argument(
        '--print-visual-reuse-info',
        default=False,
        action='store_true',
        help='Print visual reuse information about the incremental parse \
              instead of diffing the syntax trees. This option is intended \
              for debug purposes only.')

    args = parser.parse_args(sys.argv[1:])

    test_file = args.file.name
    test_file_name = os.path.basename(test_file)
    test_case = args.test_case
    temp_dir = args.temp_dir
    swift_syntax_test = args.swift_syntax_test
    visual_reuse_info = args.print_visual_reuse_info

    if not os.path.exists(temp_dir):
        os.makedirs(temp_dir)

    incremental_serialized_file = temp_dir + '/' + test_file_name + '.' \
        + test_case + '.postViaIncr.json'
    post_edit_serialized_file = temp_dir + '/' + test_file_name + '.' \
        + test_case + '.post.json'

    # Generate the syntax tree once incrementally and once from scratch
    try:
        serializeIncrParseMarkupFile(test_file=test_file,
                                     test_case=test_case,
                                     mode='incremental',
                                     serialization_mode='full',
                                     serialization_format='json',
                                     omit_node_ids=True,
                                     output_file=incremental_serialized_file,
                                     temp_dir=temp_dir + '/temp',
                                     swift_syntax_test=swift_syntax_test,
                                     print_visual_reuse_info=visual_reuse_info)
        if visual_reuse_info:
            # If we just want the reuse info, we don't need to parse the file
            # from scratch or validate it
            sys.exit(0)

        serializeIncrParseMarkupFile(test_file=test_file,
                                     test_case=test_case,
                                     mode='post-edit',
                                     serialization_mode='full',
                                     serialization_format='json',
                                     omit_node_ids=True,
                                     output_file=post_edit_serialized_file,
                                     temp_dir=temp_dir + '/temp',
                                     swift_syntax_test=swift_syntax_test,
                                     print_visual_reuse_info=visual_reuse_info)
    except TestFailedError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file),
              file=sys.stderr)
        print(e.message, file=sys.stderr)
        sys.exit(1)

    # Check if the two syntax trees are the same
    try:
        run_command([
            'diff', '-u', incremental_serialized_file,
            post_edit_serialized_file
        ])
    except subprocess.CalledProcessError as e:
        print('Test case "%s" of %s FAILed' % (test_case, test_file),
              file=sys.stderr)
        print(
            'Syntax tree of incremental parsing does not match '
            'from-scratch parsing of post-edit file:\n\n',
            file=sys.stderr)
        print(e.output, file=sys.stderr)
        sys.exit(1)