def test_build_buildspecs(): buildspec_paths = os.path.join(test_root, "buildsystem", "valid_buildspecs") buildtest_configuration = load_settings() class args: buildspec = [buildspec_paths] debug = False stage = None testdir = None exclude = None tags = None executor = None filter_tags = None rebuild = None # testing buildtest build --buildspec tests/examples/buildspecs func_build_subcmd(args, buildtest_configuration) class args: buildspec = [buildspec_paths] debug = False stage = None testdir = None exclude = [buildspec_paths] tags = None executor = None filter_tags = None rebuild = None # testing buildtest build --buildspec tests/examples/buildspecs --exclude tests/examples/buildspecs # this results in no buildspecs built with pytest.raises(SystemExit): func_build_subcmd(args, buildtest_configuration)
def test_build_by_stages(): buildtest_configuration = load_settings() class args: buildspec = None debug = False stage = "parse" testdir = None exclude = None tags = ["python"] executor = None filter_tags = None rebuild = None # testing buildtest build --tags python --stage=parse func_build_subcmd(args, buildtest_configuration) class args: buildspec = None debug = False stage = "build" testdir = None exclude = None tags = ["python"] executor = None filter_tags = None rebuild = None # testing buildtest build --tags tutorials --stage=build func_build_subcmd(args, buildtest_configuration)
def test_cori(): if os.getenv("NERSC_HOST") != "cori": pytest.skip("Test runs only on Cori") here = os.path.dirname(os.path.abspath(__file__)) cori_configuration = os.path.join(here, "settings", "cori.config.yml") settings = check_settings(cori_configuration, retrieve_settings=True) buildspec_files = os.path.join(here, "examples", "cori_buildspecs", "hostname.yml") class args: buildspec = [buildspec_files] debug = False stage = None testdir = None exclude = None tags = None executor = None filter_tags = None rebuild = None # test job submission on Cori func_build_subcmd(args, settings)
def test_build_multi_executors(): buildtest_configuration = load_settings() class args: executor = ["local.sh", "local.python"] buildspec = None debug = False stage = None testdir = None exclude = None tags = None filter_tags = None rebuild = None # testing buildtest build --executor local.sh --executor local.python func_build_subcmd(args, buildtest_configuration)
def test_buildspec_tag_executor(): buildtest_configuration = load_settings() class args: executor = ["local.sh"] tags = ["fail"] buildspec = None debug = False stage = None testdir = None exclude = None filter_tags = None rebuild = None # testing buildtest build --tags fail --executor local.sh func_build_subcmd(args, buildtest_configuration)
def test_build_rebuild(): buildtest_configuration = load_settings() buildspec_file = os.path.join(BUILDTEST_ROOT, "tutorials", "python-shell.yml") class args: buildspec = [buildspec_file] debug = False stage = None testdir = None exclude = None tags = None executor = None filter_tags = None rebuild = 5 # rebuild 5 times (buildtest build -b tutorials/python-shell.yml --rebuild=5 func_build_subcmd(args, buildtest_configuration)
def test_build_by_tags(): # ensure we rebuild cache file before running by tags # rerunning buildtest buildspec find without --rebuild option this will read from cache file class args: find = True rebuild = True root = None buildspec_files = False executors = False tags = False paths = False group_by_tags = False group_by_executor = False maintainers = False maintainers_by_buildspecs = False filter = None format = None helpfilter = False helpformat = False func_buildspec_find(args) buildtest_configuration = load_settings() class args: buildspec = None debug = False stage = None testdir = None exclude = None tags = ["pass"] executor = None filter_tags = None rebuild = None # testing buildtest build --tags pass func_build_subcmd(args, buildtest_configuration) class args: buildspec = [os.path.join(test_root, "tutorials")] debug = False stage = None testdir = None exclude = None tags = ["fail", "python"] executor = None filter_tags = None rebuild = None # testing buildtest build --tags fail --tags python func_build_subcmd(args, buildtest_configuration) class args: buildspec = None debug = False stage = None testdir = None exclude = None tags = ["pass"] executor = None filter_tags = ["pass"] rebuild = None # testing buildtest build --tags pass --tags pass func_build_subcmd(args, buildtest_configuration)
def main(): """Entry point to buildtest.""" # create a temporary file to store logfile and we don't delete file by setting 'delete=False' # by default tempfile will delete file upon exit. tf = tempfile.NamedTemporaryFile(prefix="buildtest_", delete=False, suffix=".log") dest_logfile = tf.name logger = init_logfile(dest_logfile) logger.info("Starting buildtest log") create_dir(BUILDTEST_USER_HOME) create_dir(var_root) # Create a build test system, and check requirements # BuildTestSystem() system.check() parser = BuildTestParser() args = parser.parse_options() if args.debug: streamlog(args.debug) # invoking load_settings will attempt to initialize buildtest settings and # load the schema settings_file = resolve_settings_file() logger.info(f"Processing buildtest configuration file: {settings_file}") buildtest_configuration = check_settings(settings_file, retrieve_settings=True) if args.subcommands == "build": func_build_subcmd(args, buildtest_configuration) else: if args.subcommands and args.func: args.func(args) return logdir = buildtest_configuration.get("logdir") if not logdir: print(f"Writing Logfile to: {dest_logfile}") sys.exit(0) logdir = resolve_path(logdir, exist=False) if logdir: create_dir(logdir) fname = os.path.basename(dest_logfile) logpath = os.path.join(logdir, fname) shutil.copy2(dest_logfile, logpath) print(f"Writing Logfile to: {logpath}") else: print(f"Writing Logfile to: {dest_logfile}") # store copy of logfile at $BUILDTEST_ROOT/buildtest.log. A convenient location for user to # find logfile for last build, this will be overwritten for every subsequent build. shutil.copy2(dest_logfile, os.path.join(os.getenv("BUILDTEST_ROOT"), "buildtest.log"))