Beispiel #1
0
def test_find_exchanges_exchange_object(db):
    a = Database("test").get("3")
    exchanges = []
    for exc in a.technosphere():
        if exc.input.key == ('test', '2'):
            exchanges.append(exc)
    for exc in a.biosphere():
        if exc.input.key == ('bio', 'a'):
            exchanges.append(exc)
    im = InventoryBaseModel()
    result = im.find_exchanges(exchanges)
    expected = [{
        'amount': 2,
        'type': 'technosphere',
        'input': ('test', '2'),
        'uncertainty type': 0,
        'output': ('test', '3')
    }, {
        'amount': 22,
        'type': 'biosphere',
        'input': ('bio', 'a'),
        'uncertainty type': 0,
        'output': ('test', '3')
    }]
    assert result == expected
Beispiel #2
0
def test_find_exchanges_three_tuple(db):
    im = InventoryBaseModel()
    result = im.find_exchanges([
        (('test', '2'), ('test', '3'), 'technosphere'),
        (('bio', 'a'), ('test', '3'), 'biosphere'),
    ])
    expected = [{
        'amount': 2,
        'type': 'technosphere',
        'input': ('test', '2'),
        'uncertainty type': 0,
        'output': ('test', '3')
    }, {
        'amount': 22,
        'type': 'biosphere',
        'input': ('bio', 'a'),
        'uncertainty type': 0,
        'output': ('test', '3')
    }]
    assert result == expected
Beispiel #3
0
def test_presample_creation():
    exchanges = [
        {
            'input': 0,
            'output': 1,
            'type': 'technosphere'
        },
        {
            'input': 2,
            'output': 3,
            'type': 'production'
        },
        {
            'input': 4,
            'output': 5,
            'type': 'biosphere'
        },
        {
            'input': 6,
            'output': 7,
            'type': 'biosphere'
        },
    ]
    model = InventoryBaseModel()
    model.data = exchanges
    model.matrix_array = np.arange(20).reshape((4, 5))
    package = model.create_stored_presample_package("test")
    assert package.id == 1
    assert package.name == "test"
    assert package.description is None
    mp = PackagesDataLoader([package.path])
    assert len(mp.matrix_data_loaded) == 1
    assert mp.matrix_data_loaded[0]['name'] == 'test'
    assert 'id' in mp.matrix_data_loaded[0]
    b, t = mp.matrix_data_loaded[0]['matrix-data']
    assert b['matrix'] == 'biosphere_matrix'
    assert t['matrix'] == 'technosphere_matrix'
    assert b['samples'].data[0].shape == (2, 5)
    assert t['samples'].data[0].shape == (2, 5)
Beispiel #4
0
def test_find_exchanges_with_type_none_error(db):
    im = InventoryBaseModel()
    with pytest.raises(ValueError):
        im.find_exchanges([(('test', '3'), ('test', '2'), 'technosphere')])
Beispiel #5
0
def test_find_exchanges_with_type_multiple_error(db):
    im = InventoryBaseModel()
    im.find_exchanges([(('test', '3'), ('test', '3'), 'production')])
    with pytest.raises(ValueError):
        im.find_exchanges([(('test', '3'), ('test', '3'), 'technosphere')])
Beispiel #6
0
def test_find_exchanges_none_error(db):
    im = InventoryBaseModel()
    with pytest.raises(ValueError):
        im.find_exchanges([(('test', '10'), ('test', '11'))])
Beispiel #7
0
def test_find_exchanges_wrong_type(db):
    im = InventoryBaseModel()
    with pytest.raises(ValueError):
        im.find_exchanges(['3'])
Beispiel #8
0
def test_no_matrix_array(db):
    im = InventoryBaseModel()
    with pytest.raises(ValueError):
        im.matrix_data