def test_write_only_activity_parameters_no_activate_others(no_init): Database("PCB").register() obj = ExcelImporter() obj.db_name = "PCB" obj.data = deepcopy(DATA) obj.write_database(activate_parameters=False) NEW = [{ 'code': '45cb34db4147e510a2561cceec541f6b', 'database': 'PCB', 'exchanges': [], 'name': 'unmounted printed circuit board', 'type': 'process', 'unit': 'square meter', 'parameters': [{ 'name': 'something_test', 'amount': 2, 'formula': '3 + 2' }], }] obj = ExcelImporter() obj.db_name = "PCB" obj.write_activity_parameters(NEW) assert ActivityParameter.select().count() == 1 assert ActivityParameter.get().formula == '3 + 2' assert 'parameters' not in get_activity( ('PCB', '45cb34db4147e510a2561cceec541f6b')) assert 'parameters' in get_activity( ('PCB', '32aa5ab78beda5b8c8efbc89587de7a5'))
def test_write_only_activity_parameters_no_activate_others(no_init): Database("PCB").register() obj = ExcelImporter() obj.db_name = "PCB" obj.data = deepcopy(DATA) obj.write_database(activate_parameters=False) NEW = [ { "code": "45cb34db4147e510a2561cceec541f6b", "database": "PCB", "exchanges": [], "name": "unmounted printed circuit board", "type": "process", "unit": "square meter", "parameters": [{"name": "something_test", "amount": 2, "formula": "3 + 2"}], } ] obj = ExcelImporter() obj.db_name = "PCB" obj.write_activity_parameters(NEW) assert ActivityParameter.select().count() == 1 assert ActivityParameter.get().formula == "3 + 2" assert "parameters" not in get_activity(("PCB", "45cb34db4147e510a2561cceec541f6b")) assert "parameters" in get_activity(("PCB", "32aa5ab78beda5b8c8efbc89587de7a5"))
def test_write_only_activity_parameters(no_init): assert not ActivityParameter.select().count() Database("PCB").register() obj = ExcelImporter() obj.db_name = "PCB" obj.data = deepcopy(DATA) obj.write_database() assert ActivityParameter.select().count() == 1 assert ActivityParameter.get().amount != 7 NEW = [{ 'code': '32aa5ab78beda5b8c8efbc89587de7a5', 'database': 'PCB', 'parameters': [{ 'name': 'PCB_mass_total', 'amount': 11, 'formula': '7' }], }] obj.write_activity_parameters(NEW) assert ActivityParameter.select().count() == 1 a = ActivityParameter.get() assert a.formula == '7' assert a.amount == 7
def test_empty_activity_parameters_dont_delete(no_init): # Empty activity parameters aren't considered at all # so they shouldn't be deleted if empty section provided Database("PCB").register() obj = ExcelImporter() obj.db_name = "PCB" obj.data = deepcopy(DATA) obj.write_database() assert len(parameters) NEW = deepcopy(DATA) for ds in NEW: if "parameters" in ds: del ds["parameters"] Database("PCB").register() obj = ExcelImporter() obj.db_name = "PCB" obj.data = NEW obj.write_database(delete_existing=False) assert len(parameters)
def test_write_only_database_parameters(no_init): Database("foo").register() obj = ExcelImporter() obj.db_name = "foo" obj.data = None obj.database_parameters = deepcopy(DB) obj.write_database_parameters(activate_parameters=False) assert not DatabaseParameter.select().count() assert "parameters" in obj.metadata obj.write_database_parameters() assert DatabaseParameter.select().count() == 3 obj.database_parameters = deepcopy(DB[:1]) obj.write_database_parameters() assert DatabaseParameter.select().count() == 1
def test_write_only_activity_parameters(no_init): assert not ActivityParameter.select().count() Database("PCB").register() obj = ExcelImporter() obj.db_name = "PCB" obj.data = deepcopy(DATA) obj.write_database() assert ActivityParameter.select().count() == 1 assert ActivityParameter.get().amount != 7 NEW = [ { "code": "32aa5ab78beda5b8c8efbc89587de7a5", "database": "PCB", "parameters": [{"name": "PCB_mass_total", "amount": 11, "formula": "7"}], } ] obj.write_activity_parameters(NEW) assert ActivityParameter.select().count() == 1 a = ActivityParameter.get() assert a.formula == "7" assert a.amount == 7
def test_get_activity_metadata_indexing(no_init): given = [ [ "Activity", "mounted printed circuit board", "", "", "", "", "", "", "", "", "", "", "", "", ], [ "arbitrary", "metadata", "", "", "", "", "", "", "", "", "", "", "", "" ], ["unit", "kilogram", "", "", "", "", "", "", "", "", "", "", "", ""], ["", "", "", "", "", "", "", "", "", "", "", "", "", ""], ["Parameters", "", "", "", "", "", "", "", "", "", "", "", "", ""], ] ei = ExcelImporter() ei.db_name = "db" expected = { "arbitrary": "metadata", "database": "db", "name": "mounted printed circuit board", "exchanges": [], "unit": "kilogram", "worksheet name": "a", } assert ei.get_activity("a", given) == expected given = [ [ "Activity", "mounted printed circuit board", "", "", "", "", "", "", "", "", "", "", "", "", ], [ "arbitrary", "metadata", "", "", "", "", "", "", "", "", "", "", "", "" ], ["unit", "kilogram", "", "", "", "", "", "", "", "", "", "", "", ""], ["", "", "", "", "", "", "", "", "", "", "", "", "", ""], ] ei = ExcelImporter() ei.db_name = "db" expected = { "arbitrary": "metadata", "database": "db", "name": "mounted printed circuit board", "exchanges": [], "unit": "kilogram", "worksheet name": "a", } assert ei.get_activity("a", given) == expected given = [ [ "Activity", "mounted printed circuit board", "", "", "", "", "", "", "", "", "", "", "", "", ], [ "arbitrary", "metadata", "", "", "", "", "", "", "", "", "", "", "", "" ], ["unit", "kilogram", "", "", "", "", "", "", "", "", "", "", "", ""], ] ei = ExcelImporter() ei.db_name = "db" expected = { "arbitrary": "metadata", "database": "db", "name": "mounted printed circuit board", "exchanges": [], "unit": "kilogram", "worksheet name": "a", } assert ei.get_activity("a", given) == expected
def test_get_activity(no_init): given = [ [ "Activity", "mounted printed circuit board", "", "", "", "", "", "", "", "", "", "", "", "", ], [ "comment", "something important here maybe?", "", "", "", "", "", "", "", "", "", "", "", "", ], [ "arbitrary", "metadata", "", "", "", "", "", "", "", "", "", "", "", "" ], ["location", "GLO", "", "", "", "", "", "", "", "", "", "", "", ""], ["type", "process", "", "", "", "", "", "", "", "", "", "", "", ""], ["unit", "kilogram", "", "", "", "", "", "", "", "", "", "", "", ""], ["", "", "", "", "", "", "", "", "", "", "", "", "", ""], ["Parameters", "", "", "", "", "", "", "", "", "", "", "", "", ""], [ "name", "amount", "formula", "", "", "", "", "", "", "", "", "", "", "" ], [ "PCB_mass_total", 0.6, "PCB_cap_mass_film + PCB_cap_mass_SMD + PCB_cap_mass_Tantalum", "", "", "", "", "", "", "", "", "", "", "", ], ["", "", "", "", "", "", "", "", "", "", "", "", "", ""], ["Exchanges", "", "", "", "", "", "", "", "", "", "", "", "", ""], [ "name", "amount", "unit", "database", "location", "type", "formula", "", "", "", "", "", "", "", ], [ "unmounted printed circuit board", 0.0, "square meter", "PCB", "GLO", "technosphere", "PCB_area * 2", "PCB_area * 2", "", "", "", "", "", "", ], [ "mounted printed circuit board", 0.0, "kilogram", "PCB", "GLO", "production", "PCB_mass_total", "PCB_mass_total", "", "", "", "", "", "", ], ["", "", "", "", "", "", "", "", "", "", "", "", "", ""], [ "Activity", "unmounted printed circuit board", "", "", "", "", "", "", "", "", "", "", "", "", ], ] ei = ExcelImporter() ei.db_name = "db" expected = { "arbitrary": "metadata", "comment": "something important here maybe?", "database": "db", "exchanges": [ { "database": "PCB", "amount": 0.0, "formula": "PCB_area * 2", "location": "GLO", "name": "unmounted printed circuit board", "type": "technosphere", "unit": "square meter", }, { "database": "PCB", "amount": 0.0, "formula": "PCB_mass_total", "location": "GLO", "name": "mounted printed circuit board", "type": "production", "unit": "kilogram", }, ], "location": "GLO", "name": "mounted printed circuit board", "parameters": { "PCB_mass_total": { "amount": 0.6, "formula": "PCB_cap_mass_film + PCB_cap_mass_SMD + PCB_cap_mass_Tantalum", } }, "type": "process", "unit": "kilogram", "worksheet name": "a", } assert ei.get_activity("a", given) == expected
def test_get_activity(no_init): given = [ [ 'Activity', 'mounted printed circuit board', '', '', '', '', '', '', '', '', '', '', '', '' ], [ 'comment', 'something important here maybe?', '', '', '', '', '', '', '', '', '', '', '', '' ], [ 'arbitrary', 'metadata', '', '', '', '', '', '', '', '', '', '', '', '' ], ['location', 'GLO', '', '', '', '', '', '', '', '', '', '', '', ''], ['type', 'process', '', '', '', '', '', '', '', '', '', '', '', ''], ['unit', 'kilogram', '', '', '', '', '', '', '', '', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '', ''], ['Parameters', '', '', '', '', '', '', '', '', '', '', '', '', ''], [ 'name', 'amount', 'formula', '', '', '', '', '', '', '', '', '', '', '' ], [ 'PCB_mass_total', 0.6, 'PCB_cap_mass_film + PCB_cap_mass_SMD + PCB_cap_mass_Tantalum', '', '', '', '', '', '', '', '', '', '', '' ], ['', '', '', '', '', '', '', '', '', '', '', '', '', ''], ['Exchanges', '', '', '', '', '', '', '', '', '', '', '', '', ''], [ 'name', 'amount', 'unit', 'database', 'location', 'type', 'formula', '', '', '', '', '', '', '' ], [ 'unmounted printed circuit board', 0.0, 'square meter', 'PCB', 'GLO', 'technosphere', 'PCB_area * 2', 'PCB_area * 2', '', '', '', '', '', '' ], [ 'mounted printed circuit board', 0.0, 'kilogram', 'PCB', 'GLO', 'production', 'PCB_mass_total', 'PCB_mass_total', '', '', '', '', '', '' ], ['', '', '', '', '', '', '', '', '', '', '', '', '', ''], [ 'Activity', 'unmounted printed circuit board', '', '', '', '', '', '', '', '', '', '', '', '' ], ] ei = ExcelImporter() ei.db_name = 'db' expected = { 'arbitrary': 'metadata', 'comment': 'something important here maybe?', 'database': 'db', 'exchanges': [{ 'database': 'PCB', 'amount': 0.0, 'formula': 'PCB_area * 2', 'location': 'GLO', 'name': 'unmounted printed circuit board', 'type': 'technosphere', 'unit': 'square meter' }, { 'database': 'PCB', 'amount': 0.0, 'formula': 'PCB_mass_total', 'location': 'GLO', 'name': 'mounted printed circuit board', 'type': 'production', 'unit': 'kilogram' }], 'location': 'GLO', 'name': 'mounted printed circuit board', 'parameters': { 'PCB_mass_total': { 'amount': 0.6, 'formula': 'PCB_cap_mass_film + PCB_cap_mass_SMD + PCB_cap_mass_Tantalum' } }, 'type': 'process', 'unit': 'kilogram', 'worksheet name': 'a' } assert ei.get_activity('a', given) == expected
def test_get_activity_metadata_indexing(no_init): given = [ [ 'Activity', 'mounted printed circuit board', '', '', '', '', '', '', '', '', '', '', '', '' ], [ 'arbitrary', 'metadata', '', '', '', '', '', '', '', '', '', '', '', '' ], ['unit', 'kilogram', '', '', '', '', '', '', '', '', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '', ''], ['Parameters', '', '', '', '', '', '', '', '', '', '', '', '', ''], ] ei = ExcelImporter() ei.db_name = 'db' expected = { 'arbitrary': 'metadata', 'database': 'db', 'name': 'mounted printed circuit board', 'exchanges': [], 'unit': 'kilogram', 'worksheet name': 'a' } assert ei.get_activity('a', given) == expected given = [ [ 'Activity', 'mounted printed circuit board', '', '', '', '', '', '', '', '', '', '', '', '' ], [ 'arbitrary', 'metadata', '', '', '', '', '', '', '', '', '', '', '', '' ], ['unit', 'kilogram', '', '', '', '', '', '', '', '', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '', '', '', '', ''], ] ei = ExcelImporter() ei.db_name = 'db' expected = { 'arbitrary': 'metadata', 'database': 'db', 'name': 'mounted printed circuit board', 'exchanges': [], 'unit': 'kilogram', 'worksheet name': 'a' } assert ei.get_activity('a', given) == expected given = [ [ 'Activity', 'mounted printed circuit board', '', '', '', '', '', '', '', '', '', '', '', '' ], [ 'arbitrary', 'metadata', '', '', '', '', '', '', '', '', '', '', '', '' ], ['unit', 'kilogram', '', '', '', '', '', '', '', '', '', '', '', ''], ] ei = ExcelImporter() ei.db_name = 'db' expected = { 'arbitrary': 'metadata', 'database': 'db', 'name': 'mounted printed circuit board', 'exchanges': [], 'unit': 'kilogram', 'worksheet name': 'a' } assert ei.get_activity('a', given) == expected