1# Copyright (C) 2022 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15import json 16import pathlib 17import sys 18from typing import Any, Dict 19 20# Type definition 21JsonObject = Dict[str, Any] 22 23 24def load_json_fast_pair_test_data(json_file_name: str) -> JsonObject: 25 """Loads a JSON text file from test data directory into a Json object. 26 27 Args: 28 json_file_name: The name of the JSON file. 29 """ 30 return json.loads( 31 pathlib.Path(sys.argv[0]).parent.joinpath( 32 'test_data', 'fastpair', json_file_name).read_text() 33 ) 34 35 36def serialize_as_simplified_json_str(json_data: JsonObject) -> str: 37 """Serializes a JSON object into a string without empty space. 38 39 Args: 40 json_data: The JSON object to be serialized. 41 """ 42 return json.dumps(json_data, separators=(',', ':')) 43