Exemple #1
0
def test_setup_restartdir():

    restartdir = labdir / 'archive' / 'restarts'

    # Set a restart directory in config
    config['restart'] = str(restartdir)
    write_config()

    make_restarts()

    manifests = get_manifests(ctrldir / 'manifests')
    payu_setup(lab_path=str(labdir))

    # Manifests should not match, as have added restarts
    assert (not manifests == get_manifests(ctrldir / 'manifests'))
Exemple #2
0
def test_restart_reproduce():

    # Set reproduce restart to True
    config['manifest']['reproduce']['input'] = False
    config['manifest']['reproduce']['restart'] = True
    del (config['restart'])
    write_config()
    manifests = get_manifests(ctrldir / 'manifests')

    # Run setup with unchanged restarts
    payu_setup(lab_path=str(labdir))
    assert (manifests == get_manifests(ctrldir / 'manifests'))

    restartdir = labdir / 'archive' / 'restarts'
    # Change modification times on restarts
    for i in range(1, 4):
        (restartdir / 'restart_00{i}.bin'.format(i=i)).touch()

    # Run setup with touched restarts, should work with modified
    # manifest
    payu_setup(lab_path=str(labdir))

    # Manifests should have changed
    assert (not manifests == get_manifests(ctrldir / 'manifests'))

    # Reset manifest "truth"
    manifests = get_manifests(ctrldir / 'manifests')

    # Modify restart files
    make_restarts()

    # Run setup again, which should raise an error due to changed restarts
    with pytest.raises(SystemExit) as pytest_wrapped_e:
        # Run setup with unchanged exe but reproduce exe set to True
        payu_setup(lab_path=str(labdir))

    # Set reproduce restart to False
    config['manifest']['reproduce']['restart'] = False
    write_config()

    # Run setup with modified restarts reproduce set to False
    payu_setup(lab_path=str(labdir))

    # Manifests should have changed
    assert (not manifests == get_manifests(ctrldir / 'manifests'))
Exemple #3
0
def test_setup():

    # Create some input and executable files
    make_inputs()
    make_exe()

    bindir = labdir / 'bin'
    exe = config['exe']

    config_files = payu.models.test.config_files
    for file in config_files:
        make_random_file(ctrldir / file, 29)

    # Run setup
    payu_setup(lab_path=str(labdir))

    assert (workdir.is_symlink())
    assert (workdir.is_dir())
    assert ((workdir / exe).resolve() == (bindir / exe).resolve())
    workdirfull = workdir.resolve()

    for f in config_files + ['config.yaml']:
        assert ((workdir / f).is_file())

    for i in range(1, 4):
        assert ((workdir /
                 'input_00{i}.bin'.format(i=i)).stat().st_size == 1000**2 + i)

    manifests = get_manifests(ctrldir / 'manifests')
    for mfpath in manifests:
        assert ((ctrldir / 'manifests' / mfpath).is_file())

    # Check manifest in work directory is the same as control directory
    assert (manifests == get_manifests(workdir / 'manifests'))

    # Sweep workdir and recreate
    sweep_work()

    assert (not workdir.is_dir())
    assert (not workdirfull.is_dir())

    payu_setup(lab_path=str(labdir))

    assert (manifests == get_manifests(workdir / 'manifests'))
Exemple #4
0
def test_all_reproduce():

    # Remove reproduce options from config
    del (config['manifest']['reproduce'])
    write_config()

    # Run setup
    payu_setup(lab_path=str(labdir))

    manifests = get_manifests(ctrldir / 'manifests')

    make_all_files()

    # Run setup with reproduce=True, which should raise an error as
    # all files changed
    with pytest.raises(SystemExit) as pytest_wrapped_e:
        # Run setup with unchanged exe but reproduce exe set to True
        payu_setup(lab_path=str(labdir), reproduce=True)

    # Run setup
    payu_setup(lab_path=str(labdir))

    # Manifests should have changed
    assert (not manifests == get_manifests(ctrldir / 'manifests'))
Exemple #5
0
def test_input_scaninputs():

    inputdir = labdir / 'input' / config['input']
    inputdir.mkdir(parents=True, exist_ok=True)

    # Set scaninputs input to True
    config['manifest']['scaninputs'] = True
    write_config()

    # Run setup with unchanged input
    payu_setup(lab_path=str(labdir))
    manifests = get_manifests(ctrldir / 'manifests')

    # Set scaninputs input to False
    config['manifest']['scaninputs'] = False
    write_config()

    # Run setup, should work and manifests unchanged
    payu_setup(lab_path=str(labdir))
    assert (manifests == get_manifests(ctrldir / 'manifests'))

    # Update modification times for input files
    for i in range(1, 4):
        (inputdir / 'input_00{i}.bin'.format(i=i)).touch()

    # Run setup, should work as only fasthash will differ, code then
    # checks full hash and updates fasthash if fullhash matches
    payu_setup(lab_path=str(labdir))

    # Manifests should no longer match as fasthashes have been updated
    assert (not manifests == get_manifests(ctrldir / 'manifests'))

    # Reset manifest "truth"
    manifests = get_manifests(ctrldir / 'manifests')

    # Re-create input files
    make_inputs()

    # Run setup again. Should be fine, but manifests changed
    payu_setup(lab_path=str(labdir))
    assert (not manifests == get_manifests(ctrldir / 'manifests'))

    # Reset manifest "truth"
    manifests = get_manifests(ctrldir / 'manifests')

    # Make a new input file
    (inputdir / 'lala').touch()

    # Run setup again. Should be fine, manifests unchanged as
    # scaninputs=False
    payu_setup(lab_path=str(labdir))
    assert (manifests == get_manifests(ctrldir / 'manifests'))

    # Set scaninputs input to True
    config['manifest']['scaninputs'] = True
    write_config()

    # Run setup again. Should be fine, but manifests changed now
    # as scaninputs=False
    payu_setup(lab_path=str(labdir))
    assert (not manifests == get_manifests(ctrldir / 'manifests'))
    assert ((workdir / 'lala').is_file())

    # Delete silly input file
    (inputdir / 'lala').unlink()

    # Re-run after removing silly input file
    payu_setup(lab_path=str(labdir))

    # Reset manifest "truth"
    manifests = get_manifests(ctrldir / 'manifests')
