def check_page_content(raw, comp_pages): ''' Pattern function. Splits a raw, then checks the number of pages generated, and that each page's content matches the contents of comp_pages. Interpretation of comp_pages is as follows: comp_pages is am item or a list of items. Each item is a string, tuple, or None. If it is a string, the page's content is matched; if it is a tuple, the page's content and/or header are checked. If any of the items are None, that comparison is ignored. ''' #Convert to single-element list if not isinstance(comp_pages, list): comp_pages = [comp_pages] #Convert all non-tuples to tuples comp_pages = [ item if isinstance(item, tuple) else (item, None) for item in comp_pages ] #execute resources.split pages = list(pagination.split(raw)) assert len(pages) == len(comp_pages) for generated_page, (content, header) in zip(pages, comp_pages): if content is not None: assert generated_page.content == content, repr( generated_page.content) + " should be " + repr(content) if header is not None: assert generated_page.header == header, repr( generated_page.header) + " should be " + repr(header)
def check_page_content(raw, comp_pages): ''' Pattern function. Splits a raw, then checks the number of pages generated, and that each page's content matches the contents of comp_pages. Interpretation of comp_pages is as follows: comp_pages is am item or a list of items. Each item is a string, tuple, or None. If it is a string, the page's content is matched; if it is a tuple, the page's content and/or header are checked. If any of the items are None, that comparison is ignored. ''' #Convert to single-element list if not isinstance(comp_pages, list): comp_pages = [comp_pages] #Convert all non-tuples to tuples comp_pages = [item if isinstance(item, tuple) else (item, None) for item in comp_pages] #execute resources.split pages = list(pagination.split(raw)) assert len(pages) == len(comp_pages) for generated_page, (content, header) in zip(pages, comp_pages): if content is not None: assert generated_page.content == content, repr(generated_page.content) + " should be " + repr(content) if header is not None: assert generated_page.header == header, repr(generated_page.header) + " should be " + repr(header)
def check_offsets(raw, offsets): actual = [page.offset for page in split(raw)] assert actual == offsets, actual
def check_offsets(raw, offsets): actual = [page.offset for page in split(raw)] assert actual == offsets