Commits

powersurge360  committed 86cbc1e

Added a few tests, will finish the rest soon.

  • Participants
  • Parent commits ba3ad08

Comments (0)

Files changed (5)

File management/commands/compilescss.py

 
 import djangosassy.utils
 
+
 class Command(BaseCommand):
     '''A command that will pull down any files in blog/scss and compile it to
     css.

File models.py

Empty file added.

File templatetags/compilescss.py

 
 register = template.Library()
 
+
 @register.tag
 def compile_scss(parser, token):
     app, scss_file = token.split_contents()[1:]
 
     return CompiledScssNode(app, scss_file)
 
+
 class CompiledScssNode(template.Node):
     def __init__(self, app, scss_file):
         self.app = app[1:-1]
 
     def render(self, context):
         module = __import__(self.app)
-        
+
         directories = djangosassy.utils.build_paths(
             os.path.realpath(
                 os.path.dirname(getattr(module, "__file__"))
+import os
+import time
+
+from django import test
+
+import utils
+
+
+class UtilsTest(test.TestCase):
+    css_root = os.path.join(
+        os.path.join(utils.DJANGOSASSY_PATH, 'static'),
+        'styles'
+    )
+
+    scss_root = utils.SCSS_ROOT
+
+    def setUp(self):
+        self.scss_file = os.path.join(self.scss_root, 'test.scss') 
+        self.css_file = os.path.join(self.css_root, 'test.css')
+
+        with file(self.scss_file, 'w') as scss_file:
+            scss_file.write(' ')
+
+        with file(self.css_file, 'w') as css_file:
+            css_file.write(' ')
+
+    def tearDown(self):
+        os.remove(self.scss_file)
+        os.remove(self.css_file)
+
+    def test_compile_style_old(self):
+        original_modified_time = os.stat(self.css_file).st_mtime
+
+        file_name = utils.compile_style(self.css_file, self.css_root)
+        full_path = os.path.join(self.css_root, file_name)
+
+        new_modified_time = os.stat(full_path).st_mtime
+
+        self.assertEqual(original_modified_time, new_modified_time)
+
+    def test_compile_style_new(self):
+        time.sleep(.5)
+        os.utime(self.scss_file, None)
+
+        original_modified_time = os.stat(self.css_file).st_mtime
+
+        file_name = utils.compile_style(self.css_file, self.css_root)
+        full_path = os.path.join(self.css_root, file_name)
+
+        new_modified_time = os.stat(full_path).st_mtime
+
+        self.assertNotEqual(original_modified_time, new_modified_time)
+
+    def test_compile_styles(self):
+        pass
+
+    def test_create_directories(self):
+        pass
+
+    def test_build_paths(self):
+        pass
 import os
 import glob
-import time
 
 import scss
 
 import djangosassy
 DJANGOSASSY_PATH = os.path.dirname(djangosassy.__file__)
+SCSS_ROOT = os.path.join(DJANGOSASSY_PATH, 'scss')
 
-scss.LOAD_PATHS = scss.LOAD_PATHS+","+os.path.join(DJANGOSASSY_PATH, 'scss')
+scss.LOAD_PATHS = (
+    scss.LOAD_PATHS +
+    "," +
+    SCSS_ROOT
+)
 
 compiler = scss.Scss()
 
+
 def compile_styles(scss_dir, css_dir):
     '''Compiles a number of scss files into css files given the scss directory
     and the css directory. Will only compile in the root, other files are
     considered to be 'library' files.
     '''
-    for file_name in glob.glob(os.path.join(scss_dir, '*.scss')):
-        # If the file has not been modified since last compiled, skip.
+    file_names = glob.glob(os.path.join(scss_dir, '*.scss'))
 
-        compile_style(file_name, css_dir)
+    return [compile_style(file_name, css_dir) for file_name in file_names]
+
 
 def compile_style(file_name, css_dir):
     '''Compiles a style for a given scss file and sticks it in the given
         css_file.write(compiler.compile(scss_file.read()))
 
     return css_file_name
-    
+
 
 def create_directories(directory_dict):
     '''Creates all the directories necessary, passes on failures (assumes
         except OSError:
             pass
 
+
 def build_paths(module_path):
     '''Builds a path dictionary for the other functions to use.'''
     directories = {}