<commit_before>import os
from datetime import datetime

from lektor._compat import iteritems


def almost_equal(a, b, e=0.00001):
    return abs(a - b) < e


def test_exif(pad):
    image = pad.root.attachments.images.get('test.jpg')
    assert image is not None

    assert image.exif

    assert almost_equal(image.exif.altitude, 779.0293)
    assert almost_equal(image.exif.aperture, 2.275)
    assert image.exif.artist is None
    assert image.exif.camera == 'Apple iPhone 6'
    assert image.exif.camera_make == 'Apple'
    assert image.exif.camera_model == 'iPhone 6'
    assert image.exif.copyright is None
    assert image.exif.created_at == datetime(2015, 12, 6, 11, 37, 38)
    assert image.exif.exposure_time == '1/33'
    assert image.exif.f == u'\u0192/2.2'
    assert almost_equal(image.exif.f_num, 2.2)
    assert image.exif.flash_info == 'Flash did not fire, compulsory flash mode'
    assert image.exif.focal_length == '4.2mm'
    assert image.exif.focal_length_35mm == '29mm'
    assert image.exif.iso == 160
    assert almost_equal(image.exif.latitude, 46.6338333)
    assert image.exif.lens == 'Apple iPhone 6 back camera 4.15mm f/2.2'
    assert image.exif.lens_make == 'Apple'
    assert image.exif.lens_model == 'iPhone 6 back camera 4.15mm f/2.2'
    assert almost_equal(image.exif.longitude, 13.4048333)
    assert image.exif.location == (image.exif.latitude, image.exif.longitude)
    assert image.exif.shutter_speed == '1/33'

    assert image.exif.documentname == 'testName'
    assert image.exif.description == 'testDescription'
    assert image.exif.is_rotated

    assert isinstance(image.exif.to_dict(), dict)

    for key, value in iteritems(image.exif.to_dict()):
        assert getattr(image.exif, key) == value


def test_image_attributes(pad):
    image = pad.root.attachments.images.get('test.jpg')
    assert image is not None

    assert image.width == 512
    assert image.height == 384
    assert image.format == 'jpeg'


def test_thumbnail_height(builder):
    builder.build_all()
    with open(os.path.join(builder.destination_path, 'index.html')) as f:
        html = f.read()

    # Thumbnail is half the original width, so its computed height is half.
    assert '<img src="./test@192.jpg" width="192" height="256">' in html

def test_thumbnail_quality(builder):
    builder.build_all()
    image_file = os.path.join(builder.destination_path, 'test@192x256_q20.jpg')
    image_size = os.path.getsize(image_file)

    # See if the image file with said quality suffix exists
    assert os.path.isfile(image_file)
    # And the filesize is less than 9000 bytes
    assert image_size < 9200
<commit_msg>Changed the filesize in comment.<commit_after>import os
from datetime import datetime

from lektor._compat import iteritems


def almost_equal(a, b, e=0.00001):
    return abs(a - b) < e


def test_exif(pad):
    image = pad.root.attachments.images.get('test.jpg')
    assert image is not None

    assert image.exif

    assert almost_equal(image.exif.altitude, 779.0293)
    assert almost_equal(image.exif.aperture, 2.275)
    assert image.exif.artist is None
    assert image.exif.camera == 'Apple iPhone 6'
    assert image.exif.camera_make == 'Apple'
    assert image.exif.camera_model == 'iPhone 6'
    assert image.exif.copyright is None
    assert image.exif.created_at == datetime(2015, 12, 6, 11, 37, 38)
    assert image.exif.exposure_time == '1/33'
    assert image.exif.f == u'\u0192/2.2'
    assert almost_equal(image.exif.f_num, 2.2)
    assert image.exif.flash_info == 'Flash did not fire, compulsory flash mode'
    assert image.exif.focal_length == '4.2mm'
    assert image.exif.focal_length_35mm == '29mm'
    assert image.exif.iso == 160
    assert almost_equal(image.exif.latitude, 46.6338333)
    assert image.exif.lens == 'Apple iPhone 6 back camera 4.15mm f/2.2'
    assert image.exif.lens_make == 'Apple'
    assert image.exif.lens_model == 'iPhone 6 back camera 4.15mm f/2.2'
    assert almost_equal(image.exif.longitude, 13.4048333)
    assert image.exif.location == (image.exif.latitude, image.exif.longitude)
    assert image.exif.shutter_speed == '1/33'

    assert image.exif.documentname == 'testName'
    assert image.exif.description == 'testDescription'
    assert image.exif.is_rotated

    assert isinstance(image.exif.to_dict(), dict)

    for key, value in iteritems(image.exif.to_dict()):
        assert getattr(image.exif, key) == value


def test_image_attributes(pad):
    image = pad.root.attachments.images.get('test.jpg')
    assert image is not None

    assert image.width == 512
    assert image.height == 384
    assert image.format == 'jpeg'


def test_thumbnail_height(builder):
    builder.build_all()
    with open(os.path.join(builder.destination_path, 'index.html')) as f:
        html = f.read()

    # Thumbnail is half the original width, so its computed height is half.
    assert '<img src="./test@192.jpg" width="192" height="256">' in html

def test_thumbnail_quality(builder):
    builder.build_all()
    image_file = os.path.join(builder.destination_path, 'test@192x256_q20.jpg')
    image_size = os.path.getsize(image_file)

    # See if the image file with said quality suffix exists
    assert os.path.isfile(image_file)
    # And the filesize is less than 9200 bytes
    assert image_size < 9200

{'fraction_non_alphanumeric': 0.11466767087177555, 'fraction_numerical': 0.04368292223686688, 'mean_word_length': 3.5016949152542374, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7421153', 'n_tokens_mistral': 1982, 'n_tokens_neox': 1777, 'n_words': 446}