コード例 #1
0
def test_when_transform_happy_path(runner, source, transformation,
                                   transformations, expected):
    source = data_filename_resolver(source)
    transformations = data_filename_resolver(transformations)
    with runner.isolated_filesystem():
        out = "test_when_transformation_is_specified_by_spec.out"
        result = runner.invoke(
            mckit,
            args=[
                "transform",
                "-o",
                out,
                "-t",
                transformation,
                "-i",
                transformations,
                source,
            ],
            catch_exceptions=False,
        )
        assert result.exit_code == 0, f"Failed to transform {source}"
        expected_universe = from_file(
            data_filename_resolver(expected)).universe
        expected_surfaces = list(expected_universe[0])
        actual_universe = from_file(out).universe
        actual_surfaces = list(actual_universe[0])

        def key(a):
            return a.args[0].options["name"]

        assert sorted(actual_surfaces, key=key) == sorted(expected_surfaces,
                                                          key=key)
コード例 #2
0
ファイル: test_compose.py プロジェクト: MC-kit/mckit
def test_anonymous_transforms(runner, disable_log, source, output, expected):
    source = data_filename_resolver(source)
    with runner.isolated_filesystem() as test_folder:
        result = runner.invoke(mckit,
                               args=["compose", "--output", output, source],
                               catch_exceptions=False)
        assert (
            result.exit_code == 0
        ), "Should success using fill_descriptor in the same directory as source file"
        assert Path(output).exists(
        ), f"Should create file {output} file in {test_folder}"
        actual = from_file(output)
        expected = from_file(data_filename_resolver(expected))
        assert actual.universe.has_equivalent_cells(
            expected.universe), "Cells differ"
コード例 #3
0
ファイル: test_compose.py プロジェクト: MC-kit/mckit
def test_compose(runner, disable_log, universes):
    source = f"data/{universes}.universes/envelopes.i"
    output = f"{universes}.i"
    expected = f"data/{universes}.mcnp"
    source = data_filename_resolver(source)
    assert Path(source).exists(), f"File {source} does not exist"
    with runner.isolated_filesystem() as test_folder:
        result = runner.invoke(mckit,
                               args=["compose", "--output", output, source],
                               catch_exceptions=False)
        assert (
            result.exit_code == 0
        ), "Should success using fill_descriptor in the same directory as source file"
        assert Path(output).exists(
        ), f"Should create file {output} file in {test_folder}"
        actual = from_file(output)
        expected = from_file(data_filename_resolver(expected))
        assert actual.universe.has_equivalent_cells(
            expected.universe), "Cells differ"
        actual_transformations = collect_transformations(actual.universe)
        expected_transformations = collect_transformations(expected.universe)
        assert (actual_transformations == expected_transformations
                ), "The transformations should be the same"
コード例 #4
0
def test_test_universe_analyser():
    universe_path = cli_data("data/shared_surface.mcnp")
    assert universe_path.exists()
    universe = from_file(universe_path).universe
    analyzer = UniverseAnalyser(universe)
    assert not analyzer.cell_duplicates
    assert not analyzer.surface_duplicates
    assert analyzer.surface_to_universe_map
    assert analyzer.surface_to_universe_map[1] == {
        0: 3,
        1: 1,
    }, "The surface 1 occurs 3 times in universes 0 and once in universe 1"
    assert analyzer.we_are_all_clear()
    out = StringIO()
    analyzer.print_duplicates_map(stream=out)
    assert "surface 1 occurs" in out.getvalue()
コード例 #5
0
ファイル: test_decompose.py プロジェクト: MC-kit/mckit
def test_when_only_source_is_specified(runner, disable_log, source, expected):
    source: Path = data_filename_resolver(source)
    with runner.isolated_filesystem():
        result = runner.invoke(
            mckit, args=["decompose", source], catch_exceptions=False
        )
        assert result.exit_code == 0, (
            "Should success without specified output: " + result.output
        )
        output: Path = get_default_output_directory(source)
        for f in expected:
            p = output / f
            assert (
                p.exists()
            ), f"Should store the file {p} in the default directory '{output}'"
            model = from_file(p).universe
            for cell in model:
                assert "U" not in cell.options or cell.options["U"].name() == 0
コード例 #6
0
ファイル: test_decompose.py プロジェクト: MC-kit/mckit
def test_input_files_reading(path, expected_cells):
    universe = from_file(data_filename_resolver(path)).universe
    assert len(universe) == expected_cells, f"Failed to read from file {path}"
コード例 #7
0

@pytest.mark.parametrize(
    "case, box",
    [
        (1, Box([0, 0, 0], 20, 20, 20)),
        (2, Box([0, 0, 0], 20, 20, 20)),
        (3, Box([0, 0, 0], 20, 20, 20)),
    ],
)
def test_save(universe, case, box):
    u = universe(case)
    out = tempfile.NamedTemporaryFile(mode="w+b", delete=False)
    u.save(out.name)
    out.close()
    ur = from_file(out.name).universe

    points = box.generate_random_points(100000)
    universes_orig = {x.name(): x for x in u.get_universes()}
    universes_expected = {x.name(): x for x in ur.get_universes()}
    assert universes_orig.keys() == universes_expected.keys()
    for k, univ in universes_orig.items():
        test_a = univ.test_points(points)
        test_f = universes_expected[k].test_points(points)
        np.testing.assert_array_equal(test_f, test_a)


@pytest.mark.parametrize(
    "case, rename",
    [
        (2, {