Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
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