def _add_mob_tags() -> dict: mob_num = get_book_data()[str(BookItem.MOBS)] data = assertion.is_dict(get_mob_data()) tmp = {} for key, val in data.items(): type = val[str(MobItem.TYPE)] name = val[str(MobItem.NAME)] tmp[key] = name if type == str(MobType.MOB): for i in range(int(mob_num)): tmp[key + str(i)] = name + hankaku_to_zenkaku(str(i)) return tmp
def _get_plot_item_of(record: StoryRecord, item: PlotItem) -> str: assert isinstance(record, StoryRecord) assert isinstance(item, PlotItem) data = assertion.is_dict(elm_plot_of(record)) if not data: logger.warning( msg.ERR_FAIL_MISSING_DATA.format(data=f"plot data in {PROC}")) return "" key = str(item) if key not in data: logger.warning( msg.ERR_FAIL_INVALID_DATA.format( data=f"{key} of record in {PROC}")) return "" return data[key]
def remove_item_order_data(item: OrderItem, fname: str) -> dict: assert isinstance(item, OrderItem) assert isinstance(fname, str) data = assertion.is_dict(_get_order_raw_data()) _fname = ordername_of(item, fname) if OrderItem.CHAPTER is item: if not _reject_chapter_from_order(data, _fname): logger.error( msg.ERR_FAIL_CANNOT_REMOVE_DATA.format(data=f"in {PROC}")) return data elif OrderItem.EPISODE is item: if not _reject_episode_from_order(data, _fname): logger.error( msg.ERR_FAIL_CANNOT_REMOVE_DATA.format(data=f"in {PROC}")) return data elif OrderItem.SCENE is item: if not _reject_scene_from_order(data, _fname): logger.error( msg.ERR_FAIL_CANNOT_REMOVE_DATA.format(data=f"in {PROC}")) return data else: return data
def elm_plot_of(record: StoryRecord) -> dict: return assertion.is_dict(_safe_get_elm_item_of(record, PLOTS))
def _add_time_tags() -> dict: data = assertion.is_dict(get_time_data()) tmp = {} for key, val in data.items(): tmp[key] = val[str(TimeItem.NAME)] return tmp
def _add_term_tags() -> dict: data = assertion.is_dict(get_term_data()) tmp = {} for key, val in data.items(): tmp[key] = val['name'] return tmp
def _get_columns_rows() -> tuple: data = assertion.is_dict(get_basefile_data(ElmType.BOOK)) return data[str(BookItem.COLUMNS)], data[str(BookItem.ROWS)]
def test_assertion_is_dict__failure(x): with pytest.raises(AssertionError): is_dict(x)
def test_assertion_is_dict(x): assert is_dict(x) or is_dict( x) == {}, f"Expected a dictionary type value: {x}"