def test_generate_multiple(tmpdir, mock_generate): spec = ScalarPotentialSpec(16, 2, correlation.IsotropicGaussian(0.1), 1.0) spec.create = mock.Mock(side_effect=spec.create) for p_file in generate_multiple(spec, 5, options=None, work_dir=str(tmpdir)): spec.create.assert_called_once_with(p_file.file_name, options={}) spec.create.reset_mock() assert p_file.file_name.startswith(str(tmpdir)) assert mock_generate.call_count() == 5
def test_scalar_potential_generate(tmpdir, mock_generate): cor = correlation.IsotropicGaussian(1.0) sp = ScalarPotentialSpec((25, 25), None, cor, 1.5) target_file = str(tmpdir.join("target_file")) result = sp.create(target_file, 25) mock_generate.assert_called_once_with(target_file, 2, (25, 25), cor, 1.5, 25) assert result.file_name == target_file with mock.patch("branchedflowsim.potgen.generate") as potgen: result = sp.create(target_file, 25, {"option": "value"}) potgen.assert_called_with(target_file, 2, (25, 25), cor, 1.5, 25, option="value") assert result.file_name == target_file
def test_scalar_potential_spec(): cor = correlation.IsotropicGaussian(1.0) sp = ScalarPotentialSpec((25, 25), None, cor, 1.5) assert sp.shape == (25, 25) assert sp.dimension == 2 assert sp.support == pytest.approx(np.ones(2)) assert sp.strength == 1.5 assert sp.correlation == cor sp = ScalarPotentialSpec(12, 3, cor, 1.5) assert sp.shape == (12, 12, 12) assert sp.dimension == 3 assert sp.support == pytest.approx(np.ones(3)) assert sp.strength == 1.5 assert sp.correlation == cor with pytest.raises(ValueError): sp = ScalarPotentialSpec((25, 25), 3, cor, 1.5) sp = ScalarPotentialSpec((25, 25), None, cor, 1.5) assert sp.dimension == 2
def test_iso_gauss(): c = correlation.IsotropicGaussian(0.5) assert c.args == ["-c", "gauss", "-l", "0.5"]
def test_trafo(): c = correlation.Transformed(correlation.AnisotropicGaussian(0.5, [1, 2]), [1, 0, 0, 1]) assert type(c.base_correlation) == correlation.AnisotropicGaussian assert c.transform == pytest.approx([1, 0, 0, 1]) assert c.args == [ "-c", "gauss", "1", "2", "--trafo", '"1 0 0 1"', "-l", "0.5" ] correlations = [ correlation.Correlation("gauss", 0.5), correlation.Parametrized("gauss", 0.5, "param"), correlation.IsotropicGaussian(0.5), correlation.AnisotropicGaussian(0.5, [1.0, 2.0, 2.0]), correlation.CustomScript(0.5, "script", OrderedDict([("arg", 5), ("param", 8)])), correlation.Transformed(correlation.AnisotropicGaussian(0.5, [1, 2]), [1, 0, 0, 1]) ] @pytest.mark.parametrize("corr", correlations) def test_as_dict_round_trip(corr): dict_rep = corr.as_dict reconstructed = correlation.Correlation.from_dict(dict_rep) assert corr == reconstructed