Exemple #6
0
def test_input_reproduce():

    inputdir = labdir / 'input' / config['input']
    inputdir.mkdir(parents=True, exist_ok=True)

    # Set reproduce input to True
    config['manifest']['reproduce']['exe'] = False
    config['manifest']['reproduce']['input'] = True
    write_config()
    manifests = get_manifests(ctrldir / 'manifests')

    # Run setup with unchanged input reproduce input set to True
    # to make sure works with no changes
    payu_setup(lab_path=str(labdir))
    assert (manifests == get_manifests(ctrldir / 'manifests'))

    # Delete input directory from config, should still work from
    # manifest with input reproduce True
    input = config['input']
    write_config()
    del (config['input'])

    # Run setup, should work
    payu_setup(lab_path=str(labdir))

    assert (manifests == get_manifests(ctrldir / 'manifests'))

    # Update modification times for input files
    for i in range(1, 4):
        (inputdir / 'input_00{i}.bin'.format(i=i)).touch()

    # Run setup, should work as only fasthash will differ, code then
    # checks full hash and updates fasthash if fullhash matches
    payu_setup(lab_path=str(labdir))

    # Manifests should no longer match as fasthashes have been updated
    assert (not manifests == get_manifests(ctrldir / 'manifests'))

    # Reset manifest "truth"
    manifests = get_manifests(ctrldir / 'manifests')

    # Re-create input files. Have to set input path for this purpose
    # but not written to config.yaml, so doesn't affect payu commands
    config['input'] = input
    make_inputs()
    del (config['input'])

    # Run setup again, which should raise an error due to changed inputs
    with pytest.raises(SystemExit) as pytest_wrapped_e:
        payu_setup(lab_path=str(labdir))

        assert pytest_wrapped_e.type == SystemExit
        assert pytest_wrapped_e.value.code == 1

    # Change reproduce input back to False
    config['manifest']['reproduce']['input'] = False
    write_config()

    # Run setup with changed inputs but reproduce input set to False
    payu_setup(lab_path=str(labdir))

    # Check manifests have changed as expected and input files
    # linked in work
    assert (not manifests == get_manifests(ctrldir / 'manifests'))
    for i in range(1, 4):
        assert ((workdir / 'input_00{i}.bin'.format(i=i)).is_file())

    # Reset manifest "truth"
    manifests = get_manifests(ctrldir / 'manifests')

    # Delete input manifest
    (ctrldir / 'manifests' / 'input.yaml').unlink()

    # Setup with no input dir and no manifest. Should work ok
    payu_setup(lab_path=str(labdir))

    # Check there are no linked inputs
    for i in range(1, 4):
        assert (not (workdir / 'input_00{i}.bin'.format(i=i)).is_file())

    # Set input path back and recreate input manifest
    config['input'] = input
    write_config()
    payu_setup(lab_path=str(labdir))
Exemple #7
0
def test_exe_reproduce():

    # Set reproduce exe to True
    config['manifest']['reproduce']['exe'] = True
    write_config()
    manifests = get_manifests(ctrldir / 'manifests')

    # Run setup with unchanged exe but reproduce exe set to True.
    # Should run without error
    payu_setup(lab_path=str(labdir))

    assert (manifests == get_manifests(ctrldir / 'manifests'))

    bindir = labdir / 'bin'
    exe = config['exe']

    # Update the modification time of the executable, should run ok
    (bindir / exe).touch()

    # Run setup with changed exe but reproduce exe set to False
    payu_setup(lab_path=str(labdir))

    # Manifests will have changed as fasthash is altered
    assert (not manifests == get_manifests(ctrldir / 'manifests'))

    # Reset manifests "truth"
    manifests = get_manifests(ctrldir / 'manifests')

    # Delete exe path from config, should get it from manifest
    del (config['exe'])
    write_config()

    # Run setup with changed exe but reproduce exe set to False
    payu_setup(lab_path=str(labdir))

    # Manifests will not have changed
    assert (manifests == get_manifests(ctrldir / 'manifests'))
    assert ((workdir / exe).resolve() == (bindir / exe).resolve())

    # Reinstate exe path
    config['exe'] = exe

    # Recreate fake executable file
    make_exe()

    # Run setup again, which should raise an error due to changed executable
    with pytest.raises(SystemExit) as pytest_wrapped_e:
        # Run setup with unchanged exe but reproduce exe set to True
        payu_setup(lab_path=str(labdir))

        assert pytest_wrapped_e.type == SystemExit
        assert pytest_wrapped_e.value.code == 1

    # Change reproduce exe back to False
    config['manifest']['reproduce']['exe'] = False
    write_config()

    # Run setup with changed exe but reproduce exe set to False
    payu_setup(lab_path=str(labdir))

    # Check manifests have changed as expected
    assert (not manifests == get_manifests(ctrldir / 'manifests'))