예제 #1
0
def main(number_of_sessions=3):
    for i in range(
            number_of_sessions
    ):  # run the front end instance 3 times with appropriate inputs
        # prepare program parameters
        sys.argv = [
            'frontend.py', 'valid_accounts.txt',
            'new_transactions/transaction_' + str(i) + '.txt'
        ]
        frontend.main()
    temp_fd, temp_file = tempfile.mkstemp()
    merged_transaction_file = temp_file
    transaction_files = glob.glob(
        "new_transactions/*.txt")  # list of transaction summary files
    with open(merged_transaction_file,
              'w') as wf:  # create merged txn summary file
        for file in transaction_files:
            with open(file, 'r') as tf:
                for line in tf:
                    if line != 'EOS 0000000 000 0000000 ***':
                        wf.write(line)
        wf.write('EOS 0000000 000 0000000 ***')
    for transaction in transaction_files:
        os.remove(transaction)
    # run backend with updated files
    sys.argv = ['backend.py', 'master_accounts.txt', merged_transaction_file]
    backend.main()
    os.close(temp_fd)
    os.remove(temp_file)
예제 #2
0
def helper(capsys, terminal_input, expected_tail_of_terminal_output,
           input_valid_accounts, expected_output_transactions):
    """Helper function for testing

    Arguments:
        capsys -- object created by pytest to capture stdout and stderr
        terminal_input -- list of string for terminal input
        expected_tail_of_terminal_output list of expected string at the tail of terminal
        input_valid_accounts -- list of valid accounts in the valid_account_list_file
        expected_output_transactions -- list of expected output transactions
    """

    # cleanup package
    reload(app)

    # create a temporary file in the system to store output transactions
    temp_fd, temp_file = tempfile.mkstemp()
    transaction_summary_file = temp_file

    # create a temporary file in the system to store the valid accounts:
    temp_fd2, temp_file2 = tempfile.mkstemp()
    valid_account_list_file = temp_file2
    with open(valid_account_list_file, 'w') as wf:
        wf.write('\n'.join(input_valid_accounts))

    # prepare program parameters
    sys.argv = [
        'frontend.py', valid_account_list_file, transaction_summary_file
    ]

    # set terminal input
    sys.stdin = io.StringIO('\n'.join(terminal_input))
    # run the program
    app.main()

    # capture terminal output / errors
    # assuming that in this case we don't use stderr
    out, err = capsys.readouterr()

    # split terminal output in lines
    out_lines = out.splitlines()
    # compare terminal outputs at the end.`
    for i in range(1, len(expected_tail_of_terminal_output) + 1):
        index = i * -1
        assert expected_tail_of_terminal_output[index] == out_lines[index]

    # compare transactions:
    with open(transaction_summary_file, 'r') as of:
        content = of.read().splitlines()
        for ind in range(len(content)):
            assert content[ind] == expected_output_transactions[ind]

    # clean up
    os.close(temp_fd)
    os.remove(temp_file)
예제 #3
0
파일: ui.py 프로젝트: oguzalp7/ROME
 def db(self):
     if self.ok == False:
         g = Thread(target=frontend.main())
         g.daemon = True
         if once:
             g.start()
             # print(sound_time)
             once = False
         g.join()
예제 #4
0
def run_frontend(input_cities, terminal_input):
    # run frontend for multiple cities for the day
    for i in range(len(terminal_input)): 
        # cleanup package
        reload(frontend) 
        # prepare program parameters
        sys.argv = [
            'frontend.py',
            input_cities[i],
            accountsPath,
            ticketsPath
        ]
                
        # set terminal input
        sys.stdin = io.StringIO(
            '\n'.join(terminal_input[i]))

        # run the program
        frontend.main()
예제 #5
0
def main():
    logging.basicConfig(
        format='%(asctime)-15s %(levelname)-7s [%(name)s] %(message)s')
    logging.getLogger("").setLevel(logging.INFO)
    logger = logging.getLogger(__name__)
    logger.info("Starting application")

    args = parse_command_line_arguments()
    if args.import_data:
        application.initialize_application()
        logger.info(args)
        account_file = os.path.join(args.import_data, "accounts.csv")
        category_file = os.path.join(args.import_data, "categories.csv")
        transaction_file = os.path.join(args.import_data, "transactions.csv")
        logger.info("Importing native csv-files: %s, %s and %s", account_file,
                    category_file, transaction_file)
        application.import_native_data(account_file, transaction_file,
                                       category_file)
        return

    if args.export_data:
        application.initialize_application()
        account_file = os.path.join(args.export_data, "accounts.csv")
        category_file = os.path.join(args.export_data, "categories.csv")
        transaction_file = os.path.join(args.export_data, "transactions.csv")
        logger.info("Exporting data to %s, %s and %s", account_file,
                    transaction_file, category_file)
        application.export_native_data(account_file, transaction_file,
                                       category_file)
        return

    if args.import_rabobank_csv:
        application.initialize_application()
        logger.info("Importing rabobank csv-file: %s",
                    args.import_rabobank_csv)
        application.import_rabobank_transactions([args.import_rabobank_csv])
        return

    frontend.main()