Пример #1
0
def test_picture_with_crop_true_will_crop_to_fit():
    base_path = '/basepath/for/test_picture_success'
    path = 'my_picture.jpg'

    mox = Mox()

    mox.StubOutWithMock(image, 'Image')
    mox.StubOutWithMock(image, 'StringIO')
    mox.StubOutWithMock(image, 'crop_to_fit')

    img_mock = mox.CreateMockAnything()
    img_mock.size = 300, 300

    stringio_mock = mox.CreateMockAnything()
    return_mock = mox.CreateMockAnything()

    stringio_mock.getvalue().AndReturn(return_mock)

    image.StringIO.StringIO().AndReturn(stringio_mock)

    cherrypy.config['image.dir'] = base_path

    image.Image.open(join(base_path, path)).AndReturn(img_mock)
    img_mock.save(stringio_mock, 'JPEG', quality=100)
    image.crop_to_fit(img_mock, (100, 100)).AndReturn(img_mock)

    mox.ReplayAll()

    ret = image.picture(path, 100, 100, crop=True, center=False)
    assert ret == return_mock, "Expected %r. Got %r." % (return_mock, ret)

    mox.VerifyAll()
    del cherrypy.config['image.dir']
Пример #2
0
def test_picture_with_crop_true_will_crop_to_fit():
    base_path = '/basepath/for/test_picture_success'
    path = 'my_picture.jpg'

    mox = Mox()

    mox.StubOutWithMock(image, 'Image')
    mox.StubOutWithMock(image, 'StringIO')
    mox.StubOutWithMock(image, 'crop_to_fit')

    img_mock = mox.CreateMockAnything()
    img_mock.size = 300, 300

    stringio_mock = mox.CreateMockAnything()
    return_mock = mox.CreateMockAnything()

    stringio_mock.getvalue().AndReturn(return_mock)

    image.StringIO.StringIO().AndReturn(stringio_mock)

    cherrypy.config['image.dir'] = base_path

    image.Image.open(join(base_path, path)).AndReturn(img_mock)
    img_mock.save(stringio_mock, 'JPEG', quality=100)
    image.crop_to_fit(img_mock, (100, 100)).AndReturn(img_mock)

    mox.ReplayAll()

    ret = image.picture(path, 100, 100, crop=True, center=False)
    assert ret == return_mock, "Expected %r. Got %r." % (return_mock, ret)

    mox.VerifyAll()
    del cherrypy.config['image.dir']
Пример #3
0
def test_crop_to_fit_lower():
    img = Image.new('RGBA', (500, 750))
    ret = image.crop_to_fit(img, (320, 240))
    assert ret.size == (320, 240), 'Got expected size 320x240, got %rx%r.' % ret.size
Пример #4
0
def test_crop_to_fit_lower():
    img = Image.new('RGBA', (500, 750))
    ret = image.crop_to_fit(img, (320, 240))
    assert ret.size == (
        320, 240), 'Got expected size 320x240, got %rx%r.' % ret.size