def test_redo_lci_switches_demand(self): test_data = { ("t", "1"): { 'exchanges': [{ 'amount': 0.5, 'input': ('t', "2"), 'type': 'technosphere', 'uncertainty type': 0 }, { 'amount': 1, 'input': ('biosphere', "1"), 'type': 'biosphere', 'uncertainty type': 0 }], 'type': 'process', 'unit': 'kg' }, ("t", "2"): { 'exchanges': [], 'type': 'process', 'unit': 'kg' }, } self.add_basic_biosphere() test_db = Database("t") test_db.write(test_data) lca = LCA({("t", "1"): 1}) lca.lci() self.assertEqual(lca.demand, {("t", "1"): 1}) lca.redo_lci({("t", "1"): 2}) self.assertEqual(lca.demand, {("t", "1"): 2})
def test_redo_lci_with_no_new_demand_no_error(self): self.add_basic_biosphere() test_data = { ("t", "1"): { 'exchanges': [{ 'amount': 1, 'input': ('biosphere', "1"), 'type': 'biosphere' }] } } test_db = Database("t") test_db.register() test_db.write(test_data) more_test_data = { ("z", "1"): { 'exchanges': [{ 'amount': 1, 'input': ('t', "1"), 'type': 'technosphere' }] } } more_test_db = Database("z") more_test_db.register() more_test_db.write(more_test_data) lca = LCA({("t", "1"): 1}) lca.lci() lca.redo_lci()
def test_redo_lci_fails_if_activity_outside_technosphere(self): self.add_basic_biosphere() test_data = { ("t", "1"): { 'exchanges': [{ 'amount': 1, 'input': ('biosphere', "1"), 'type': 'biosphere' }] } } test_db = Database("t") test_db.register() test_db.write(test_data) more_test_data = { ("z", "1"): { 'exchanges': [{ 'amount': 1, 'input': ('t', "1"), 'type': 'technosphere' }] } } more_test_db = Database("z") more_test_db.register() more_test_db.write(more_test_data) lca = LCA({("t", "1"): 1}) lca.lci() with self.assertRaises(OutsideTechnosphere): lca.redo_lci({("z", "1"): 1})
def test_redo_lci_with_no_new_demand_no_error(self): self.add_basic_biosphere() test_data = { ("t", "1"): { "exchanges": [{ "amount": 1, "input": ("biosphere", "1"), "type": "biosphere" }] } } test_db = Database("t") test_db.register() test_db.write(test_data) more_test_data = { ("z", "1"): { "exchanges": [{ "amount": 1, "input": ("t", "1"), "type": "technosphere" }] } } more_test_db = Database("z") more_test_db.register() more_test_db.write(more_test_data) lca = LCA({("t", "1"): 1}) lca.lci() lca.redo_lci()
def test_redo_lci_fails_if_activity_outside_technosphere(self): self.add_basic_biosphere() test_data = { ("t", "1"): { "exchanges": [{ "amount": 1, "input": ("biosphere", "1"), "type": "biosphere" }] } } test_db = Database("t") test_db.register() test_db.write(test_data) more_test_data = { ("z", "1"): { "exchanges": [{ "amount": 1, "input": ("t", "1"), "type": "technosphere" }] } } more_test_db = Database("z") more_test_db.register() more_test_db.write(more_test_data) lca = LCA({("t", "1"): 1}) lca.lci() with self.assertRaises(OutsideTechnosphere): lca.redo_lci({("z", "1"): 1})
def test_fix_dictionaries(self): test_data = { ("t", "1"): { "exchanges": [ { "amount": 0.5, "input": ("t", "2"), "type": "technosphere", "uncertainty type": 0, }, { "amount": 1, "input": ("biosphere", "1"), "type": "biosphere", "uncertainty type": 0, }, ], "type": "process", "unit": "kg", }, ("t", "2"): { "exchanges": [], "type": "process", "unit": "kg" }, } self.add_basic_biosphere() test_db = Database("t") test_db.register() test_db.write(test_data) lca = LCA({("t", "1"): 1}) lca.lci() supply = lca.supply_array.sum() self.assertTrue(lca._fixed) self.assertFalse(lca.fix_dictionaries()) # Second time doesn't do anything self.assertFalse(lca.fix_dictionaries()) self.assertTrue(lca._fixed) lca.redo_lci({("t", "1"): 2}) self.assertEqual(lca.supply_array.sum(), supply * 2)
def test_fix_dictionaries(self): test_data = { ("t", "1"): { 'exchanges': [{ 'amount': 0.5, 'input': ('t', "2"), 'type': 'technosphere', 'uncertainty type': 0 }, { 'amount': 1, 'input': ('biosphere', "1"), 'type': 'biosphere', 'uncertainty type': 0 }], 'type': 'process', 'unit': 'kg' }, ("t", "2"): { 'exchanges': [], 'type': 'process', 'unit': 'kg' }, } self.add_basic_biosphere() test_db = Database("t") test_db.register() test_db.write(test_data) lca = LCA({("t", "1"): 1}) lca.lci() supply = lca.supply_array.sum() self.assertTrue(lca._fixed) self.assertFalse(lca.fix_dictionaries()) # Second time doesn't do anything self.assertFalse(lca.fix_dictionaries()) self.assertTrue(lca._fixed) lca.redo_lci({("t", "1"): 2}) self.assertEqual(lca.supply_array.sum(), supply * 2)
def test_redo_lci_switches_demand(self): test_data = { ("t", "1"): { "exchanges": [ { "amount": 0.5, "input": ("t", "2"), "type": "technosphere", "uncertainty type": 0, }, { "amount": 1, "input": ("biosphere", "1"), "type": "biosphere", "uncertainty type": 0, }, ], "type": "process", "unit": "kg", }, ("t", "2"): { "exchanges": [], "type": "process", "unit": "kg" }, } self.add_basic_biosphere() test_db = Database("t") test_db.write(test_data) lca = LCA({("t", "1"): 1}) lca.lci() self.assertEqual(lca.demand, {("t", "1"): 1}) lca.redo_lci({("t", "1"): 2}) self.assertEqual(lca.demand, {("t", "1"): 2})