diff options
author | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2014-08-27 16:10:10 -0700 |
---|---|---|
committer | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2014-08-27 16:10:10 -0700 |
commit | a78bb715cab3a9686440a9963b498eeda3aa869b (patch) | |
tree | d67f76f05ca4c2bbaf6800b4e8b3a5062d1d2501 | |
parent | 6dad0e9ed0a651c43564ea71d0a16624cc56a2fd (diff) | |
download | pyscss-a78bb715cab3a9686440a9963b498eeda3aa869b.tar.gz |
Move Compass to an extension.
-rw-r--r-- | scss/compiler.py | 3 | ||||
-rw-r--r-- | scss/extension/bootstrap.py | 4 | ||||
-rw-r--r-- | scss/extension/compass/__init__.py | 32 | ||||
-rw-r--r-- | scss/extension/compass/gradients.py (renamed from scss/functions/compass/gradients.py) | 29 | ||||
-rw-r--r-- | scss/extension/compass/helpers.py (renamed from scss/functions/compass/helpers.py) | 95 | ||||
-rw-r--r-- | scss/extension/compass/images.py (renamed from scss/functions/compass/images.py) | 30 | ||||
-rw-r--r-- | scss/extension/compass/layouts.py (renamed from scss/functions/compass/layouts.py) | 0 | ||||
-rw-r--r-- | scss/extension/compass/sprites.py (renamed from scss/functions/compass/sprites.py) | 37 | ||||
-rw-r--r-- | scss/functions/compass/__init__.py | 2 | ||||
-rw-r--r-- | scss/legacy.py | 4 | ||||
-rw-r--r-- | scss/tests/functions/compass/test_gradients.py | 6 | ||||
-rw-r--r-- | scss/tests/functions/compass/test_helpers.py | 17 | ||||
-rw-r--r-- | scss/tests/functions/compass/test_images.py | 26 |
13 files changed, 137 insertions, 148 deletions
diff --git a/scss/compiler.py b/scss/compiler.py index 6afd149..0530efe 100644 --- a/scss/compiler.py +++ b/scss/compiler.py @@ -24,8 +24,7 @@ from scss.expression import Calculator from scss.extension import Extension from scss.extension.core import CoreExtension from scss.extension import NamespaceAdapterExtension -from scss.functions import COMPASS_LIBRARY -from scss.functions.compass.sprites import sprite_map +from scss.extension.compass.sprites import sprite_map from scss.rule import BlockAtRuleHeader from scss.rule import Namespace from scss.rule import RuleAncestry diff --git a/scss/extension/bootstrap.py b/scss/extension/bootstrap.py index 76cdb02..bd1b75e 100644 --- a/scss/extension/bootstrap.py +++ b/scss/extension/bootstrap.py @@ -4,9 +4,9 @@ from __future__ import unicode_literals from __future__ import division from scss.extension import Extension +from scss.extension.compass.helpers import _font_url +from scss.extension.compass.images import _image_url from scss.namespace import Namespace -from scss.functions.compass.helpers import _font_url -from scss.functions.compass.images import _image_url class BootstrapExtension(Extension): diff --git a/scss/extension/compass/__init__.py b/scss/extension/compass/__init__.py new file mode 100644 index 0000000..daed9ef --- /dev/null +++ b/scss/extension/compass/__init__.py @@ -0,0 +1,32 @@ +"""Extension providing Compass support.""" +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +from scss.extension import Extension +from scss.namespace import Namespace + + +# Global cache of image sizes, shared between sprites and images libraries. +# TODO put on the extension, somehow. +_image_size_cache = {} + + +# Import all our children to register their functions +from .gradients import gradients_namespace +from .helpers import helpers_namespace +from .images import images_namespace +from .sprites import sprites_namespace + + +class CompassExtension(Extension): + name = 'compass' + namespace = Namespace.derive_from( + gradients_namespace, + helpers_namespace, + images_namespace, + sprites_namespace, + ) + + +__all__ = ['CompassExtension'] diff --git a/scss/functions/compass/gradients.py b/scss/extension/compass/gradients.py index 2d92ba5..81edbfd 100644 --- a/scss/functions/compass/gradients.py +++ b/scss/extension/compass/gradients.py @@ -10,18 +10,15 @@ import logging import six -from scss.functions.library import FunctionLibrary -from scss.functions.compass.helpers import opposite_position, position +from .helpers import opposite_position, position +from scss.namespace import Namespace from scss.types import Color, List, Number, String from scss.util import escape, split_params, to_float, to_str log = logging.getLogger(__name__) +ns = gradients_namespace = Namespace() +__all__ = ['gradients_namespace'] -COMPASS_GRADIENTS_LIBRARY = FunctionLibrary() -register = COMPASS_GRADIENTS_LIBRARY.register - - -# ------------------------------------------------------------------------------ def __color_stops(percentages, *args): if len(args) == 1: @@ -107,7 +104,7 @@ def _render_standard_color_stops(color_stops): return List(pairs, use_comma=True) -@register('grad-color-stops') +@ns.declare def grad_color_stops(*args): args = List.from_maybe_starargs(args) color_stops = __color_stops(True, *args) @@ -119,7 +116,7 @@ def __grad_end_position(radial, color_stops): return __grad_position(-1, 100, radial, color_stops) -@register('grad-point') +@ns.declare def grad_point(*p): pos = set() hrz = vrt = Number(0.5, '%') @@ -146,13 +143,13 @@ def __grad_position(index, default, radial, color_stops): return stops -@register('grad-end-position') +@ns.declare def grad_end_position(*color_stops): color_stops = __color_stops(False, *color_stops) return Number(__grad_end_position(False, color_stops)) -@register('color-stops') +@ns.declare def color_stops(*args): args = List.from_maybe_starargs(args) color_stops = __color_stops(False, *args) @@ -160,7 +157,7 @@ def color_stops(*args): return String.unquoted(ret) -@register('color-stops-in-percentages') +@ns.declare def color_stops_in_percentages(*args): args = List.from_maybe_starargs(args) color_stops = __color_stops(True, *args) @@ -222,7 +219,7 @@ def _get_gradient_color_stops(args): # 4. fixed to use a custom type instead of monkeypatching -@register('radial-gradient') +@ns.declare def radial_gradient(*args): args = List.from_maybe_starargs(args) @@ -305,7 +302,7 @@ def radial_gradient(*args): return ret -@register('linear-gradient') +@ns.declare def linear_gradient(*args): args = List.from_maybe_starargs(args) @@ -365,7 +362,7 @@ def linear_gradient(*args): return ret -@register('radial-svg-gradient') +@ns.declare def radial_svg_gradient(*args): args = List.from_maybe_starargs(args) color_stops = args @@ -382,7 +379,7 @@ def radial_svg_gradient(*args): return String.unquoted(inline) -@register('linear-svg-gradient') +@ns.declare def linear_svg_gradient(*args): args = List.from_maybe_starargs(args) color_stops = args diff --git a/scss/functions/compass/helpers.py b/scss/extension/compass/helpers.py index 2cbb94b..4abb4fe 100644 --- a/scss/functions/compass/helpers.py +++ b/scss/extension/compass/helpers.py @@ -14,16 +14,14 @@ import os.path import six from scss import config -from scss.functions.library import FunctionLibrary +from scss.namespace import Namespace from scss.types import Boolean, List, Null, Number, String from scss.util import escape, to_str, getmtime, make_data_url import re log = logging.getLogger(__name__) - - -COMPASS_HELPERS_LIBRARY = FunctionLibrary() -register = COMPASS_HELPERS_LIBRARY.register +ns = helpers_namespace = Namespace() +__all__ = ['gradients_namespace'] FONT_TYPES = { 'woff': 'woff', @@ -53,7 +51,7 @@ def add_cache_buster(url, mtime): # ------------------------------------------------------------------------------ # Data manipulation -@register('blank') +@ns.declare def blank(*objs): """Returns true when the object is false, an empty string, or an empty list""" for o in objs: @@ -72,7 +70,7 @@ def blank(*objs): return Boolean(True) -@register('compact') +@ns.declare def compact(*args): """Returns a new list after removing any non-true values""" use_comma = True @@ -86,7 +84,7 @@ def compact(*args): ) -@register('reject') +@ns.declare def reject(lst, *values): """Removes the given values from the list""" lst = List.from_maybe(lst) @@ -99,7 +97,7 @@ def reject(lst, *values): return List(ret, use_comma=lst.use_comma) -@register('first-value-of') +@ns.declare def first_value_of(*args): if len(args) == 1 and isinstance(args[0], String): first = args[0].value.split()[0] @@ -112,12 +110,12 @@ def first_value_of(*args): return Null() -@register('-compass-list') +@ns.declare_alias('-compass-list') def dash_compass_list(*args): return List.from_maybe_starargs(args) -@register('-compass-space-list') +@ns.declare_alias('-compass-space-list') def dash_compass_space_list(*lst): """ If the argument is a list, it will return a new list that is space delimited @@ -128,7 +126,7 @@ def dash_compass_space_list(*lst): return ret -@register('-compass-slice', 3) +@ns.declare_alias('-compass-slice') def dash_compass_slice(lst, start_index, end_index=None): start_index = Number(start_index).value end_index = Number(end_index).value if end_index is not None else None @@ -144,7 +142,7 @@ def dash_compass_slice(lst, start_index, end_index=None): # ------------------------------------------------------------------------------ # Property prefixing -@register('prefixed') +@ns.declare def prefixed(prefix, *args): to_fnct_str = 'to_' + to_str(prefix).replace('-', '_') for arg in List.from_maybe_starargs(args): @@ -153,7 +151,7 @@ def prefixed(prefix, *args): return Boolean(False) -@register('prefix') +@ns.declare def prefix(prefix, *args): to_fnct_str = 'to_' + to_str(prefix).replace('-', '_') args = list(args) @@ -175,47 +173,47 @@ def prefix(prefix, *args): return List.maybe_new(args, use_comma=True) -@register('-moz') +@ns.declare_alias('-moz') def dash_moz(*args): return prefix('_moz', *args) -@register('-svg') +@ns.declare_alias('-svg') def dash_svg(*args): return prefix('_svg', *args) -@register('-css2') +@ns.declare_alias('-css2') def dash_css2(*args): return prefix('_css2', *args) -@register('-pie') +@ns.declare_alias('-pie') def dash_pie(*args): return prefix('_pie', *args) -@register('-webkit') +@ns.declare_alias('-webkit') def dash_webkit(*args): return prefix('_webkit', *args) -@register('-owg') +@ns.declare_alias('-owg') def dash_owg(*args): return prefix('_owg', *args) -@register('-khtml') +@ns.declare_alias('-khtml') def dash_khtml(*args): return prefix('_khtml', *args) -@register('-ms') +@ns.declare_alias('-ms') def dash_ms(*args): return prefix('_ms', *args) -@register('-o') +@ns.declare_alias('-o') def dash_o(*args): return prefix('_o', *args) @@ -223,7 +221,7 @@ def dash_o(*args): # ------------------------------------------------------------------------------ # Selector generation -@register('append-selector', 2) +@ns.declare def append_selector(selector, to_append): if isinstance(selector, List): lst = selector.value @@ -264,7 +262,7 @@ _elements_of_type = { } -@register('elements-of-type', 1) +@ns.declare def elements_of_type(display): d = String.unquoted(display) ret = _elements_of_type.get(d.value, None) @@ -273,8 +271,7 @@ def elements_of_type(display): return List(map(String, ret), use_comma=True) -@register('enumerate', 3) -@register('enumerate', 4) +@ns.declare def enumerate_(prefix, frm, through, separator='-'): separator = String.unquoted(separator).value try: @@ -302,12 +299,8 @@ def enumerate_(prefix, frm, through, separator='-'): return List(ret, use_comma=True) -@register('headers', 0) -@register('headers', 1) -@register('headers', 2) -@register('headings', 0) -@register('headings', 1) -@register('headings', 2) +@ns.declare_alias('headings') +@ns.declare def headers(frm=None, to=None): if frm and to is None: if isinstance(frm, String) and frm.value.lower() == 'all': @@ -332,7 +325,7 @@ def headers(frm=None, to=None): return List(ret, use_comma=True) -@register('nest') +@ns.declare def nest(*arguments): if isinstance(arguments[0], List): lst = arguments[0] @@ -393,8 +386,7 @@ def nest(*arguments): # This isn't actually from Compass, but it's just a shortcut for enumerate(). # DEVIATION: allow reversed ranges (range() uses enumerate() which allows reversed values, like '@for .. from .. through') -@register('range', 1) -@register('range', 2) +@ns.declare def range_(frm, through=None): if through is None: through = frm @@ -457,12 +449,12 @@ def _position(opposite, positions): return List(ret, use_comma=False).maybe() -@register('position') +@ns.declare def position(p): return _position(False, p) -@register('opposite-position') +@ns.declare def opposite_position(p): return _position(True, p) @@ -470,18 +462,17 @@ def opposite_position(p): # ------------------------------------------------------------------------------ # Math -@register('pi', 0) +@ns.declare def pi(): return Number(math.pi) -@register('e', 0) +@ns.declare def e(): return Number(math.e) -@register('log', 1) -@register('log', 2) +@ns.declare def log_(number, base=None): if not isinstance(number, Number): raise TypeError("Expected number, got %r" % (number,)) @@ -503,15 +494,15 @@ def log_(number, base=None): return Number(ret) -@register('pow', 2) +@ns.declare def pow(number, exponent): return number ** exponent -COMPASS_HELPERS_LIBRARY.add(Number.wrap_python_function(math.sqrt), 'sqrt', 1) -COMPASS_HELPERS_LIBRARY.add(Number.wrap_python_function(math.sin), 'sin', 1) -COMPASS_HELPERS_LIBRARY.add(Number.wrap_python_function(math.cos), 'cos', 1) -COMPASS_HELPERS_LIBRARY.add(Number.wrap_python_function(math.tan), 'tan', 1) +ns.set_function('sqrt', 1, Number.wrap_python_function(math.sqrt)) +ns.set_function('sin', 1, Number.wrap_python_function(math.sin)) +ns.set_function('cos', 1, Number.wrap_python_function(math.cos)) +ns.set_function('tan', 1, Number.wrap_python_function(math.tan)) # ------------------------------------------------------------------------------ @@ -599,8 +590,7 @@ def _font_files(args, inline): return List(fonts, separator=',') -@register('font-url', 1) -@register('font-url', 2) +@ns.declare def font_url(path, only_path=False, cache_buster=True): """ Generates a path to an asset found relative to the project's font directory. @@ -610,12 +600,12 @@ def font_url(path, only_path=False, cache_buster=True): return _font_url(path, only_path, cache_buster, False) -@register('font-files') +@ns.declare def font_files(*args): return _font_files(args, inline=False) -@register('inline-font-files') +@ns.declare def inline_font_files(*args): return _font_files(args, inline=True) @@ -623,8 +613,7 @@ def inline_font_files(*args): # ------------------------------------------------------------------------------ # External stylesheets -@register('stylesheet-url', 1) -@register('stylesheet-url', 2) +@ns.declare def stylesheet_url(path, only_path=False, cache_buster=True): """ Generates a path to an asset found relative to the project's css directory. diff --git a/scss/functions/compass/images.py b/scss/extension/compass/images.py index e9b4e6c..a3721fb 100644 --- a/scss/functions/compass/images.py +++ b/scss/extension/compass/images.py @@ -10,10 +10,10 @@ import os.path import six from six.moves import xrange +from . import _image_size_cache +from .helpers import add_cache_buster from scss import config -from scss.functions.compass import _image_size_cache -from scss.functions.compass.helpers import add_cache_buster -from scss.functions.library import FunctionLibrary +from scss.namespace import Namespace from scss.types import Color, List, Number, String from scss.util import escape, getmtime, make_data_url, make_filename_hash @@ -26,12 +26,9 @@ except ImportError: Image = None log = logging.getLogger(__name__) +ns = images_namespace = Namespace() +__all__ = ['gradients_namespace'] -COMPASS_IMAGES_LIBRARY = FunctionLibrary() -register = COMPASS_IMAGES_LIBRARY.register - - -# ------------------------------------------------------------------------------ def _images_root(): return config.STATIC_ROOT if config.IMAGES_ROOT is None else config.IMAGES_ROOT @@ -188,11 +185,7 @@ def _image_url(path, only_path=False, cache_buster=True, dst_color=None, src_col return String.unquoted(url) -@register('inline-image', 1) -@register('inline-image', 2) -@register('inline-image', 3) -@register('inline-image', 4) -@register('inline-image', 5) +@ns.declare def inline_image(image, mime_type=None, dst_color=None, src_color=None, spacing=None, collapse_x=None, collapse_y=None): """ Embeds the contents of a file directly inside your stylesheet, eliminating @@ -203,12 +196,7 @@ def inline_image(image, mime_type=None, dst_color=None, src_color=None, spacing= return _image_url(image, False, False, dst_color, src_color, True, mime_type, spacing, collapse_x, collapse_y) -@register('image-url', 1) -@register('image-url', 2) -@register('image-url', 3) -@register('image-url', 4) -@register('image-url', 5) -@register('image-url', 6) +@ns.declare def image_url(path, only_path=False, cache_buster=True, dst_color=None, src_color=None, spacing=None, collapse_x=None, collapse_y=None): """ Generates a path to an asset found relative to the project's images @@ -219,7 +207,7 @@ def image_url(path, only_path=False, cache_buster=True, dst_color=None, src_colo return _image_url(path, only_path, cache_buster, dst_color, src_color, False, None, spacing, collapse_x, collapse_y) -@register('image-width', 1) +@ns.declare def image_width(image): """ Returns the width of the image found at the path supplied by `image` @@ -253,7 +241,7 @@ def image_width(image): return Number(width, 'px') -@register('image-height', 1) +@ns.declare def image_height(image): """ Returns the height of the image found at the path supplied by `image` diff --git a/scss/functions/compass/layouts.py b/scss/extension/compass/layouts.py index ae086ce..ae086ce 100644 --- a/scss/functions/compass/layouts.py +++ b/scss/extension/compass/layouts.py diff --git a/scss/functions/compass/sprites.py b/scss/extension/compass/sprites.py index 908adcd..d3fea1d 100644 --- a/scss/functions/compass/sprites.py +++ b/scss/extension/compass/sprites.py @@ -30,21 +30,20 @@ except ImportError: from six.moves import xrange +from . import _image_size_cache +from .layouts import PackedSpritesLayout, HorizontalSpritesLayout, VerticalSpritesLayout, DiagonalSpritesLayout from scss import config -from scss.functions.compass import _image_size_cache -from scss.functions.compass.layouts import PackedSpritesLayout, HorizontalSpritesLayout, VerticalSpritesLayout, DiagonalSpritesLayout -from scss.functions.library import FunctionLibrary +from scss.namespace import Namespace from scss.types import Color, List, Number, String, Boolean from scss.util import escape, getmtime, make_data_url, make_filename_hash log = logging.getLogger(__name__) +ns = sprites_namespace = Namespace() +__all__ = ['gradients_namespace'] MAX_SPRITE_MAPS = 4096 KEEP_SPRITE_MAPS = int(MAX_SPRITE_MAPS * 0.8) -COMPASS_SPRITES_LIBRARY = FunctionLibrary() -register = COMPASS_SPRITES_LIBRARY.register - # ------------------------------------------------------------------------------ # Compass-like functionality for sprites and images @@ -93,7 +92,7 @@ def alpha_composite(im1, im2, offset=None, box=None, opacity=1): return im1 -@register('sprite-map') +@ns.declare def sprite_map(g, **kwargs): """ Generates a sprite map from the files matching the glob pattern. @@ -417,7 +416,7 @@ def sprite_map(g, **kwargs): return asset -@register('sprite-map-name', 1) +@ns.declare def sprite_map_name(map): """ Returns the name of a sprite map The name is derived from the folder than @@ -432,7 +431,7 @@ def sprite_map_name(map): return String.unquoted('') -@register('sprite-file', 2) +@ns.declare def sprite_file(map, sprite): """ Returns the relative path (from the images directory) to the original file @@ -452,23 +451,20 @@ def sprite_file(map, sprite): return String.unquoted('') -@register('sprites', 1) -@register('sprite-names', 1) +@ns.declare_alias('sprite-names') +@ns.declare def sprites(map, remove_suffix=False): map = map.render() sprite_map = sprite_maps.get(map, {}) return List([String.unquoted(s) for s in sorted(set(s.rsplit('-', 1)[0] if remove_suffix else s for s in sprite_map if not s.startswith('*')))]) -@register('sprite-classes', 1) +@ns.declare def sprite_classes(map): return sprites(map, True) -@register('sprite', 2) -@register('sprite', 3) -@register('sprite', 4) -@register('sprite', 5) +@ns.declare def sprite(map, sprite, offset_x=None, offset_y=None, cache_buster=True): """ Returns the image and background position for use in a single shorthand @@ -497,8 +493,7 @@ def sprite(map, sprite, offset_x=None, offset_y=None, cache_buster=True): return List([Number(0), Number(0)]) -@register('sprite-url', 1) -@register('sprite-url', 2) +@ns.declare def sprite_url(map, cache_buster=True): """ Returns a url to the sprite image. @@ -516,7 +511,7 @@ def sprite_url(map, cache_buster=True): return String.unquoted('') -@register('has-sprite', 2) +@ns.declare def has_sprite(map, sprite): map = map.render() sprite_map = sprite_maps.get(map) @@ -527,9 +522,7 @@ def has_sprite(map, sprite): return Boolean(bool(sprite)) -@register('sprite-position', 2) -@register('sprite-position', 3) -@register('sprite-position', 4) +@ns.declare def sprite_position(map, sprite, offset_x=None, offset_y=None): """ Returns the position for the original image in the sprite. diff --git a/scss/functions/compass/__init__.py b/scss/functions/compass/__init__.py deleted file mode 100644 index 73cb9df..0000000 --- a/scss/functions/compass/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# Global cache of image sizes, shared between sprites and images libraries. -_image_size_cache = {} diff --git a/scss/legacy.py b/scss/legacy.py index 90016a2..c4fb984 100644 --- a/scss/legacy.py +++ b/scss/legacy.py @@ -10,9 +10,9 @@ import scss.config as config from scss.expression import Calculator from scss.extension.bootstrap import BootstrapExtension from scss.extension.core import CoreExtension +from scss.extension.compass import CompassExtension from scss.extension.extra import ExtraExtension from scss.extension.fonts import FontsExtension -from scss.functions import COMPASS_LIBRARY from scss.namespace import Namespace from scss.scss_meta import ( BUILD_INFO, PROJECT, VERSION, REVISION, URL, AUTHOR, AUTHOR_EMAIL, LICENSE, @@ -128,7 +128,7 @@ class Scss(object): CoreExtension, ExtraExtension, FontsExtension, - Namespace(functions=COMPASS_LIBRARY), + CompassExtension, BootstrapExtension, ], search_path=search_paths, diff --git a/scss/tests/functions/compass/test_gradients.py b/scss/tests/functions/compass/test_gradients.py index a141740..f93e335 100644 --- a/scss/tests/functions/compass/test_gradients.py +++ b/scss/tests/functions/compass/test_gradients.py @@ -3,7 +3,8 @@ from __future__ import absolute_import from __future__ import unicode_literals from scss.expression import Calculator -from scss.functions.compass.gradients import COMPASS_GRADIENTS_LIBRARY, linear_gradient +from scss.extension.compass.gradients import gradients_namespace +from scss.extension.compass.gradients import linear_gradient from scss.rule import Namespace from scss.types import String, List, Number, Color @@ -12,8 +13,7 @@ import pytest @pytest.fixture def calc(): - ns = Namespace(functions=COMPASS_GRADIENTS_LIBRARY) - return Calculator(ns).evaluate_expression + return Calculator(gradients_namespace).evaluate_expression def test_linear_gradient(): diff --git a/scss/tests/functions/compass/test_helpers.py b/scss/tests/functions/compass/test_helpers.py index a0615aa..bbcaaf0 100644 --- a/scss/tests/functions/compass/test_helpers.py +++ b/scss/tests/functions/compass/test_helpers.py @@ -12,24 +12,21 @@ Ruby code. from __future__ import absolute_import from __future__ import unicode_literals +import os + +from scss import config from scss.expression import Calculator -from scss.functions.compass.helpers import COMPASS_HELPERS_LIBRARY +from scss.extension.compass.helpers import helpers_namespace from scss.rule import Namespace - import pytest -from scss import config -import os -from _pytest.monkeypatch import monkeypatch -xfail = pytest.mark.xfail # TODO many of these tests could also stand to test for failure cases @pytest.fixture def calc(): - ns = Namespace(functions=COMPASS_HELPERS_LIBRARY) - return Calculator(ns).evaluate_expression + return Calculator(helpers_namespace).evaluate_expression # ------------------------------------------------------------------------------ @@ -179,12 +176,12 @@ def test_font_files(calc): # inline-font-files -def test_inline_font_files(calc): +def test_inline_font_files(calc, monkeypatch): """ @author: funvit @note: adapted from compass / test / units / sass_extensions_test.rb """ - monkeypatch().setattr(config, 'FONTS_ROOT', os.path.join(config.PROJECT_ROOT, 'tests/files/fonts')) + monkeypatch.setattr(config, 'FONTS_ROOT', os.path.join(config.PROJECT_ROOT, 'tests/files/fonts')) with open(os.path.join(config.PROJECT_ROOT, 'tests/files/fonts/bgrove.base64.txt'), 'r') as f: font_base64 = ''.join((f.readlines())) diff --git a/scss/tests/functions/compass/test_images.py b/scss/tests/functions/compass/test_images.py index 1478fa7..dc1d6e2 100644 --- a/scss/tests/functions/compass/test_images.py +++ b/scss/tests/functions/compass/test_images.py @@ -12,25 +12,21 @@ Ruby code. from __future__ import absolute_import from __future__ import unicode_literals -from scss.expression import Calculator -from scss.functions.compass.images import COMPASS_IMAGES_LIBRARY -from scss.rule import Namespace - +import os +import sys import pytest + from scss import config -import os -import sys -from _pytest.monkeypatch import monkeypatch -xfail = pytest.mark.xfail +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 +# TODO many of these tests could also stand to test for failure cases @pytest.fixture def calc(): - ns = Namespace(functions=COMPASS_IMAGES_LIBRARY) - return Calculator(ns).evaluate_expression + return Calculator(images_namespace).evaluate_expression def test_image_url(calc): @@ -40,8 +36,8 @@ def test_image_url(calc): # inline-image -def test_inline_image(calc): - monkeypatch().setattr(config, 'IMAGES_ROOT', os.path.join(config.PROJECT_ROOT, 'tests/files/images')) +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() @@ -49,8 +45,8 @@ def test_inline_image(calc): @pytest.mark.skipif(sys.platform == 'win32', reason='cur mimetype is defined on windows') -def test_inline_cursor(calc): - monkeypatch().setattr(config, 'IMAGES_ROOT', os.path.join(config.PROJECT_ROOT, 'tests/files/cursors')) +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() |