Exemplo n.º 1
0
def test_emptyconfig(tmpdir):
    cfg = tmpdir / "bad.cfg"
    cfg.write("[DEFAULT]\nkey = value\n")

    with pytest.raises(KeyError):
        Settings.fromFile(cfg, strict=True)

    with pytest.warns(UserWarning):
        Settings.fromFile(cfg, strict=False)
Exemplo n.º 2
0
def test_update(cleanEnviron, mockSerpentData, useDataDir, allStrings, onHydep):
    SETTINGS = {
        "acelib": mockSerpentData[Library.ACE],
        "nfylib": mockSerpentData[Library.NFY],
        "declib": mockSerpentData[Library.DEC],
        "thermal scattering": mockSerpentData[Library.SAB],
        "executable": "sss2",
        "mpi": 8,
        "omp": 64,
        "generations per batch": 10,
        "particles": 1000,
        "active": 50,
        "inactive": 20,
        "k0": 1.2,
        "fpy mode": "weighted",
        "fsp inactive batches": 5,
    }

    if useDataDir:
        for key in {"acelib", "declib", "nfylib"}:
            SETTINGS[key] = SETTINGS[key].name
        SETTINGS["datadir"] = mockSerpentData[Library.DATA_DIR]

    if allStrings:
        SETTINGS = {k: str(v) for k, v in SETTINGS.items()}

    if onHydep:
        SETTINGS = {"hydep": {}, "hydep.serpent": SETTINGS}
        hset = Settings()
        hset.updateAll(SETTINGS)
        serpent = hset.serpent
    else:
        serpent = SerpentSettings()
        serpent.update(SETTINGS)

    if useDataDir:
        assert serpent.datadir == mockSerpentData[Library.DATA_DIR]
    else:
        assert serpent.datadir is None
    assert serpent.acelib.samefile(mockSerpentData[Library.ACE])
    assert serpent.declib.samefile(mockSerpentData[Library.DEC])
    assert serpent.nfylib.samefile(mockSerpentData[Library.NFY])
    assert serpent.sab.samefile(mockSerpentData[Library.SAB])
    assert serpent.executable == "sss2"
    assert serpent.mpi == 8
    assert serpent.omp == 64
    assert serpent.generationsPerBatch == 10
    assert serpent.particles == 1000
    assert serpent.active == 50
    assert serpent.inactive == 20
    assert serpent.k0 == 1.2
    assert serpent.fpyMode == "weighted"
    assert serpent.fspInactiveBatches == 5
Exemplo n.º 3
0
def test_subsettings():
    randomSection = "".join(random.sample(string.ascii_letters, 10))
    settings = Settings()
    assert not hasattr(settings, "test")
    assert not hasattr(settings, randomSection)

    class IncompleteSetting(SubSetting, sectionName="incomplete"):
        pass

    with pytest.raises(TypeError, match=".*abstract methods"):
        IncompleteSetting()

    class MySubSettings(SubSetting, sectionName="test"):
        def __init__(self):
            self.truth = True

        def update(self, options):
            v = options.get("truth", None)
            if v is not None:
                self.truth = asBool("truth", v)

    t = settings.test
    assert isinstance(t, MySubSettings)
    assert not hasattr(settings, randomSection)
    assert t.truth

    settings.updateAll({"hydep.test": {"truth": "0"}})
    assert not t.truth

    fresh = Settings()
    fresh.updateAll({
        "hydep": {
            "depletion solver": "cram48"
        },
        "hydep.test": {
            "truth": "n"
        }
    })
    assert fresh.depletionSolver == "cram48"
    assert not fresh.test.truth

    with pytest.raises(ValueError, match=f".*{randomSection}"):
        fresh.updateAll({f"hydep.{randomSection}": {"key": "value"}})

    with pytest.raises(ValueError, match=".*test"):

        class DuplicateSetting(SubSetting, sectionName="test"):
            pass
Exemplo n.º 4
0
def test_fromSettings():
    """Test the integration into the dynamic settings framework"""
    hsettings = Settings()

    hsettings.updateAll(
        {
            "hydep": {},
            "hydep.sfv": {
                "modes": "1E6",
                "mode fraction": "0.5",
                "density cutoff": "1E-5",
            },
        }
    )
    assert hsettings.sfv.modes == 1e6
    assert hsettings.sfv.modeFraction == 0.5
    assert hsettings.sfv.densityCutoff == 1e-5
Exemplo n.º 5
0
def regressionSettings():
    datadir = os.environ.get("SERPENT_DATA")
    if not datadir:
        pytest.skip("Need SERPENT_DATA environment variable")
    options = {
        "hydep": {
            "boundary conditions": "reflective"
        },
        "hydep.serpent": {
            "seed": 12345678910,
            "particles": 100,
            "generations per batch": 2,
            "active": 10,
            "inactive": 2,
            "executable": "sss2",
            "acelib": "sss_endfb7u.xsdata",
            "declib": "sss_endfb7.dec",
            "nfylib": "sss_endfb7.nfy",
            "datadir": datadir,
        },
    }
    settings = Settings()
    settings.updateAll(options)
    return settings
Exemplo n.º 6
0
def test_exampleConfig(serpentdata):
    cfg = pathlib.Path(__file__).parents[1] / "hydep.cfg.example"
    assert cfg.is_file(), cfg

    settings = Settings.fromFile(cfg)

    assert settings.boundaryConditions == ("reflective", "vacuum",
                                           "reflective")
    assert settings.basedir == pathlib.Path("example/base").resolve()
    assert settings.depletionSolver == "48"
    assert settings.rundir == pathlib.Path("example/run").resolve()
    assert not settings.useTempDir
    assert settings.fittingOrder == 0
    assert settings.numFittingPoints == 2

    serpent = settings.serpent

    assert serpent.acelib.parent == serpentdata
    assert serpent.acelib.name == "sss_endfb7u.xsdata"
    assert serpent.declib.parent == serpentdata
    assert serpent.declib.name == "sss_endfb71.dec"
    assert serpent.nfylib.parent == serpentdata
    assert serpent.nfylib.name == "sss_endfb71.nfy"

    assert serpent.particles == int(5e6)
    assert serpent.generationsPerBatch == 10
    assert serpent.active == 20
    assert serpent.inactive == 15
    assert serpent.seed == 123456
    assert serpent.k0 == 1.2

    assert serpent.executable == "sss2"
    assert serpent.omp == 16
    assert serpent.mpi == 2

    assert serpent.fpyMode == "constant"
    assert serpent.constantFPYSpectrum == "fast"

    assert serpent.fspInactiveBatches == 2

    sfv = settings.sfv
    assert sfv.modes == 10
    assert sfv.modeFraction == 0.75
    assert sfv.densityCutoff == 1e-20
Exemplo n.º 7
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.º 8
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"})