<s> import math <EOL> import unittest <EOL> from requests_toolbelt . multipart . encoder import ( <EOL> IDENTITY , MultipartEncoder , MultipartEncoderMonitor <EOL> ) <EOL> class TestMultipartEncoderMonitor ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . fields = { '<STR_LIT:a>' : '<STR_LIT:b>' } <EOL> self . boundary = '<STR_LIT>' <EOL> self . encoder = MultipartEncoder ( self . fields , self . boundary ) <EOL> self . monitor = MultipartEncoderMonitor ( self . encoder ) <EOL> def test_content_type ( self ) : <EOL> assert self . monitor . content_type == self . encoder . content_type <EOL> def test_length ( self ) : <EOL> assert self . encoder . len == self . monitor . len <EOL> def test_read ( self ) : <EOL> new_encoder = MultipartEncoder ( self . fields , self . boundary ) <EOL> assert new_encoder . read ( ) == self . monitor . read ( ) <EOL> def test_callback_called_when_reading_everything ( self ) : <EOL> callback = Callback ( self . monitor ) <EOL> self . monitor . callback = callback <EOL> self . monitor . read ( ) <EOL> assert callback . called == <NUM_LIT:1> <EOL> def test_callback ( self ) : <EOL> callback = Callback ( self . monitor ) <EOL> self . monitor . callback = callback <EOL> chunk_size = int ( math . ceil ( self . encoder . len / <NUM_LIT> ) ) <EOL> while self . monitor . read ( chunk_size ) : <EOL> pass <EOL> assert callback . called == <NUM_LIT:5> <EOL> def test_bytes_read ( self ) : <EOL> bytes_to_read = self . encoder . len <EOL> self . monitor . read ( ) <EOL> assert self . monitor . bytes_read == bytes_to_read <EOL> def test_default_callable_is_the_identity ( self ) : <EOL> assert self . monitor . callback == IDENTITY <EOL> assert IDENTITY ( <NUM_LIT:1> ) == <NUM_LIT:1> <EOL> def test_from_fields ( self ) : <EOL> monitor = MultipartEncoderMonitor . from_fields ( <EOL> self . fields , self . boundary <EOL> ) <EOL> assert isinstance ( monitor , MultipartEncoderMonitor ) <EOL> assert isinstance ( monitor . encoder , MultipartEncoder ) <EOL> assert monitor . encoder . boundary_value == self . boundary <EOL> class Callback ( object ) : <EOL> def __init__ ( self , monitor ) : <EOL> self . called = <NUM_LIT:0> <EOL> self . monitor = monitor <EOL> def __call__ ( self , monitor ) : <EOL> self . called += <NUM_LIT:1> <EOL> assert monitor == self . monitor </s>
