Ejemplo n.º 1
0
    def test_timer_decorator(self):
        log_file = base_log_file + '_decorator'
        my_logging.prepare_logger(log_file)
        sleep(0.5)
        my_logging.shutdown()

        content = read_file(log_file + '_data.log')

        d = json.loads(content)
        self.assertAlmostEqual(0.5, d['value'], 1)
Ejemplo n.º 2
0
    def test_timer_context_manager(self):
        log_file = base_log_file + '_context_manager'
        my_logging.prepare_logger(log_file)
        my_logging.shutdown()

        with time_measure('mykey2'):
            time.sleep(0.5)

        content = read_file(log_file + '_data.log')
        d = json.loads(content)
        self.assertAlmostEqual(0.5, d['value'], 1)
Ejemplo n.º 3
0
    def test_data(self):
        log_file = default_log_file + '_data_test'
        my_logging.prepare_logger(log_file)
        my_logging.data('key', 2)
        my_logging.info('ABCD')
        my_logging.shutdown()

        # check
        content = read_file(log_file + '_data.log')
        d = json.loads(content)
        self.assertEqual(d['key'], 'key')
        self.assertEqual(d['value'], 2)
        self.assertTrue('ABCD' not in content)
Ejemplo n.º 4
0
    def test_logger(self):
        # ignore warnings
        warnings.simplefilter("ignore")

        # log something
        log_file = default_log_file + '_basic_test'
        my_logging.prepare_logger(log_file)
        my_logging.info("ABCD")
        my_logging.shutdown()

        # check logfile
        success = 'ABCD' in read_file(log_file + '_info.log')
        self.assertTrue(success)
Ejemplo n.º 5
0
    def __init__(self, directory: str, filename: str, keys: Dict[str, int]):
        add_log_context('inputfileTx', filename)
        # locations
        self.directory = directory
        self.filename = filename
        self.output_directory = os.path.join(directory, 'compiled')
        self.code_file = os.path.join(directory, filename)

        # copy template to current directory
        self.scenario_directory = os.path.join(self.directory, 'scenario')
        dir_util.copy_tree(template, self.scenario_directory)
        self.scenario_js_file = os.path.join(self.scenario_directory, 'scenario.js')
        self.scenario_js = read_file(self.scenario_js_file)
        self.deploy_js_file = os.path.join(self.scenario_directory, 'migrations', '2_deploy_contracts.js')
        self.deploy_js = read_file(self.deploy_js_file)

        # copy contracts
        for filename in os.listdir(self.output_directory):
            if filename.endswith('.sol'):
                source = os.path.join(self.output_directory, filename)
                target = os.path.join(self.scenario_directory, 'contracts', filename)
                copyfile(source, target)

        # prepare logging
        log_file = my_logging.get_log_file(None, self.scenario_directory, 'transactions', False)
        my_logging.prepare_logger(log_file)

        # prepare runner
        self.r = get_runner(self.output_directory, self.code(), self.name(), keys)

        # others
        self.transactions = []
        self.set_contract_name()
        self.set_accounts(keys)
        self.set_pk_announce(keys)
        self.set_contract_fetch()
        self.set_verifiers()

        self.n_calls = 0
Ejemplo n.º 6
0
Archivo: main.py Proyecto: fmerg/zkay
        if get_binaries:
            # compilation of the solidity code is not required
            compile_solidity(d, code_file)

    if count:
        my_logging.data('nStatements', count_statements(ast))


if __name__ == '__main__':
    # parse arguments
    a = parse_arguments()

    # create output directory
    ensure_directory(a.output)

    # create log directory
    log_file = my_logging.get_log_file(filename='compile',
                                       parent_dir=a.output,
                                       include_timestamp=False,
                                       label=None)
    my_logging.prepare_logger(log_file)

    # only type-check
    if a.type_check:
        code = read_file(a.input)
        ast = get_processed_ast(code)
    else:
        # compile
        with log_context('inputfile', os.path.basename(a.input)):
            compile(a.input, a.output, a.count)