PunkyBrowster / tests /

import os
import shutil
import tempfile

from PIL import Image
from import eq_, set_trace as st

from tests import browser

root_dir = tempfile.mkdtemp()

def teardown():

def test_save_snapshot():
    """Does save_snapshot() produce an image of the expected size and format?


    img_path = get_img_path('snapshot_1.png')
    img =

    # The real size of the body is 280x400, but the 20-pixel margin increases
    # size of the snapshot.
    eq_(img.size, (300, 440))
    eq_(img.format, 'PNG')

def test_save_snapshot_specific_element():
    """Does passing a specific element to save_snapshot() product an image of
    the expected size and format?


    img_path = get_img_path('snapshot_2.png')
    browser.save_snapshot(img_path, browser.first('#side-bar'))

    img =

    # Although the actual size is 100x200, there is a 10-pixel padding and
    # automatic two-pixel margin:
    eq_(img.size, (122, 222))
    eq_(img.format, 'PNG')

def test_save_snapshot_large_small():
    """Does screencapturing two successive pages cause the second page's image
    to be larger than necessary?

    Specifically, if the first page is large and the second is small, does
    the small page's image get inflated to the size of the large page?
    large_img_path = get_img_path('large_page.png')

    small_img_path = get_img_path('small_page.png')

    large_img =
    small_img =

    # Width is the same
    assert large_img.size[0] == small_img.size[0]
    # But height is different
    assert large_img.size[1] > small_img.size[1]

def get_img_path(name):
    return os.path.join(root_dir, name)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.