def test_css_top_files_ordered(self): """ Make sure that the This is only important if there are multiple settings.CSS_TOP_FILES and matches found TODO:Finish this test """ top, std, bottom = heavy_lifting.organize_css_files( self.fake_file_list) if len(top) > 1 and len(list_css_top_files()) > 1: for found_file in top: found_file_name = os.path.basename(found_file) for f_file_again in top: f_file_again_name = os.path.basename(f_file_again) if not found_file_name == f_file_again_name: if top.index(found_file) > top.index(f_file_again): self.assertGreater( list_css_top_files().index(found_file_name), list_css_top_files().index(f_file_again_name)) if top.index(found_file) < top.index(f_file_again): self.assertLess( list_css_top_files().index(found_file_name), list_css_top_files().index(f_file_again_name))
def test_css_bottom_files_belong(self): """ Make sure that all bottom files returned by the organize_css_files belong there """ top, std, bottom = heavy_lifting.organize_css_files(self.fake_file_list) for fle in bottom: self.assertIn(os.path.basename(fle), list_css_bottom_files())
def test_css_top_files_ordered(self): """ Make sure that the This is only important if there are multiple settings.CSS_TOP_FILES and matches found TODO:Finish this test """ top, std, bottom = heavy_lifting.organize_css_files(self.fake_file_list) if len(top) > 1 and len(list_css_top_files()) > 1: for found_file in top: found_file_name = os.path.basename(found_file) for f_file_again in top: f_file_again_name = os.path.basename(f_file_again) if not found_file_name == f_file_again_name: if top.index(found_file) > top.index(f_file_again): self.assertGreater(list_css_top_files().index(found_file_name), list_css_top_files().index(f_file_again_name)) if top.index(found_file) < top.index(f_file_again): self.assertLess(list_css_top_files().index(found_file_name), list_css_top_files().index(f_file_again_name))
def test_css_bottom_files_belong(self): """ Make sure that all bottom files returned by the organize_css_files belong there """ top, std, bottom = heavy_lifting.organize_css_files( self.fake_file_list) for fle in bottom: self.assertIn(os.path.basename(fle), list_css_bottom_files())
def compile_and_cache_css(css_dirs, cache_dir, app_name=None): """ Return the cache_name of the compiled file It has been compiled and written to a cache file """ css_files = [] for css_dir in css_dirs: css_files += list_media_in_dirs("css", css_dir) if not app_name: app_name = "css" timestamp = latest_timestamp(css_files) cache_name = generate_cache_name("css", timestamp, app_name) cache_fullpath = os.path.join(cache_dir, cache_name) top, mid, bottom = organize_css_files(css_files) css_files = top + mid + bottom if not os.path.isfile(cache_fullpath): css_contents = compile_files(css_files) abs_path = dirs.get_css_url() if not abs_path.endswith("/"): abs_path += "/" # remove spaces css_contents = css_contents.replace("url (", "url(") # regex an absolute path into URLs that qualify css_contents = re.sub(r'url\(("|\')?([^"\'(https?\:)(//)])([^")]+)("|\')?\)', r'url("%s\2\3")' % abs_path, css_contents) # remove any double quotes at the end of url lines css_contents = css_contents.replace("'\")","\")") if dirs.remove_old_files(): unlink_cache(cache_dir, "css", app_name) cache_file = open(cache_fullpath, "w") cache_file.write(minify.cssmin(css_contents)) cache_file.close() return cache_name