def test_list(self): finder = FileSystemFinder([ASSETS_DIR]) self.assertItemsEqual(finder.list('js/templates/*'), ( ('js/templates/readme.txt', os.path.join(ASSETS_DIR, 'js/templates/readme.txt')), ('js/templates/a.js.handlebars', os.path.join(ASSETS_DIR, 'js/templates/a.js.handlebars')), ('js/templates/b.js.handlebars', os.path.join(ASSETS_DIR, 'js/templates/b.js.handlebars')), ('js/templates/c.js.handlebars', os.path.join(ASSETS_DIR, 'js/templates/c.js.handlebars')), ))
def test_find_all_if_does_not_exist(self): finder = FileSystemFinder(('/first', '/second', '/third')) finder.find_location = Mock(return_value=False) self.assertEqual(list(finder.find_all('js/script.js')), []) self.assertEqual(finder.find_location.call_args_list, [ (('/first', 'js/script.js'), {}), (('/second', 'js/script.js'), {}), (('/third', 'js/script.js'), {})])
def test_find_all_if_does_not_exist(self): finder = FileSystemFinder(('/first', '/second', '/third')) finder.find_location = Mock(return_value=False) self.assertEqual(list(finder.find_all('js/script.js')), []) self.assertEqual(finder.find_location.call_args_list, [(('/first', 'js/script.js'), {}), (('/second', 'js/script.js'), {}), (('/third', 'js/script.js'), {})])
def test_find_all_if_does_not_exist(self): finder = FileSystemFinder(("/first", "/second", "/third")) finder.find_location = Mock(return_value=False) self.assertEqual(list(finder.find_all("js/script.js")), []) self.assertEqual( finder.find_location.call_args_list, [(("/first", "js/script.js"), {}), (("/second", "js/script.js"), {}), (("/third", "js/script.js"), {})], )
def test_find(self): finder = FileSystemFinder([ASSETS_DIR]) self.assertItemsEqual( finder.list("js/templates"), ( ("js/templates/readme.txt", os.path.join(ASSETS_DIR, "js/templates/readme.txt")), ("js/templates/a.js.handlebars", os.path.join(ASSETS_DIR, "js/templates/a.js.handlebars")), ("js/templates/b.js.handlebars", os.path.join(ASSETS_DIR, "js/templates/b.js.handlebars")), ("js/templates/c.js.handlebars", os.path.join(ASSETS_DIR, "js/templates/c.js.handlebars")), ), )
def test_find_all_if_exists(self): def find_location(root, path): if root != "/first": return os.path.join(root, path) finder = FileSystemFinder(("/first", "/second", "/third")) finder.find_location = Mock(side_effect=find_location) paths = list(finder.find_all("js/script.js")) self.assertEqual(paths, ["/second/js/script.js", "/third/js/script.js"]) self.assertEqual( finder.find_location.call_args_list, [(("/first", "js/script.js"), {}), (("/second", "js/script.js"), {}), (("/third", "js/script.js"), {})], )
def test_find_all_if_exists(self): def find_location(root, path): if root != '/first': return os.path.join(root, path) finder = FileSystemFinder(('/first', '/second', '/third')) finder.find_location = Mock(side_effect=find_location) paths = list(finder.find_all('js/script.js')) self.assertEqual(paths, ['/second/js/script.js', '/third/js/script.js']) self.assertEqual(finder.find_location.call_args_list, [ (('/first', 'js/script.js'), {}), (('/second', 'js/script.js'), {}), (('/third', 'js/script.js'), {})])
def test_find_all_if_exists(self): def find_location(root, path): if root != '/first': return os.path.join(root, path) finder = FileSystemFinder(('/first', '/second', '/third')) finder.find_location = Mock(side_effect=find_location) paths = list(finder.find_all('js/script.js')) self.assertEqual(paths, ['/second/js/script.js', '/third/js/script.js']) self.assertEqual(finder.find_location.call_args_list, [(('/first', 'js/script.js'), {}), (('/second', 'js/script.js'), {}), (('/third', 'js/script.js'), {})])
def setUp(self): self.compiler = SASSCompiler() self.env = Environment(root=OUTPUT_DIR, public_assets=(r'.*\.css', ), fingerprinting=False) self.env.finders.register(FileSystemFinder([SCSS_DIR])) self.env.compilers.register('.scss', self.compiler.as_handler()) self.env.register_defaults() self.env.save()
def test_find_if_exists(self): finder = FileSystemFinder(('/first', '/second', '/third')) finder.find_all = Mock(return_value=('/second/js/script.js', '/third/js/script.js')) self.assertEqual(finder.find('js/script.js'), '/second/js/script.js') finder.find_all.assert_called_once_with('js/script.js')
def test_find_location_if_does_not_exist(self, exists): exists.return_value = False finder = FileSystemFinder(('/assets', )) self.assertIsNone(finder.find_location('/assets', 'js/script.js')) exists.assert_called_once_with('/assets/js/script.js')
def test_find_location_if_exists(self, exists): exists.return_value = True finder = FileSystemFinder(('/assets', )) location = finder.find_location('/assets', 'js/script.js') self.assertEqual(location, '/assets/js/script.js') exists.assert_called_once_with('/assets/js/script.js')
def test_if_directories_is_not_iterable(self): with self.assertRaises(ImproperlyConfigured): finder = FileSystemFinder('/first')
def test_initialization(self): finder = FileSystemFinder(('/first', '/second', '/third', '/first')) self.assertEqual(finder.locations, ['/first', '/second', '/third'])
def get_default_finder(self, app): return FileSystemFinder(directories=(self.get_assets_folder(app), ))
def test_find_if_exists(self): finder = FileSystemFinder(("/first", "/second", "/third")) finder.find_all = Mock(return_value=("/second/js/script.js", "/third/js/script.js")) self.assertEqual(finder.find("js/script.js"), "/second/js/script.js") finder.find_all.assert_called_once_with("js/script.js")
path = path.lstrip('/') fingerprint_path = env.manifest.files[path] asset[path_type] = fingerprint_path with open(filename, 'wb') as f: f.write(unicode(soup.prettify())) def delete_dest(): if os.path.exists(DEST_DIR): shutil.rmtree(DEST_DIR) if __name__ == '__main__': #clean slate delete_dest() #defines where files will be emitted env = Environment(DEST_DIR, public_assets=( lambda path: any(path.endswith(ext) for ext in ('.css', '.js', '.html')), lambda path: any(path.startswith(ext) for ext in ('fonts', 'images'))) ) env.finders.register(FileSystemFinder([SOURCE_DIR])) env.register_defaults() env.save() reference_fingerprinted_files(env) delete_unused_files(env.manifest)
def test_list_empty_if_path_isnt_dir(self): finder = FileSystemFinder([ASSETS_DIR]) self.assertItemsEqual(finder.list('js/templates/readme.txt'), ())
def test_find_if_does_not_exist(self): finder = FileSystemFinder(('/first', '/second', '/third')) finder.find_all = Mock(return_value=()) with self.assertRaises(FileNotFound): finder.find('js/script.js') finder.find_all.assert_called_once_with('js/script.js')
def test_find_if_exists(self): finder = FileSystemFinder(('/first', '/second', '/third')) finder.find_all = Mock(return_value=( '/second/js/script.js', '/third/js/script.js')) self.assertEqual(finder.find('js/script.js'), '/second/js/script.js') finder.find_all.assert_called_once_with('js/script.js')
def test_find_location_if_does_not_exist(self, exists): exists.return_value = False finder = FileSystemFinder(('/assets',)) self.assertIsNone(finder.find_location('/assets', 'js/script.js')) exists.assert_called_once_with('/assets/js/script.js')
def test_find_location_if_exists(self, exists): exists.return_value = True finder = FileSystemFinder(('/assets',)) location = finder.find_location('/assets', 'js/script.js') self.assertEqual(location, '/assets/js/script.js') exists.assert_called_once_with('/assets/js/script.js')
def setUp(self): self.environment = Environment(STATIC_DIR) self.environment.register_defaults() self.environment.finders.register(FileSystemFinder([ASSETS_DIR]))
def test_list_empty_if_path_doesnt_exist(self): finder = FileSystemFinder([ASSETS_DIR]) self.assertItemsEqual(finder.list('js/views'), ())
def test_find_if_does_not_exist(self): finder = FileSystemFinder(("/first", "/second", "/third")) finder.find_all = Mock(return_value=()) with self.assertRaises(FileNotFound): finder.find("js/script.js") finder.find_all.assert_called_once_with("js/script.js")
def get_finder(self, fixture): fixture_path = self.get_fixture_path(fixture) return FileSystemFinder([fixture_path])
def test_list_empty_if_path_doesnt_exist(self): finder = FileSystemFinder([ASSETS_DIR]) self.assertItemsEqual(finder.list('js/views/*'), ())
def get_finder(self, fixture): return FileSystemFinder([self.get_fixture_path(fixture)])
import os from gears.environment import Environment from gears.finders import FileSystemFinder from gears_babel import Babel6to5Compiler ROOT_DIR = os.path.abspath(os.path.dirname(__file__)) ASSETS_DIR = os.path.join(ROOT_DIR, 'assets') STATIC_DIR = os.path.join(ROOT_DIR, 'static') env = Environment(STATIC_DIR) env.finders.register(FileSystemFinder([ASSETS_DIR])) env.compilers.register('.jsx', Babel6to5Compiler.as_handler()) env.register_defaults() if __name__ == '__main__': env.save()