コード例 #1
0
ファイル: rest_of_world.py プロジェクト: damanncarlos/Ocelot
def test_multiple_global_datasets():
    given = [{
        'name':
        'make something',
        'type':
        'market activity',
        'location':
        'GLO',
        'exchanges': [{
            'name': 'a product',
            'amount': 1,
            'type': 'reference product'
        }]
    }, {
        'name':
        'make something',
        'type':
        'market activity',
        'location':
        'GLO',
        'exchanges': [{
            'name': 'a product',
            'amount': 1,
            'type': 'reference product'
        }]
    }]
    with pytest.raises(MultipleGlobalDatasets):
        relabel_global_to_row(given)
コード例 #2
0
ファイル: rest_of_world.py プロジェクト: damanncarlos/Ocelot
def test_relabel_global_to_row_skip_market_groups():
    given = [{
        'name':
        'shellfish',
        'type':
        'market group',
        'location':
        'GLO',
        'exchanges': [{
            'name': 'a product',
            'amount': 1,
            'type': 'reference product'
        }]
    }, {
        'name':
        'shellfish',
        'type':
        'market group',
        'location':
        'CN',
        'exchanges': [{
            'name': 'a product',
            'amount': 1,
            'type': 'reference product'
        }]
    }]
    expected = deepcopy(given)
    assert relabel_global_to_row(given) == expected
コード例 #3
0
ファイル: rest_of_world.py プロジェクト: damanncarlos/Ocelot
def test_relabel_global_to_row_subtract_origianal_pv():
    given = [{
        'name':
        'make something',
        'location':
        'GLO',
        'type':
        'market activity',
        'exchanges': [{
            'name': 'a product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume': {
                'amount': 100
            }
        }]
    }, {
        'name':
        'make something',
        'location':
        'somewhere else',
        'unit':
        '',
        'type':
        'market activity',
        'exchanges': [{
            'name': 'a product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume': {
                'amount': 10,
                'subtracted activity link volume': 40,
                'original amount': 50
            }
        }]
    }]
    expected = {
        'name':
        'make something',
        'location':
        'RoW',
        'type':
        'market activity',
        'exchanges': [{
            'name': 'a product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume': {
                'amount': 50,
                'global amount': 100,
            }
        }]
    }
    assert next(o for o in relabel_global_to_row(given)
                if o['location'] == 'RoW') == expected
コード例 #4
0
ファイル: rest_of_world.py プロジェクト: pjamesjoyce/Ocelot
def test_relabel_global_to_row_only_single_nonglobal():
    given = [{
        'name': 'make something',
        'location': 'somewhere',
        'exchanges': [{
            'name': 'a product',
            'type': 'reference product'
        }]
    }]
    expected = deepcopy(given)
    assert relabel_global_to_row(given) == expected
コード例 #5
0
ファイル: rest_of_world.py プロジェクト: OcelotProject/Ocelot
def test_multiple_global_datasets():
    given = [{
        'name': 'make something',
        'type': 'market activity',
        'location': 'GLO',
        'exchanges': [{
            'name': 'a product',
            'amount': 1,
            'type': 'reference product'
        }]
    }, {
        'name': 'make something',
        'type': 'market activity',
        'location': 'GLO',
        'exchanges': [{
            'name': 'a product',
            'amount': 1,
            'type': 'reference product'
        }]
    }]
    with pytest.raises(MultipleGlobalDatasets):
        relabel_global_to_row(given)
コード例 #6
0
ファイル: rest_of_world.py プロジェクト: OcelotProject/Ocelot
def test_relabel_global_to_row_only_single_nonglobal():
    given = [{
        'name': 'make something',
        'type': 'market activity',
        'location': 'somewhere',
        'exchanges': [{
            'name': 'a product',
            'amount': 1,
            'type': 'reference product'
        }]
    }]
    expected = deepcopy(given)
    assert relabel_global_to_row(given) == expected
コード例 #7
0
ファイル: rest_of_world.py プロジェクト: damanncarlos/Ocelot
def test_relabel_global_to_row_only_single_global():
    given = [{
        'name':
        'make something',
        'type':
        'market activity',
        'location':
        'GLO',
        'exchanges': [{
            'name': 'a product',
            'amount': 1,
            'type': 'reference product'
        }]
    }]
    expected = deepcopy(given)
    assert relabel_global_to_row(given) == expected
コード例 #8
0
ファイル: rest_of_world.py プロジェクト: OcelotProject/Ocelot
def test_relabel_global_to_row_subtract_origianal_pv():
    given = [{
        'name': 'make something',
        'location': 'GLO',
        'type': 'market activity',
        'exchanges': [{
            'name': 'a product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume':{
                'amount':100
            }
        }]
    }, {
        'name': 'make something',
        'location': 'somewhere else',
        'unit': '',
        'type': 'market activity',
        'exchanges': [{
            'name': 'a product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume':{
                'amount':10,
                'subtracted activity link volume': 40,
                'original amount': 50
            }
        }]
    }]
    expected = {
        'name': 'make something',
        'location': 'RoW',
        'type': 'market activity',
        'exchanges': [{
            'name': 'a product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume':{
                'amount':50,
                'global amount': 100,
            }
        }]
    }
    assert next(o for o in relabel_global_to_row(given) if o['location'] == 'RoW') == expected
コード例 #9
0
ファイル: rest_of_world.py プロジェクト: OcelotProject/Ocelot
def test_relabel_global_to_row_skip_market_groups():
    given = [{
        'name': 'shellfish',
        'type': 'market group',
        'location': 'GLO',
        'exchanges': [{
            'name': 'a product',
            'amount': 1,
            'type': 'reference product'
        }]
    }, {
        'name': 'shellfish',
        'type': 'market group',
        'location': 'CN',
        'exchanges': [{
            'name': 'a product',
            'amount': 1,
            'type': 'reference product'
        }]
    }]
    expected = deepcopy(given)
    assert relabel_global_to_row(given) == expected
コード例 #10
0
ファイル: rest_of_world.py プロジェクト: damanncarlos/Ocelot
def test_relabel_global_to_row_subtract_pv_overspecified_regional_pv():
    given = [{
        'name':
        'make something',
        'location':
        'GLO',
        'unit':
        '',
        'type':
        'market activity',
        'exchanges': [{
            'name': 'a product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume': {
                'amount': 100
            }
        }]
    }, {
        'name':
        'make something',
        'location':
        'somewhere else',
        'unit':
        '',
        'type':
        'market activity',
        'exchanges': [{
            'name': 'a product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume': {
                'amount': 110
            }
        }]
    }, {
        'name':
        'make something else',
        'location':
        'GLO',
        'unit':
        '',
        'type':
        'market activity',
        'exchanges': [{
            'name': 'a product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume': {
                'amount': 100
            }
        }]
    }, {
        'name':
        'make something else',
        'location':
        'somewhere else',
        'unit':
        '',
        'type':
        'market activity',
        'exchanges': [{
            'name': 'a product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume': {
                'amount': 150
            }
        }]
    }]
    expected = [{
        'name':
        'make something',
        'location':
        'RoW',
        'type':
        'market activity',
        'exchanges': [{
            'name': 'a product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume': {
                'amount': 0
            }
        }]
    }, {
        'name':
        'make something',
        'location':
        'somewhere else',
        'type':
        'market activity',
        'exchanges': [{
            'name': 'a product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume': {
                'amount': 110
            }
        }]
    }, {
        'name':
        'make something else',
        'location':
        'RoW',
        'type':
        'market activity',
        'exchanges': [{
            'name': 'another product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume': {
                'amount': 0
            }
        }]
    }, {
        'name':
        'make something else',
        'location':
        'somewhere else',
        'type':
        'market activity',
        'exchanges': [{
            'name': 'another product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume': {
                'amount': 150
            }
        }]
    }]
    # Can't directly compare dictionaries if order has changed
    hashify = lambda x: {(y['name'], y['location'], y['exchanges'][0][
        'production volume']['amount'])
                         for y in x}
    assert hashify(relabel_global_to_row(given)) == hashify(expected)
コード例 #11
0
ファイル: rest_of_world.py プロジェクト: damanncarlos/Ocelot
def test_relabel_global_to_row_ignore_zero_dropped_products():
    given = [{
        'name':
        'make something',
        'location':
        'GLO',
        'type':
        'market activity',
        'exchanges': [{
            'name': 'a product',
            'unit': '',
            'type': 'reference product',
            'production volume': {
                'amount': 0
            },
            'amount': 1,
        }, {
            'name': 'another product',
            'unit': '',
            'type': 'byproduct',
            'byproduct classification': 'allocatable product',
            'production volume': {
                'amount': 0
            },
            'amount': 0,
        }]
    }, {
        'name':
        'make something',
        'location':
        'somewhere else',
        'unit':
        '',
        'type':
        'market activity',
        'exchanges': [{
            'name': 'a product',
            'unit': '',
            'type': 'reference product',
            'amount': 1,
            'production volume': {
                'amount': 0
            }
        }]
    }]
    expected = [{
        'name':
        'make something',
        'location':
        'RoW',
        'type':
        'market activity',
        'exchanges': [{
            'name': 'a product',
            'unit': '',
            'type': 'reference product',
            'amount': 1,
            'production volume': {
                'amount': 0
            }
        }, {
            'name': 'another product',
            'unit': '',
            'type': 'byproduct',
            'byproduct classification': 'allocatable product',
            'production volume': {
                'amount': 0
            },
            'amount': 0,
        }]
    }, {
        'name':
        'make something',
        'location':
        'somewhere else',
        'type':
        'market activity',
        'exchanges': [{
            'name': 'a product',
            'unit': '',
            'type': 'reference product',
            'amount': 1,
            'production volume': {
                'amount': 0
            }
        }]
    }]
    # Can't directly compare dictionaries if order has changed
    hashify = lambda x: {(y['name'], y['location']) for y in x}
    assert hashify(relabel_global_to_row(given)) == hashify(expected)
