Beispiel #1
0
def test_link_consumers_to_markets_global_use_row():
    given = [{
        'type': 'market activity',
        'reference product': 'cheese',
        'name': '',
        'location': 'RER',
        'code': '',
        'exchanges': [],
    }, {
        'type': 'market activity',
        'reference product': 'cheese',
        'name': '',
        'location': 'RoW',
        'code': 'yes!',
        'exchanges': [],
    }, {
        'type': 'transforming activity',
        'reference product': 'crackers',
        'name': '',
        'location': 'US',
        'exchanges': [{
            'type': 'from technosphere',
            'name': 'cheese',
            'amount': 1,
        }]
    }]
    result = link_consumers_to_markets(given)
    assert result[2]['reference product'] == 'crackers'
    assert result[2]['exchanges'][0]['code'] == 'yes!'
Beispiel #2
0
def test_link_consumers_to_markets_no_market():
    missing = [{
        'type': 'market activity',
        'reference product': 'granola',
        'name': '',
        'location': 'UCTE without Germany',
        'code': '',
        'exchanges': [],
    }, {
        'type': 'transforming activity',
        'reference product': 'crackers',
        'name': '',
        'location': 'FR',
        'exchanges': [{
            'type': 'from technosphere',
            'name': 'cheese'
        }]
    }]
    with pytest.raises(MissingSupplier):
        link_consumers_to_markets(missing)
Beispiel #3
0
def test_link_consumers_to_markets_include_global_mg():
    given = [{
        'type': 'market group',
        'reference product': 'cheese',
        'name': '',
        'location': 'GLO',
        'code': 'a',
        'exchanges': [{
            'type': 'reference product',
            'production volume': {'amount': 1},
            'name': ''
        }],
    }, {
        'type': 'market activity',
        'reference product': 'cheese',
        'name': '',
        'location': 'WECC',
        'code': 'b',
        'exchanges': [{
            'type': 'reference product',
            'production volume': {'amount': 1},
            'name': ''
        }],
    }, {
        'type': 'market activity',
        'reference product': 'cheese',
        'name': '',
        'location': 'CA',
        'code': 'c',
        'exchanges': [{
            'type': 'reference product',
            'production volume': {'amount': 1},
            'name': ''
        }],
    }, {
        'type': 'transforming activity',
        'reference product': 'crackers',
        'name': '',
        'location': 'GLO',
        'exchanges': [{
            'type': 'from technosphere',
            'name': 'cheese',
            'amount': 1,
            'unit': ''
        }]
    }]
    result = link_consumers_to_markets(given)
    assert set(x['code'] for x in result[-1]['exchanges']) == set('a')
Beispiel #4
0
def test_link_consumers_to_markets_same_product_name():
    given = [{
        'type': 'transforming activity',
        'reference product': 'crackers',
        'name': 'something different',
        'location': 'GLO',
        'code': 'a',
        'exchanges': [{
            'type': 'reference product',
            'production volume': {'amount': 1},
            'name': ''
        }],
    }, {
        'type': 'market activity',
        'reference product': 'cheese',
        'name': '',
        'location': 'WECC',
        'code': 'b',
        'exchanges': [{
            'type': 'reference product',
            'production volume': {'amount': 1},
            'name': ''
        }],
    }, {
        'type': 'market activity',
        'reference product': 'cheese',
        'name': '',
        'location': 'CA',
        'code': 'c',
        'exchanges': [{
            'type': 'reference product',
            'production volume': {'amount': 1},
            'name': ''
        }],
    }, {
        'type': 'transforming activity',
        'reference product': 'crackers',
        'name': 'something',
        'location': 'NAFTA',
        'exchanges': [{
            'type': 'from technosphere',
            'name': 'cheese',
            'amount': 1,
            'unit': ''
        }]
    }]
    result = link_consumers_to_markets(given)
    assert [x['code'] for x in result[-1]['exchanges']] == ['c']
