mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Test less generator
This commit is contained in:
parent
d4e981f916
commit
1d3e38c5dd
1 changed files with 51 additions and 2 deletions
|
|
@ -2,10 +2,12 @@
|
|||
|
||||
from mock import MagicMock
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
from pelican.generators import ArticlesGenerator
|
||||
from pelican.generators import ArticlesGenerator, LessCSSGenerator
|
||||
from pelican.settings import _DEFAULT_CONFIG
|
||||
from .support import unittest
|
||||
from .support import unittest, temporary_folder, skipIfNoExecutable
|
||||
|
||||
CUR_DIR = os.path.dirname(__file__)
|
||||
|
||||
|
|
@ -46,3 +48,50 @@ class TestArticlesGenerator(unittest.TestCase):
|
|||
elif relfilepath == "article_without_category.rst":
|
||||
self.assertEquals(article.category.name, 'Default')
|
||||
|
||||
|
||||
class TestLessCSSGenerator(unittest.TestCase):
|
||||
|
||||
LESS_CONTENT = """
|
||||
@color: #4D926F;
|
||||
|
||||
#header {
|
||||
color: @color;
|
||||
}
|
||||
h2 {
|
||||
color: @color;
|
||||
}
|
||||
"""
|
||||
|
||||
@skipIfNoExecutable('lessc')
|
||||
def test_less_compiler(self):
|
||||
|
||||
settings = _DEFAULT_CONFIG.copy()
|
||||
settings['STATIC_PATHS'] = ['static']
|
||||
settings['LESS_GENERATOR'] = True
|
||||
settings['LESS_COMPILER'] = 'lessc'
|
||||
|
||||
# we'll nest here for py < 2.7 compat
|
||||
with temporary_folder() as temp_content:
|
||||
with temporary_folder() as temp_output:
|
||||
generator = LessCSSGenerator(None, settings, temp_content,
|
||||
_DEFAULT_CONFIG['THEME'], temp_output, None)
|
||||
|
||||
# create a dummy less file
|
||||
less_dir = os.path.join(temp_content, 'static', 'css')
|
||||
less_filename = os.path.join(less_dir, 'test.less')
|
||||
|
||||
less_output = os.path.join(temp_output, 'static', 'css',
|
||||
'test.css')
|
||||
|
||||
os.makedirs(less_dir)
|
||||
with open(less_filename, 'w') as less_file:
|
||||
less_file.write(self.LESS_CONTENT)
|
||||
|
||||
generator.generate_output()
|
||||
|
||||
# we have the file ?
|
||||
self.assertTrue(os.path.exists(less_output))
|
||||
|
||||
# was it compiled ?
|
||||
self.assertIsNotNone(re.search(r'^\s+color:\s*#4D926F;$',
|
||||
open(less_output).read(), re.MULTILINE | re.IGNORECASE))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue