Commits

Anonymous committed 0ef2510

Commit fix for issue #67.

  • Participants
  • Parent commits 0b1d384

Comments (0)

Files changed (4)

 0.12 (unreleased)
 =================
 
-- Nothing changed yet.
-
-
+- There was a bug with ordering resources when multiple libraries
+  are involved: https://bitbucket.org/fanstatic/fanstatic/issue/67/ordering-of-resources-when-multiple
+  
 0.11.1 (2011-04-13)
 ===================
 
 
 * Dan Korostolev
 
+* Alberto Valverde González 
+
 * Guido Wesdorp

fanstatic/core.py

     """
     library_nrs = {}
     for resource in resources:
-        library_nr = library_nrs.get(resource.library, 0)
+        # the order is used to distinguish library numbers between
+        # types of resources. without the order here, a resource can
+        # end up being in the wrong place if another resource in that
+        # library has a deeper dependency structure; order should always
+        # trump library nr
+        rkey = resource.order, resource.library
+        library_nr = library_nrs.get(rkey, 0)
         library_nr = max(resource.library_nr, library_nr)
-        library_nrs[resource.library] = library_nr
+        library_nrs[rkey] = library_nr
 
     def key(resource):
         return (
             resource.order,
-            library_nrs[resource.library],
+            library_nrs[(resource.order, resource.library)],
             resource.library.name,
             resource.dependency_nr,
             resource.relpath)

fanstatic/test_core.py

 
     assert resources == [a]
 
+def test_inter_library_dependencies_ordering():
+    lib1 = Library('lib1', '')
+    lib2 = Library('lib2', '')
+    lib3 = Library('lib3', '')
+    lib4 = Library('lib4', '')
+    
+    js1 = Resource(lib1, 'js1.js')
+    js2 = Resource(lib2, 'js2.js', depends=[js1]) 
+    js3 = Resource(lib3, 'js3.js', depends=[js2])
+    
+    style1 = Resource(lib3, 'style1.css')
+    style2 = Resource(lib4, 'style2.css', depends=[style1])
+
+    needed = NeededResources()
+
+    needed.need(js3)
+    needed.need(style2)
+    resources = needed.resources()
+    assert resources == [style1, style2, js1, js2, js3]
+
+
 # XXX tests for hashed resources when this is enabled. Needs some plausible
 # directory to test for hashes