Beispiel #5
0
def test_link_consumers_to_markets_global_activity():
    given = [{
        'type': 'transforming activity',
        'reference product': 'cheese',
        'name': '',
        'location': 'GLO',
        'code': 'g',
        'exchanges': [{
            'type': 'from technosphere',
            'name': 'enzymes',
            'amount': 2,
            'unit': 'foo',
        }],
    }, {
        'type': 'market activity',
        'reference product': 'enzymes',
        'name': '',
        'location': 'CH',
        'code': 'ch',
        'exchanges': [{
            'type': 'reference product',
            'production volume': {'amount': 1},
            'name': 'special swiss enzymes'
        }]
    }, {
        'type': 'market activity',
        'reference product': 'enzymes',
        'name': '',
        'location': 'US',
        'code': 'us',
        'exchanges': [{
            'type': 'reference product',
            'production volume': {'amount': 2},
            'name': 'special USA enzymes'
        }]
    }, {
        'type': 'market activity',
        'reference product': 'enzymes',
        'name': '',
        'location': 'RoW',
        'code': 'row',
        'exchanges': [{
            'type': 'reference product',
            'production volume': {'amount': 3},
            'name': 'boring enzymes'
        }]
    }, {
        'type': 'market activity',
        'reference product': 'enzymes',
        'name': '',
        'location': 'CN',
        'code': 'cn',
        'exchanges': [{
            'type': 'reference product',
            'production volume': {'amount': 4},
            'name': 'special mandarin enzymes'
        }]
    }]
    expected = [{
        'amount': 0.6,
        'code': 'row',
        'name': 'enzymes',
        'tag': 'intermediateExchange',
        'type': 'from technosphere',
        'unit': 'foo',
    },{
        'amount': 0.4,
        'code': 'us',
        'name': 'enzymes',
        'tag': 'intermediateExchange',
        'type': 'from technosphere',
        'unit': 'foo',
    },{
        'amount': 0.8,
        'code': 'cn',
        'name': 'enzymes',
        'tag': 'intermediateExchange',
        'type': 'from technosphere',
        'unit': 'foo'
    },{
        'amount': 0.2,
        'code': 'ch',
        'name': 'enzymes',
        'tag': 'intermediateExchange',
        'type': 'from technosphere',
        'unit': 'foo'
    }]
    assert (
        link_consumers_to_markets(deepcopy(given))[1:] ==
        given[1:]
    )
    assert (
        link_consumers_to_markets(deepcopy(given))[0]['exchanges'] ==
        expected
    )
Beispiel #6
0
def test_link_consumers_to_markets():
    given = [{
        'type': 'market activity',
        'reference product': 'cheese',
        'name': '',
        'location': 'RER',
        'code': 'Made in the EU',
        'exchanges': [],
    }, {
        'type': 'market activity',
        'reference product': 'cheese',
        'name': '',
        'location': 'BR',
        'code': 'olympics',
        'exchanges': [],
    }, {
        'type': 'market group',
        'reference product': 'sandwiches',
        'name': '',
        'location': 'BR',
        'exchanges': [{
            'type': 'from technosphere',
            'name': 'cheese'
        }]
    }, {
        'type': 'transforming activity',
        'reference product': 'crackers',
        'name': '',
        'location': 'DE',
        'exchanges': [{
            'type': 'from technosphere',
            'name': 'cheese',
            'amount': 2,
        }, {
            'type': 'from technosphere',
            'name': 'cheese',
            'code': 'already here',
        }, {
            'type': 'something else',
            'name': 'cheese',
        }]
    }]
    expected = [{
        'type': 'market activity',
        'reference product': 'cheese',
        'name': '',
        'location': 'RER',
        'code': 'Made in the EU',
        'exchanges': [],
    }, {
        'type': 'market activity',
        'reference product': 'cheese',
        'name': '',
        'location': 'BR',
        'code': 'olympics',
        'exchanges': [],
    }, {
        'type': 'market group',
        'reference product': 'sandwiches',
        'name': '',
        'location': 'BR',
        'exchanges': [{
            'type': 'from technosphere',
            'name': 'cheese',
        }]
    }, {
        'type': 'transforming activity',
        'reference product': 'crackers',
        'name': '',
        'location': 'DE',
        'exchanges': [{
            'type': 'from technosphere',
            'name': 'cheese',
            'amount': 2,
            'code': 'Made in the EU',
        }, {
            'type': 'from technosphere',
            'name': 'cheese',
            'code': 'already here',
        }, {
            'type': 'something else',
            'name': 'cheese',
        }]
    }]
    assert link_consumers_to_markets(given) == expected