<s> from __future__ import ( <EOL> absolute_import , division , print_function , unicode_literals <EOL> ) <EOL> import io <EOL> import logging <EOL> import unittest <EOL> from pngcanvas import * <EOL> BUFSIZE = <NUM_LIT:8> * <NUM_LIT> <EOL> HEIGHT = WIDTH = <NUM_LIT> <EOL> class CanvasTest ( unittest . TestCase ) : <EOL> @ staticmethod <EOL> def compare ( s1 , s2 ) : <EOL> while True : <EOL> b1 = s1 . read ( BUFSIZE ) <EOL> b2 = s2 . read ( BUFSIZE ) <EOL> if b1 != b2 : <EOL> return False <EOL> if not b1 : <EOL> return True <EOL> def test_generation ( self ) : <EOL> logging . debug ( "<STR_LIT>" , WIDTH , HEIGHT ) <EOL> c = PNGCanvas ( WIDTH , HEIGHT , color = ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> ) ) <EOL> c . rectangle ( <NUM_LIT:0> , <NUM_LIT:0> , WIDTH - <NUM_LIT:1> , HEIGHT - <NUM_LIT:1> ) <EOL> logging . debug ( "<STR_LIT>" ) <EOL> c . vertical_gradient ( <NUM_LIT:1> , <NUM_LIT:1> , WIDTH - <NUM_LIT:2> , HEIGHT - <NUM_LIT:2> , <EOL> ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> logging . debug ( "<STR_LIT>" ) <EOL> c . color = bytearray ( ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> ) ) <EOL> c . line ( <NUM_LIT:0> , <NUM_LIT:0> , WIDTH - <NUM_LIT:1> , HEIGHT - <NUM_LIT:1> ) <EOL> c . line ( <NUM_LIT:0> , <NUM_LIT:0> , WIDTH / <NUM_LIT:2> , HEIGHT - <NUM_LIT:1> ) <EOL> c . line ( <NUM_LIT:0> , <NUM_LIT:0> , WIDTH - <NUM_LIT:1> , HEIGHT / <NUM_LIT:2> ) <EOL> logging . debug ( "<STR_LIT>" ) <EOL> c . copy_rect ( <NUM_LIT:1> , <NUM_LIT:1> , WIDTH / <NUM_LIT:2> - <NUM_LIT:1> , HEIGHT / <NUM_LIT:2> - <NUM_LIT:1> , <NUM_LIT:1> , HEIGHT / <NUM_LIT:2> , c ) <EOL> logging . debug ( "<STR_LIT>" ) <EOL> c . blend_rect ( <NUM_LIT:1> , <NUM_LIT:1> , WIDTH / <NUM_LIT:2> - <NUM_LIT:1> , HEIGHT / <NUM_LIT:2> - <NUM_LIT:1> , WIDTH / <NUM_LIT:2> , <NUM_LIT:0> , c ) <EOL> with io . open ( '<STR_LIT>' , '<STR_LIT:rb>' ) as reference : <EOL> with io . BytesIO ( ) as test : <EOL> logging . debug ( "<STR_LIT>" ) <EOL> test . write ( c . dump ( ) ) <EOL> test . seek ( <NUM_LIT:0> ) <EOL> logging . debug ( "<STR_LIT>" ) <EOL> self . assertTrue ( self . compare ( reference , test ) ) <EOL> def test_read_consistency ( self ) : <EOL> c = PNGCanvas ( WIDTH , HEIGHT , color = ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> ) ) <EOL> with io . open ( '<STR_LIT>' , '<STR_LIT:rb>' ) as reference : <EOL> with io . BytesIO ( ) as test : <EOL> logging . debug ( "<STR_LIT>" ) <EOL> c . load ( reference ) <EOL> logging . debug ( "<STR_LIT>" ) <EOL> test . write ( c . dump ( ) ) <EOL> reference . seek ( <NUM_LIT:0> ) <EOL> test . seek ( <NUM_LIT:0> ) <EOL> logging . debug ( "<STR_LIT>" ) <EOL> self . assertTrue ( self . compare ( reference , test ) ) <EOL> def test_multi_idat ( self ) : <EOL> ref = PNGCanvas ( WIDTH , HEIGHT , color = ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> ) ) <EOL> ref_multi = PNGCanvas ( WIDTH , HEIGHT , color = ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> ) ) <EOL> with io . open ( '<STR_LIT>' , '<STR_LIT:rb>' ) as f : <EOL> ref_multi . load ( f ) <EOL> with io . open ( '<STR_LIT>' , '<STR_LIT:rb>' ) as f : <EOL> ref . load ( f ) <EOL> self . assertEqual ( ref_multi . canvas , ref . canvas ) <EOL> def test_rgb_load ( self ) : <EOL> """<STR_LIT>""" <EOL> ref = PNGCanvas ( WIDTH , HEIGHT , color = ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> ) ) <EOL> ref_rgb = PNGCanvas ( WIDTH , HEIGHT , color = ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> ) ) <EOL> with io . open ( '<STR_LIT>' , '<STR_LIT:rb>' ) as f : <EOL> ref_rgb . load ( f ) <EOL> with io . open ( '<STR_LIT>' , '<STR_LIT:rb>' ) as f : <EOL> ref . load ( f ) <EOL> self . assertEqual ( ref_rgb . canvas , ref . canvas ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