コード例 #12
0
ファイル: rest_of_world.py プロジェクト: OcelotProject/Ocelot
def test_relabel_global_to_row_subtract_pv_overspecified_regional_pv():
    given = [{
        'name': 'make something',
        'location': 'GLO',
        'unit': '',
        'type': 'market activity',
        'exchanges': [{
            'name': 'a product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume':{
                'amount':100
            }
        }]
    }, {
        'name': 'make something',
        'location': 'somewhere else',
        'unit': '',
        'type': 'market activity',
        'exchanges': [{
            'name': 'a product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume':{
                'amount':110
            }
        }]
    }, {
        'name': 'make something else',
        'location': 'GLO',
        'unit': '',
        'type': 'market activity',
        'exchanges': [{
            'name': 'a product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume':{
                'amount':100
            }
        }]
    }, {
        'name': 'make something else',
        'location': 'somewhere else',
        'unit': '',
        'type': 'market activity',
        'exchanges': [{
            'name': 'a product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume':{
                'amount':150
            }
        }]
    }]
    expected = [{
        'name': 'make something',
        'location': 'RoW',
        'type': 'market activity',
        'exchanges': [{
            'name': 'a product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume':{
                'amount':0
            }
        }]
    }, {
        'name': 'make something',
        'location': 'somewhere else',
        'type': 'market activity',
        'exchanges': [{
            'name': 'a product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume':{
                'amount':110
            }
        }]
    }, {
        'name': 'make something else',
        'location': 'RoW',
        'type': 'market activity',
        'exchanges': [{
            'name': 'another product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume':{
                'amount':0
            }
        }]
    }, {
        'name': 'make something else',
        'location': 'somewhere else',
        'type': 'market activity',
        'exchanges': [{
            'name': 'another product',
            'type': 'reference product',
            'unit': '',
            'amount': 1,
            'production volume':{
                'amount':150
            }
        }]
    }]
    # Can't directly compare dictionaries if order has changed
    hashify = lambda x: {(y['name'], y['location'], y['exchanges'][0]['production volume']['amount']) for y in x}
    assert hashify(relabel_global_to_row(given)) == hashify(expected)
コード例 #13
0
ファイル: rest_of_world.py プロジェクト: OcelotProject/Ocelot
def test_relabel_global_to_row_ignore_zero_dropped_products():
    given = [{
        'name': 'make something',
        'location': 'GLO',
        'type': 'market activity',
        'exchanges': [{
            'name': 'a product',
            'unit': '',
            'type': 'reference product',
            'production volume': {'amount': 0},
            'amount': 1,
        }, {
            'name': 'another product',
            'unit': '',
            'type': 'byproduct',
            'byproduct classification': 'allocatable product',
            'production volume': {'amount': 0},
            'amount': 0,
        }]
    }, {
        'name': 'make something',
        'location': 'somewhere else',
        'unit': '',
        'type': 'market activity',
        'exchanges': [{
            'name': 'a product',
            'unit': '',
            'type': 'reference product',
            'amount': 1,
            'production volume': {'amount': 0}
        }]
    }]
    expected = [{
        'name': 'make something',
        'location': 'RoW',
        'type': 'market activity',
        'exchanges': [{
            'name': 'a product',
            'unit': '',
            'type': 'reference product',
            'amount': 1,
            'production volume': {'amount': 0}
        }, {
            'name': 'another product',
            'unit': '',
            'type': 'byproduct',
            'byproduct classification': 'allocatable product',
            'production volume': {'amount': 0},
            'amount': 0,
        }]
    }, {
        'name': 'make something',
        'location': 'somewhere else',
        'type': 'market activity',
        'exchanges': [{
            'name': 'a product',
            'unit': '',
            'type': 'reference product',
            'amount': 1,
            'production volume': {'amount': 0}
        }]
    }]
    # Can't directly compare dictionaries if order has changed
    hashify = lambda x: {(y['name'], y['location']) for y in x}
    assert hashify(relabel_global_to_row(given)) == hashify(expected)