Spaces:
Paused
Paused
Download tests/unit_tests/key_value/codec_test.py from Leon4gr45/powerbi: direct link, hf CLI and curl.
- Browser
- Download file 3.84 kB
-
https://huggingface.co/spaces/Leon4gr45/powerbi/resolve/main/tests/unit_tests/key_value/codec_test.py
- Command line
-
hf download hf://spaces/Leon4gr45/powerbi/tests/unit_tests/key_value/codec_test.py
-
curl -L -o codec_test.py https://huggingface.co/spaces/Leon4gr45/powerbi/resolve/main/tests/unit_tests/key_value/codec_test.py
3.84 kB
| # Licensed to the Apache Software Foundation (ASF) under one | |
| # or more contributor license agreements. See the NOTICE file | |
| # distributed with this work for additional information | |
| # regarding copyright ownership. The ASF licenses this file | |
| # to you under the Apache License, Version 2.0 (the | |
| # "License"); you may not use this file except in compliance | |
| # with the License. You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, | |
| # software distributed under the License is distributed on an | |
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| # KIND, either express or implied. See the License for the | |
| # specific language governing permissions and limitations | |
| # under the License. | |
| from contextlib import nullcontext | |
| from typing import Any | |
| import pytest | |
| from marshmallow import Schema | |
| from superset.dashboards.permalink.schemas import DashboardPermalinkSchema | |
| from superset.key_value.exceptions import KeyValueCodecEncodeException | |
| from superset.key_value.types import ( | |
| BinaryKeyValueCodec, | |
| JsonKeyValueCodec, | |
| MarshmallowKeyValueCodec, | |
| PickleKeyValueCodec, | |
| ) | |
| def test_json_codec(input_: Any, expected_result: Any): | |
| cm = ( | |
| pytest.raises(type(expected_result)) | |
| if isinstance(expected_result, Exception) | |
| else nullcontext() | |
| ) | |
| with cm: | |
| codec = JsonKeyValueCodec() | |
| encoded_value = codec.encode(input_) | |
| assert expected_result == codec.decode(encoded_value) | |
| def test_marshmallow_codec(schema: Schema, input_: Any, expected_result: Any): | |
| cm = ( | |
| pytest.raises(type(expected_result)) | |
| if isinstance(expected_result, Exception) | |
| else nullcontext() | |
| ) | |
| with cm: | |
| codec = MarshmallowKeyValueCodec(schema) | |
| encoded_value = codec.encode(input_) | |
| assert expected_result == codec.decode(encoded_value) | |
| def test_pickle_codec(input_: Any, expected_result: Any): | |
| codec = PickleKeyValueCodec() | |
| encoded_value = codec.encode(input_) | |
| assert expected_result == codec.decode(encoded_value) | |
| def test_binary_codec_encode(): | |
| codec = BinaryKeyValueCodec() | |
| raw = b"\x00\x01binary\xffdata" | |
| assert codec.encode(raw) == raw | |
| def test_binary_codec_round_trips(): | |
| codec = BinaryKeyValueCodec() | |
| raw = b"\x00\x01binary\xffdata" | |
| assert codec.decode(raw) == raw | |
| assert codec.encode(codec.decode(raw)) == raw | |