コード例 #1
0
def test_pickleability(default_user_params):
    ic_ = InitialConditions(init=True, user_params=default_user_params)
    ic_.filled = True
    ic_.random_seed

    s = pickle.dumps(ic_)

    ic2 = pickle.loads(s)
    assert repr(ic_) == repr(ic2)
コード例 #2
0
def test_different_seeds(init, default_user_params):
    ic2 = InitialConditions(random_seed=2, user_params=default_user_params)

    assert init is not ic2
    assert init != ic2
    assert repr(init) != repr(ic2)
    assert init._seedless_repr() == ic2._seedless_repr()

    assert init._md5 == ic2._md5

    # make sure we didn't inadvertantly set the random seed while doing any of this
    assert init._random_seed is None
コード例 #3
0
ファイル: test_cli.py プロジェクト: IvanNikolic21/21cmFAST
def test_init(module_direc, default_user_params, runner, cfg):
    # Run the CLI. There's no way to turn off writing from the CLI (since that
    # would be useless). We produce a *new* initial conditions box in a new
    # directory and check that it exists. It gets auto-deleted after.
    result = runner.invoke(
        cli.main,
        ["init", "--direc", str(module_direc), "--seed", "101010", "--config", cfg],
    )

    if result.exception:
        print(result.output)

    assert result.exit_code == 0

    ic = InitialConditions(user_params=default_user_params, random_seed=101010)
    assert ic.exists(direc=str(module_direc))
コード例 #4
0
def test_fname(default_user_params):
    ic1 = InitialConditions(user_params=default_user_params)
    ic2 = InitialConditions(user_params=default_user_params)

    # we didn't give them seeds, so can't access the filename attribute
    # (it is undefined until a seed is set)
    with pytest.raises(AttributeError):
        assert ic1.filename != ic2.filename  # random seeds are different

    # *but* should be able to get a skeleton filename:
    assert ic1._fname_skeleton == ic2._fname_skeleton

    ic1.random_seed  # sets the random seed
    ic2.random_seed

    assert ic1.filename != ic2.filename  # random seeds should now be different
    assert ic1._fname_skeleton == ic2._fname_skeleton
コード例 #5
0
ファイル: test_output_structs.py プロジェクト: dfm/21cmFAST
def test_match_seed(test_direc, default_user_params):
    # we update this one, so don't use the global one
    ic_ = InitialConditions(init=True, random_seed=12, user_params=default_user_params)

    # fake it being filled
    ic_.filled = True
    ic_.random_seed

    ic_.write(direc=test_direc)

    ic2 = InitialConditions(random_seed=1, user_params=default_user_params)

    # should not read in just anything if its random seed is set.
    with pytest.raises(IOError):
        ic2.read(direc=test_direc)
コード例 #6
0
def test_reading_purged(ic: InitialConditions):
    lowres_density = ic.lowres_density

    # Remove it from memory
    ic.purge()

    assert "lowres_density" not in ic.__dict__
    assert ic._array_state["lowres_density"].on_disk
    assert not ic._array_state["lowres_density"].computed_in_mem

    # But we can still get it.
    lowres_density_2 = ic.lowres_density

    assert ic._array_state["lowres_density"].on_disk
    assert ic._array_state["lowres_density"].computed_in_mem

    assert np.allclose(lowres_density_2, lowres_density)

    ic.load_all()
コード例 #7
0
def test_readability(ic, tmpdirec, default_user_params):
    ic2 = InitialConditions(user_params=default_user_params)

    # without seeds, they are obviously exactly the same.
    assert ic._seedless_repr() == ic2._seedless_repr()

    assert ic2.exists(direc=tmpdirec)

    ic2.read(direc=tmpdirec)

    assert repr(ic) == repr(ic2)  # they should be exactly the same.
    assert str(ic) == str(ic2)  # their str is the same.
    assert hash(ic) == hash(ic2)
    assert ic == ic2
    assert ic is not ic2
コード例 #8
0
def init(default_user_params):
    return InitialConditions(user_params=default_user_params)
コード例 #9
0
def test_match_seed(tmpdirec, default_user_params):
    ic2 = InitialConditions(random_seed=1, user_params=default_user_params)

    # This fails because we've set the seed and it's different to the existing one.
    with pytest.raises(IOError):
        ic2.read(direc=tmpdirec)
コード例 #10
0
ファイル: test_output_structs.py プロジェクト: dfm/21cmFAST
def test_readability(test_direc, default_user_params):
    # we update this one, so don't use the global one
    ic_ = InitialConditions(init=True, user_params=default_user_params)

    # TODO: fake it being filled (need to do both of the following to fool it.
    # TODO: Actually, we *shouldn't* be able to fool it at all, but hey.
    ic_.filled = True
    ic_.random_seed  # accessing random_seed actually creates a random seed.

    ic_.write(direc=test_direc)
    ic2 = InitialConditions(user_params=default_user_params)

    # without seeds, they are obviously exactly the same.
    assert ic_._seedless_repr() == ic2._seedless_repr()

    assert ic2.exists(direc=test_direc)

    ic2.read(direc=test_direc)

    assert repr(ic_) == repr(ic2)  # they should be exactly the same.
    assert str(ic_) == str(ic2)  # their str is the same.
    assert hash(ic_) == hash(ic2)
    assert ic_ == ic2
    assert ic_ is not ic2

    # make sure we can't read it twice
    with pytest.raises(IOError):
        ic2.read(direc=test_direc)