def environment(datahome, demohome, jarfile, starhome, testhome, files): """Set up the environment to run the demos""" print(strings.heading('Environment preparation')) _setup_testhome(testhome) files.append(jarfile) _copy(files, testhome) print('\n')
def _call_pytest(options, test_cases): print(strings.heading('Calling pytest')) commands = ['export PYTHONPATH=%s' % PWD, 'export STARHOME=%s' % options.starhome, 'export TESTHOME=%s' % options.testhome, 'pytest %s %s' % (options.pytest_args, _test_files(test_cases))] os.system('; '.join(commands)) print('\n')
def print_overview(options): fmt = '%s: %s' print(strings.frame('MacroUtils tester')) print('') print(strings.heading('Important information')) print(fmt % ('DATAHOME', options.data_home)) print(fmt % ('DEMOHOME', options.demo_home)) print(fmt % ('STARHOME', options.star_home)) print(fmt % ('JAR FILE', options.jar_file)) print(fmt % ('TESTHOME', options.test_home)) print('\n') print(strings.heading('Basic Procedure')) print('1) Run demos in STAR-CCM+ -- functional tests;') print('2) Perform unit testing with pytest.') print('\n') print(strings.heading('Note')) print('- In case of a test repetition, only step (2) will be performed;') print('- If one wants to repeat step (1), just remove corresponding') print(' STAR-CCM+ files associated with the demo(s) in TESTHOME.') print('\n') print(strings.heading('Tests to run: %d' % len(options.test_cases))) print(_itemized(options.test_cases)) print('\n')
def print_overview(options): fmt = '%s: %s' print(strings.frame('MacroUtils tester')) print('') print(strings.heading('Important information')) print(fmt % ('DATAHOME', options.datahome)) print(fmt % ('DEMOHOME', options.demohome)) print(fmt % ('STARHOME', options.starhome)) print(fmt % ('JAR FILE', options.jarfile)) print(fmt % ('TESTHOME', options.testhome)) print('\n') print(strings.heading('Basic Procedure')) print('1) Run demos in STAR-CCM+ -- functional tests;') print('2) Perform unit testing with pytest.') print('\n') print(strings.heading('Note')) print('- In case of a test repetition, only step (2) will be performed;') print('- If one wants to repeat step (1), just remove corresponding') print(' STAR-CCM+ files associated with the demo(s) in TESTHOME.') print('\n') print(strings.heading('Tests to run: %d' % len(options.test_cases))) print(_itemized(options.test_cases)) print('\n')
def run_sequential(testhome, commands): """Run invidually""" print(strings.heading('Running in sequential mode')) commands_to_run = _flat(commands) if len(commands_to_run) == 0: return for command in commands_to_run: base_name = _case_name(command) np = _number_of_cores(command) snp = 'np=%d' % np if np > 1 else 'serial' if _will_run(testhome, base_name): print('Running: %s (running %s)' % (base_name, snp)) _run(testhome, command) else: print('Bypassed due presence of log/picture files: %s' % base_name)
def _copy_test_macros(options): print(strings.heading('Test macros')) # Test macros first test_macros_home = os.path.join(PWD, 'macros') java_files = glob.glob(os.path.join(test_macros_home, '*Test.java')) assert len(java_files) > 0, 'No test macros found in %s' % test_macros_home # Then auxiliary macros aux_folder = 'common' aux_macros_home = os.path.join(test_macros_home, aux_folder) aux_in_test_home = os.path.join(options.test_home, aux_folder) if os.path.isdir(aux_in_test_home): shutil.rmtree(aux_in_test_home) # Finally, copy files set_up._copy(java_files, options.test_home) shutil.copytree(aux_macros_home, aux_in_test_home) names = [os.path.split(f)[1] for f in java_files] print(strings.itemized(names)) print('\n')
def run_multiple(testhome, commands, num_threads): """Run multiple threads""" threads = '(threads = %d)' % num_threads print(strings.heading('Running in threaded mode %s' % threads)) commands_to_run = _flat(commands) if len(commands_to_run) == 0: return run_queue = queue.Queue() for i in range(num_threads): thread = TesterThread(queue=run_queue) thread.start() for command in commands_to_run: base_name = _case_name(command) if _will_run(testhome, base_name): run_queue.put([testhome, command]) time.sleep(1) else: print('Bypassed due presence of log/picture files: %s' % base_name) run_queue.join()
def _copy_test_macros(options): print(strings.heading('Test macros')) # Test macros first test_macros_home = os.path.join(PWD, 'macros') java_files = glob.glob(os.path.join(test_macros_home, '*Test.java')) assert len(java_files) > 0, 'No test macros found in %s' % test_macros_home # Then auxiliary macros aux_folder = 'common' aux_macros_home = os.path.join(test_macros_home, aux_folder) aux_in_testhome = os.path.join(options.testhome, aux_folder) if os.path.isdir(aux_in_testhome): shutil.rmtree(aux_in_testhome) # Finally, copy files set_up._copy(java_files, options.testhome) shutil.copytree(aux_macros_home, aux_in_testhome) names = [os.path.split(f)[1] for f in java_files] print(strings.itemized(names)) print('\n')