def run_load_dataframes(config, expected_columns=10, expected_rows=42):
    df_list = SourceFile.load_dataframes(config=config, logger=AirbyteLogger(), skip_data=False)
    assert len(df_list) == 1  # Properly load 1 DataFrame
    df = df_list[0]
    assert len(df.columns) == expected_columns  # DataFrame should have 10 columns
    assert len(df.index) == expected_rows  # DataFrame should have 42 rows of data
    return df
Beispiel #2
0
def source(source_file: SourceFile, args: Args) -> List[Instruction]:
    code: List[Instruction] = []
    errors: List[ParseError] = []
    span = source_file.span()
    if args.assertions:
        # An assertion at the start makes the property tests happy
        code.append(StartTapeAssertion(Span(source_file, 0, 0)))
    for sub in _split_on(span, set(['\n'])):
        try:
            code += _line(sub, args)
        except ParseError as err:
            errors.append(err)
    loops = []
    for instr in code:
        if instr.loop_level_change() == 1:
            loops.append(instr)
        elif instr.loop_level_change() == -1:
            if len(loops):
                loops.pop(-1)
            else:
                errors.append(SingleParseError('Unmatched "]"', instr.span()))
        elif instr.loop_level_change() != 0:
            assert False, 'Invalid value ' + str(
                instr.loop_level_change()) + ' for loop level change'
    for instr in loops:
        errors.append(SingleParseError('Unmatched "["', instr.span()))
    if errors:
        raise MultiParseError(errors)
    if args.optimize:
        optimize.optimize(code)
    return code
Beispiel #3
0
    def __init__(self):
        self.root = tk.Tk()

        self.SF = SourceFile(self)
        self.canvas = Canvas(self)
        self.ui = UI(self)

        self.root.mainloop()

        self.close()
Beispiel #4
0
def run(args: Args, io: Io) -> None:
    program = None
    try:
        load_start_time = time.time()
        source_file = SourceFile(args)
        code = parse.source(source_file, args)
        tape = Tape(0, [], True, False)
        program = Program(tape, code, io)
        program_start_time = time.time()
        logger.info('Took ' +
                    str(round(program_start_time - load_start_time, 2)) +
                    's to load program')
        if args.prop_tests:
            run_property_tests(args, cast(Program, program))
        else:
            run_normally(cast(Program, program))
        io.reset()
    except (ProgramError, ParseError) as e:
        if args.expect_fail:
            return
        else:
            raise
    finally:
        if program:
            program_end_time = time.time()
            input_time = io.time_waiting_for_input()
            program_time = program_end_time - program_start_time - input_time
            logger.info('Took ' + str(round(program_time, 2)) +
                        's to run the program' + ' (plus ' +
                        str(round(input_time, 2)) + 's waiting for input)')
            logger.info('Ran ' + str(program.emulated_ops) +
                        ' virtual brainfuck operations')
            logger.info('Ran ' + str(program.real_ops) +
                        ' real constant time operations')
            if not args.prop_tests:
                logger.info('Tape: ' + str(tape))
    if args.expect_fail:
        error = UnexpectedSuccessError('Succeeded unexpectedly')
        if program:
            error.tape = program.tape
        raise error
Beispiel #5
0
def run_load_nested_json_schema(config, expected_columns=10, expected_rows=42):
    data_list = SourceFile.load_nested_json(config, logger=AirbyteLogger())
    assert len(data_list) == 1  # Properly load data
    df = data_list[0]
    assert len(df) == expected_rows  # DataFrame should have 42 items
    return df
Beispiel #6
0
#
# Copyright (c) 2020 Airbyte
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.


import sys

from base_python.entrypoint import launch
from source_file import SourceFile

if __name__ == "__main__":
    source = SourceFile()
    launch(source, sys.argv[1:])
Beispiel #7
0
def get_source_file(index, dist_name):
    data = _get_dist_file_data(index, dist_name, 'source')
    return SourceFile(dist_name, data)
Beispiel #8
0
    def run(self, args):
        if "files" not in self.config:
            return

        for modify_config in self.config["files"]:
            file_path = self.translate_string(modify_config["file_path"])
            if not os.path.isabs(file_path):
                file_path = os.path.join(self.runner.project_root_path, file_path)
            source = SourceFile(file_path)
            source.open()
            operation = modify_config["operation"]

            words = None
            if "words" in modify_config:
                words = modify_config["words"]
                words = self.translate_string(words)

            if "words_file" in modify_config:
                words_file_path = self.translate_string(modify_config["words_file"])
                if not os.path.isabs(words_file_path):
                    words_file_path = os.path.join(self.runner.pack_resource_path, words_file_path)
                fp = open(words_file_path)
                words = fp.read()
                fp.close()
                words = self.translate_string(words)

            if operation == "insert":
                source.insert(modify_config["keys"], words)
            elif operation == "insert_before":
                source.insert_before(modify_config["keys"], words)
            elif operation == "replace":
                olds = modify_config["olds"]
                for i in range(len(olds)):
                    olds[i] = self.translate_string(olds[i])

                news = modify_config["news"]
                for i in range(len(news)):
                    news[i] = self.translate_string(news[i])

                source.replace(olds, news)
            elif operation == "search_replace":
                source.search_replace(modify_config["froms"], modify_config["tos"], words)
            elif operation == "search_replace_to_end":
                source.search_replace_to_end(modify_config["froms"], modify_config["tos"], words)
            elif operation == "remove":
                source.remove(modify_config["froms"], modify_config["tos"])
            source.save()
Beispiel #9
0
    def replace_scheme_data(self, scheme_file_path, target_name, xcode_project_name=None, scheme_name=None):
        print("===>replace scheme data in %s to %s,%s,%s" % (
            scheme_file_path, target_name, xcode_project_name, scheme_name))
        source = SourceFile(scheme_file_path)
        source.open()

        if target_name:
            source.search_replace(["BuildAction", "BuildableName", '"'], ['"'], target_name + ".app")
            source.search_replace(["TestAction", "BuildableName", '"'], ['"'], target_name + ".app")
            source.search_replace(["LaunchAction", "BuildableName", '"'], ['"'], target_name + ".app")
            source.search_replace(["ProfileAction", "BuildableName", '"'], ['"'], target_name + ".app")

        if xcode_project_name:
            source.search_replace(["BuildAction", "ReferencedContainer", '"'], ['"'],
                                  "container:" + xcode_project_name)
            source.search_replace(["TestAction", "ReferencedContainer", '"'], ['"'],
                                  "container:" + xcode_project_name)
            source.search_replace(["LaunchAction", "ReferencedContainer", '"'], ['"'],
                                  "container:" + xcode_project_name)
            source.search_replace(["ProfileAction", "ReferencedContainer", '"'], ['"'],
                                  "container:" + xcode_project_name)

        if scheme_name:
            source.search_replace(["BuildAction", "BlueprintName", '"'], ['"'], scheme_name)
            source.search_replace(["LaunchAction", "BlueprintName", '"'], ['"'], scheme_name)
            source.search_replace(["TestAction", "BlueprintName", '"'], ['"'], scheme_name)
            source.search_replace(["ProfileAction", "BlueprintName", '"'], ['"'], scheme_name)

        source.save()