def test_dict_propagate(self): i = inventory.Inventory("N2O-Agrar-2012", "Gg", "German N2O inventory of agricultural source " "categories for 2012", creator="Tester") i.import_inventory(self.n2o_inv, self.n2o_uncert, self.n2o_index) i.propagate() self.assertEqual(round(i.inv_uncert, 1), round(self.n2o_inv_uncert, 1))
def test_mtime_dict(self): i = inventory.Inventory("N2O-Agrar-2012", "Gg", "German N2O inventory of agricultural source " "categories for 2012", ("2012-01-01 00:00:00", None), creator="Tester") time.sleep(1) i.import_inventory(self.n2o_inv, self.n2o_percent, self.n2o_index, True) self.assertNotEqual(i.ctime, i.mtime)
def test_inventory_dict(self): i = inventory.Inventory("N2O-Agrar-2012", "Gg", "German N2O inventory of agricultural source " "categories for 2012", creator="Tester") i.import_inventory(self.n2o_inv, self.n2o_uncert, self.n2o_index) self.assertEqual(round(sum(i.inv_dict.values()), 1), 43703.4) self.assertEqual(round(sum(i.uncert_dict.values()), 1), round(sum(self.n2o_uncert), 1)) self.assertEqual(len(i.inv_dict), 18)
def test_dict_printsum(self): i = inventory.Inventory("N2O-Agrar-2012", "Gg", "German N2O inventory of agricultural source " "categories for 2012", ("2012-01-01 00:00:00", "2013-01-01 00:00:00"), creator="Tester") i.import_inventory(self.n2o_inv, self.n2o_uncert, self.n2o_index) i.accumulate() i.propagate() i.printsum() self.assertEqual(round(i.inv_sum, 1), round(np.sum(self.n2o_inv), 1)) self.assertEqual(round(i.inv_uncert, 1), round(self.n2o_inv_uncert, 1))
def test_array_propagate(self): i = inventory.Inventory("N2O-Agrar-2012", "Gg", "German N2O inventory of agricultural source " "categories for 2012", creator="Tester") n2o_inv_array = np.array(self.n2o_inv).reshape((3, 6)) n2o_inv_index = np.array(self.n2o_index).reshape((3, 6)) n2o_inv_uncert = np.array(self.n2o_percent).reshape((3, 6)) i.import_inventory(n2o_inv_array, n2o_inv_uncert, n2o_inv_index, True) i.propagate() self.assertEqual(round(i.inv_uncert, 1), round(self.n2o_inv_uncert, 1))
def test_inventory_array(self): i = inventory.Inventory("N2O-Agrar-2012", "Gg", "German N2O inventory of agricultural source " "categories for 2012", creator="Tester") n2o_inv_array = np.array(self.n2o_inv).reshape((3, 6)) n2o_inv_index = np.array(self.n2o_index).reshape((3, 6)) n2o_inv_uncert = np.array(self.n2o_percent).reshape((3, 6)) i.import_inventory(n2o_inv_array, n2o_inv_uncert, n2o_inv_index, True) self.assertEqual(np.sum(i.inv_array), 43703.4) self.assertEqual(round(np.sum(i.inv_uncert_array), 0), round(sum(self.n2o_uncert), 0)) self.assertEqual(i.inv_array.shape, (3, 6))
def test_timestamp(self): i = inventory.Inventory("N2O-Agrar-2012", "Gg", "German N2O inventory of agricultural source " "categories for 2012", ("2012-01-01 00:00:00", None), creator="Tester") start, end = i.timestamp self.assertEqual((start, end), ("2012-01-01 00:00:00", 'None')) i.timestamp = (None, "2013-01-01 00:00:00") start, end = i.timestamp self.assertEqual((start, end), ('None', "2013-01-01 00:00:00")) i.timestamp = ("2012-01-01 00:00:00", "2013-01-01 00:00:00") start, end = i.timestamp self.assertEqual((start, end), ("2012-01-01 00:00:00", "2013-01-01 00:00:00"))