def test_accept():
 formatter = hug.output_format.accept({'application/json': hug.output_format.json, 'text/plain': hug.output_format.text})
 class FakeRequest(object, ):
  accept = 'application/json'
 request = FakeRequest()
 response = FakeRequest()
 converted = hug.input_format.json(formatter(BytesIO(hug.output_format.json({'name': 'name'})), request, response))
 assert (converted == {'name': 'name'})
 request.accept = 'text/plain'
 assert (formatter('hi', request, response) == 'hi')
 request.accept = 'application/json, text/plain; q=0.5'
 assert (formatter('hi', request, response) == '"hi"')
 request.accept = 'text/plain; q=0.5, application/json'
 assert (formatter('hi', request, response) == '"hi"')
 request.accept = 'application/json;q=0.4,text/plain; q=0.5'
 assert (formatter('hi', request, response) == 'hi')
 request.accept = '*'
 assert (formatter('hi', request, response) in ['"hi"', 'hi'])
 request.accept = 'undefined; always'
 with pytest.raises(hug.HTTPNotAcceptable):
  formatter('hi', request, response)
 formatter = hug.output_format.accept({'application/json': hug.output_format.json, 'text/plain': hug.output_format.text}, hug.output_format.json)
 assert (formatter('hi', request, response) == '"hi"')

def test_accept ( ) : formatter = hug . output_format . accept ( { 'application/json' : hug . output_format . json , 'text/plain' : hug . output_format . text } ) class FakeRequest ( object , ) : accept = 'application/json' request = FakeRequest ( ) response = FakeRequest ( ) converted = hug . input_format . json ( formatter ( BytesIO ( hug . output_format . json ( { 'name' : 'name' } ) ) , request , response ) ) assert ( converted == { 'name' : 'name' } ) request . accept = 'text/plain' assert ( formatter ( 'hi' , request , response ) == 'hi' ) request . accept = 'application/json, text/plain; q=0.5' assert ( formatter ( 'hi' , request , response ) == '"hi"' ) request . accept = 'text/plain; q=0.5, application/json' assert ( formatter ( 'hi' , request , response ) == '"hi"' ) request . accept = 'application/json;q=0.4,text/plain; q=0.5' assert ( formatter ( 'hi' , request , response ) == 'hi' ) request . accept = '*' assert ( formatter ( 'hi' , request , response ) in [ '"hi"' , 'hi' ] ) request . accept = 'undefined; always' with pytest . raises ( hug . HTTPNotAcceptable ) : formatter ( 'hi' , request , response ) formatter = hug . output_format . accept ( { 'application/json' : hug . output_format . json , 'text/plain' : hug . output_format . text } , hug . output_format . json ) assert ( formatter ( 'hi' , request , response ) == '"hi"' )
tests to ensure the accept type wrapper works as expected .