def _test_from_file(base_filename, format): if format.bpp == 1: layers = djvu.decode.RENDER_MASK_ONLY else: layers = djvu.decode.RENDER_COLOR base_filename = os.path.join(here, base_filename) djvu_filename = '{base}.djvu'.format(base=base_filename) expected_filename = '{base}_{bpp}bpp.{ext}'.format(base=base_filename, bpp=format.bpp, ext=format.extension) with open(expected_filename, 'rb') as file: expected = file.read() context = djvu.decode.Context() document = context.new_document(djvu.decode.FileUri(djvu_filename)) page_job = document.pages[0].decode(wait=True) file = io.BytesIO() format.write_image(page_job, layers, file) result = file.getvalue() assert_equal(len(result), len(expected)) if result == expected: # The easy part: return else: # The result might be still correct, even if the strings are different. # Think of BMP format and its padding bytes. expected = Image.open(expected_filename) result = Image.open(io.BytesIO(result)) assert_equal(result.format, expected.format) assert_equal(result.size, expected.size) assert_equal(result.mode, expected.mode) if result.palette is None: assert_is_none(expected.palette) else: assert_equal(list(result.palette.getdata()), list(expected.palette.getdata())) assert_equal(list(result.getdata()), list(expected.getdata()))
def test_not_overridden(self): def show(message, category, filename, lineno, file=None, line=None): with assert_raises_regex(NotOverriddenWarning, r'^.*\bB.f[(][)] is not overridden$'): raise message with warnings.catch_warnings(): warnings.showwarning = show assert_is_none(self.B().f(6, 7))
def test_none(self): assert_is_none(parse_page_numbers(None))