def load_class_data(class_name: str): """ Load class data from a class data ('.cld') file. Data will be a dict with format: keys: student name values: list currently only containing the avatar filename/None. :param class_name: str :return: dict """ class_data_filename = class_name + CLASSLIST_DATA_FILE_TYPE classlist_data_path = CLASSLIST_DATA_PATH.joinpath(class_name, class_data_filename) with open(classlist_data_path, 'r') as class_datafile: loaded_class_json = class_datafile.read() class_data_dict = load_from_json(loaded_class_json) return class_data_dict
def test_load_from_json_test_class_data(self): assert test_json_class_data['loaded_dict'] == load_from_json( test_json_class_data['json_data_string'])
def test_load_from_json(self): json_data_to_convert = '{\n "1": "a",\n "b": 2,\n "3": "c",\n "d": 4\n}' converted_json_data = {"1": 'a', 'b': 2, "3": 'c', 'd': 4} assert load_from_json(json_data_to_convert) == converted_json_data
def test_load_from_json(self): assert load_from_json( self.json_data_to_convert) == self.converted_json_data
def test_load_from_json_test_class_data(self): assert load_from_json(self.test_json_class_data['json_str_rep']) == self.test_json_class_data['json_dict_rep']
def test_load_from_json(self, json_str, loaded_object): assert load_from_json(json_str) == loaded_object