summaryrefslogtreecommitdiff
path: root/scss/tests/functions/compass/test_images.py
blob: dc1d6e217770b280b87b6b4d44c9c8abfdbc494c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Tests for the Compass images functions.

Not all of Compass is implemented, and the arrangement of Compass functions
doesn't exactly match the arrangement in the original documentation.
Regardless, this is a good starting place:

http://compass-style.org/reference/compass/helpers/

Some functions appear to be undocumented, but nonetheless are part of Compass's
Ruby code.
"""
from __future__ import absolute_import
from __future__ import unicode_literals

import os
import sys

import pytest

from scss import config
from scss.expression import Calculator
from scss.extension.compass.images import images_namespace


# TODO many of these tests could also stand to test for failure cases

@pytest.fixture
def calc():
    return Calculator(images_namespace).evaluate_expression


def test_image_url(calc):
    # nb: config.IMAGES_URL is None and defaults to this
    images_url = config.STATIC_URL
    assert calc('image-url("/some_path.jpg")').render() == 'url({0}some_path.jpg)'.format(images_url)


# inline-image
def test_inline_image(calc, monkeypatch):
    monkeypatch.setattr(config, 'IMAGES_ROOT', os.path.join(config.PROJECT_ROOT, 'tests/files/images'))

    with open(os.path.join(config.PROJECT_ROOT, 'tests/files/images/test-qr.base64.txt'), 'r') as f:
        font_base64 = f.read()
    assert 'url(data:image/png;base64,%s)' % font_base64 == calc('inline_image("/test-qr.png")').render()


@pytest.mark.skipif(sys.platform == 'win32', reason='cur mimetype is defined on windows')
def test_inline_cursor(calc, monkeypatch):
    monkeypatch.setattr(config, 'IMAGES_ROOT', os.path.join(config.PROJECT_ROOT, 'tests/files/cursors'))

    with open(os.path.join(config.PROJECT_ROOT, 'tests/files/cursors/fake.base64.txt'), 'r') as f:
        font_base64 = f.read()
    assert 'url(data:image/cur;base64,%s)' % font_base64 == calc('inline_image("/fake.cur")').render()