Exemplo n.º 1
0
def test_settings():
    DEP_SOLVER = "depletion solver"
    BC = "boundary conditions"
    FIT_ORDER = "fitting order"
    N_FIT_POINTS = "fitting points"

    h = Settings()
    h.update({
        DEP_SOLVER: "cram48",
        BC: "reflective reflective vacuum",
        FIT_ORDER: 2,
        N_FIT_POINTS: 4,
    })

    assert h.depletionSolver == "cram48"
    assert h.boundaryConditions == ("reflective", "reflective", "vacuum")
    assert h.fittingOrder == 2
    assert h.numFittingPoints == 4

    h.validate()

    h.update({
        BC: "vacuum",
        FIT_ORDER: "1",
        N_FIT_POINTS: "3",
    })
    assert h.boundaryConditions == ("vacuum", ) * 3
    assert h.fittingOrder == 1
    assert h.numFittingPoints == 3

    with pytest.raises(ValueError, match=".*[B|b]oundary"):
        Settings().update({BC: ["reflective", "very strange", "vacuum"]})
    assert h.boundaryConditions == ("vacuum", ) * 3

    with pytest.raises(TypeError):
        h.fittingOrder = "1"

    fresh = Settings(
        depletionSolver="testSolver",
        boundaryConditions="reflective",
    )
    assert fresh.boundaryConditions == ("reflective", ) * 3
    assert fresh.depletionSolver == "testSolver"

    with pytest.raises(ValueError):
        Settings(fittingOrder=2, numFittingPoints=1).validate()
Exemplo n.º 2
0
def test_directories(tmpdir):
    PWD = pathlib.Path.cwd()
    FAKE_DIR = pathlib.Path(tmpdir)

    settings = Settings(basedir=FAKE_DIR, rundir=None)

    assert settings.basedir.is_absolute()
    assert settings.basedir == FAKE_DIR
    assert settings.rundir is None
    assert not settings.useTempDir

    # Resolution relative to current working directory
    settings.rundir = FAKE_DIR.name
    assert settings.rundir.is_absolute()
    assert settings.rundir == PWD / FAKE_DIR.name

    # String contains an absolute path
    settings.basedir = str(FAKE_DIR)
    assert settings.basedir.is_absolute()
    assert settings.basedir == FAKE_DIR

    # Check defaulting to CWD
    fresh = Settings(basedir=None)
    assert fresh.basedir.is_absolute()
    assert fresh.basedir == pathlib.Path.cwd()

    with pytest.raises(TypeError):
        fresh.basedir = None
    assert fresh.basedir == pathlib.Path.cwd()

    fresh.update({
        "basedir": FAKE_DIR.name,
        "rundir": "nONe",
        "use temp dir": "true",
    })

    assert fresh.basedir == PWD / FAKE_DIR.name
    assert fresh.basedir.is_absolute()
    assert fresh.rundir is None
    assert fresh.useTempDir

    fresh.update({"rundir": FAKE_DIR.name, "use temp dir": "falSe"})

    assert fresh.rundir == PWD / FAKE_DIR.name
    assert fresh.rundir.is_absolute()
    assert not fresh.useTempDir

    with pytest.raises(TypeError):
        fresh.update({"basedir": "none"})