Commits

Chris Mutel  committed 808d306

Adjust tests for IA documents always including geodata

  • Participants
  • Parent commits 5793b0a

Comments (0)

Files changed (3)

File bw2data/tests/geo.py

         d.register("biosphere", [], len(biosphere))
         d.write(biosphere)
 
-    def add_method(self, simple=True):
+    def add_method(self):
         self.add_biosphere()
         method = Method(("test method",))
-        method.register("kg")
-        if simple:
-            method.write({
-                ("biosphere", 1): 6,
-                ("biosphere", 2): 5
-                })
-        else:
-            method.write({
-                ("biosphere", 1): (6, "foo"),
-                ("biosphere", 2): (5, "bar")
-                })
+        method.register(unit="kg")
+        method.write([
+            (("biosphere", 1), 6, "foo"),
+            (("biosphere", 2), 5, "bar")
+        ])
         return method
 
     def test_geomapping_retrieval(self):
         print geomapping.data
         self.assertTrue("GLO" in geomapping)
 
-    def test_method_adds_default_geo(self):
+    def test_method_adds_correct_geo(self):
         method = self.add_method()
         method.process()
         pickled = pickle.load(open(os.path.join(config.dir, "processed",
             method.get_abbreviation() + ".pickle"), "rb"))
-        global_index = geomapping["GLO"]
-        self.assertEqual(global_index, int(pickled[0]["geo"]))
-        self.assertEqual(global_index, int(pickled[1]["geo"]))
-        self.assertEquals(pickled.shape, (2,))
-
-    def test_method_adds_correct_geo(self):
-        method = self.add_method(False)
-        method.process()
-        pickled = pickle.load(open(os.path.join(config.dir, "processed",
-            method.get_abbreviation() + ".pickle"), "rb"))
         self.assertEqual(geomapping["foo"], int(pickled[0]["geo"]))
         self.assertEqual(geomapping["bar"], int(pickled[1]["geo"]))
         self.assertEquals(pickled.shape, (2,))
             geomapping["GLO"] * np.ones(pickled.shape)))
 
     def test_method_write_adds_to_geomapping(self):
-        self.add_method(False)
+        self.add_method()
         self.assertTrue("foo" in geomapping)
         self.assertTrue("bar" in geomapping)
 

File bw2data/tests/utils.py

         d.register("Tests", [], len(biosphere))
         d.write(biosphere)
         m1 = Method(["test method 1"])
-        m1.register("p", 2)
-        m1.write({
-            ("biosphere", 1): 1,
-            ("biosphere", 2): 2
-            })
+        m1.register(unit="p", num_cfs=2)
+        m1.write([
+            (("biosphere", 1), 1, "GLO"),
+            (("biosphere", 2), 2, "GLO")
+        ])
         m2 = Method(["test method 2"])
-        m2.register("p", 1)
-        m2.write({
-            ("biosphere", 2): 10
-            })
+        m2.register(unit="p", num_cfs=1)
+        m2.write([
+            (("biosphere", 2), 10, "GLO")
+        ])
         combine_methods(["test method 3"], ["test method 1"],
             ["test method 2"])
         cm = Method(["test method 3"])
-        self.assertEqual(cm.load(), {
-            ("biosphere", 1): 1,
-            ("biosphere", 2): 12
-            })
+        self.assertEqual(sorted(cm.load()), [
+            (("biosphere", 1), 1, "GLO"),
+            (("biosphere", 2), 12, "GLO")
+        ])
         self.assertEqual(methods[["test method 3"]]["unit"], "p")

File bw2data/utils.py

     data = {}
     units = set([methods[tuple(x)]["unit"] for x in ms])
     for m in ms:
-        for key, amount in Method(m).load().iteritems():
-            data[key] = data.get(key, 0) + amount
+        for key, cf, geo in Method(m).load():
+            data[(key, geo)] = data.get((key, geo), 0) + cf
     meta = {
         "description": "Combination of the following methods: " +
             ", ".join([str(x) for x in ms]),
         "num_cfs": len(data),
         "unit": list(units)[0] if len(units) == 1 else "Unknown"
     }
+    data = [(key, cf, geo) for (key, geo), cf in data.iteritems()]
     method = Method(name)
     method.register(**meta)
     method.write(data)