示例#1
0
 def test_encoding_fail(self):
     from staticcomp.compressor import JsPayload
     payload = JsPayload(['js/a123.js', 'js/bcccc.js', 'js/foo/bar.js'], 'base')
     try:
         payload.encode()
     except OSError:
         # this is expected as these files shouldn't exist
         pass
     else:
         self.fail("The JsPayload encoder should have failed.")
示例#2
0
 def test_code_random_js(self):
     import os
     js_files = set()
     min_re = re.compile(r'\.min\.')
     media_root = os.path.normpath(settings.MEDIA_ROOT)
     is_js = lambda f: bool(os.path.splitext(f)[-1] == '.js' and not min_re.search(f))
     def w(fileset, dirname, names):
         if len(fileset) < 3:
             js_files = filter(is_js, names)
             if js_files:
                 map(fileset.add, [ os.path.join(dirname, f)[len(media_root)+1:] for f in js_files])
             
     os.path.walk(settings.MEDIA_ROOT, w, js_files)
     if js_files:
         # encoding random set of js two files
         from staticcomp.compressor import JsPayload
         payload = JsPayload(list(js_files), 'random')
         b64, hash = payload.encode()