def test_encode_no_tricks_are_removed():
    from_json = TrickLevelConfiguration.from_json(
        {
            "minimal_logic": False,
            "specific_levels": {
                "Dash": "disabled"
            }
        },
        game=RandovaniaGame.METROID_PRIME_ECHOES)

    encoded, byte_count = bitpacking.pack_results_and_bit_count(
        from_json.bit_pack_encode({}))

    assert encoded == b'\x00\x00\x00\x00'
    assert byte_count == 26

    decoder = BitPackDecoder(encoded)
    decoded = TrickLevelConfiguration.bit_pack_unpack(
        decoder, {
            "reference":
            TrickLevelConfiguration(False, {},
                                    RandovaniaGame.METROID_PRIME_ECHOES),
        })

    assert decoded.specific_levels == {}
def test_encode(trick_level_data):
    expected_bytes, expected_bit_count, value = trick_level_data

    # Run
    result, bit_count = bitpacking.pack_results_and_bit_count(
        value.bit_pack_encode({}))

    # Assert
    assert result == expected_bytes
    assert bit_count == expected_bit_count
Пример #3
0
def test_encode(major_item_state):
    # Setup
    item, expected_bytes, expected_bit_count, value, reference = major_item_state

    # Run
    result, bit_count = bitpacking.pack_results_and_bit_count(value.bit_pack_encode(item, reference=reference))

    # Assert
    assert bit_count == expected_bit_count
    assert result == expected_bytes
Пример #4
0
def test_encode(with_data):
    # Setup
    reference, expected_bytes, expected_bit_count, value = with_data

    # Run
    result, bit_count = bitpacking.pack_results_and_bit_count(
        value.bit_pack_encode({"reference": reference}))

    # Assert
    assert result == expected_bytes
    assert bit_count == expected_bit_count
Пример #5
0
def test_encode(translator_data):
    # Setup
    expected_bytes, expected_bit_count, value = translator_data

    # Run
    result, bit_count = bitpacking.pack_results_and_bit_count(
        value.bit_pack_encode({}))

    # Assert
    assert result == expected_bytes
    assert bit_count == expected_bit_count
Пример #6
0
def test_decode(mocker, invalid):
    games = (RandovaniaGame.METROID_PRIME_ECHOES, RandovaniaGame.METROID_DREAD)
    mock_from_bytes: MagicMock = mocker.patch(
        "randovania.layout.generator_parameters.GeneratorParameters.from_bytes",
        autospec=True)
    parameters = mock_from_bytes.return_value
    parameters.as_bytes = bitpacking.pack_results_and_bit_count(
        generator_parameters.encode_game_list(games))[0]
    if invalid:
        mock_from_bytes.side_effect = ValueError("Invalid Permalink")

    # This test should break whenever we change how permalinks are created
    # When this happens, we must bump the permalink version and change the tests
    encoded = "DQYwMTIzAkwMABlW"

    expected = Permalink(
        parameters=parameters,
        seed_hash=None,
        randovania_version=b"0123",
    )

    # Uncomment this line to quickly get the new encoded permalink
    # assert expected.as_base64_str == ""
    # print(expected.as_base64_str)

    if invalid:
        expectation = pytest.raises(UnsupportedPermalink)
    else:
        expectation = contextlib.nullcontext()

    # Run
    with expectation as exp:
        link = Permalink.from_str(encoded)

    # Assert
    mock_from_bytes.assert_called_once_with(b'F\x00')
    if invalid:
        assert exp.value.games == games
    else:
        assert link == expected