def test_production_volume_keyerror(): dataset = { 'exchanges': [{ 'type': 'reference product', }] } assert production_volume(dataset) is None
def test_production_volume_no_amount(): dataset = { 'exchanges': [{ 'type': 'reference product', 'production volume': {} }] } assert production_volume(dataset) is None
def test_production_volume_multiple(): dataset = { 'exchanges': [{ 'type': 'reference product', }, { 'type': 'reference product', }] } assert production_volume(dataset) is None
def test_production_volume(): dataset = { 'exchanges': [{ 'type': 'something else', 'production volume': { 'amount': 2 }, }, { 'type': 'reference product', 'production volume': { 'amount': 42 }, }] } assert production_volume(dataset) == 42
def test_production_volume_none(): dataset = {'exchanges': []} assert production_volume(dataset) is None
def test_update_market_production_volumes_recursive(): given = [{ 'name': '', 'code': 'a', 'type': 'market group', 'location': 'GLO', 'exchanges': [{ 'name': '', 'type': 'reference product', 'production volume': {}, }], 'suppliers': [ { 'code': 'b' }, { 'code': 'd' }, ] }, { 'name': '', 'code': 'b', 'type': 'market group', 'location': 'NAFTA', 'exchanges': [{ 'name': '', 'type': 'reference product', 'production volume': {}, }], 'suppliers': [{ 'code': 'c' }, { 'production volume': { 'amount': 10 }, 'code': 'e' }] }, { 'name': '', 'code': 'c', 'type': 'market group', 'location': 'US', 'exchanges': [{ 'name': '', 'type': 'reference product', 'production volume': {}, }], 'suppliers': [{ 'production volume': { 'amount': 20 }, 'code': 'f' }] }, { 'name': '', 'code': 'd', 'type': 'market group', 'location': 'CN', 'exchanges': [{ 'name': '', 'type': 'reference product', 'production volume': {}, }], 'suppliers': [{ 'production volume': { 'amount': 30 }, 'code': 'g' }] }] update_market_production_volumes(given, 'market group') assert production_volume(given[0]) == 60 assert production_volume(given[1]) == 30 assert production_volume(given[2]) == 20 assert production_volume(given[3]) == 30
def test_update_market_production_volumes_recursive(): given = [{ 'name': '', 'code': 'a', 'type': 'market group', 'location': 'GLO', 'exchanges': [{ 'name': '', 'type': 'reference product', 'production volume': {}, }], 'suppliers': [ {'code': 'b'}, {'code': 'd'}, ] }, { 'name': '', 'code': 'b', 'type': 'market group', 'location': 'NAFTA', 'exchanges': [{ 'name': '', 'type': 'reference product', 'production volume': {}, }], 'suppliers': [ {'code': 'c'}, {'production volume': {'amount': 10}, 'code': 'e'} ] }, { 'name': '', 'code': 'c', 'type': 'market group', 'location': 'US', 'exchanges': [{ 'name': '', 'type': 'reference product', 'production volume': {}, }], 'suppliers': [ {'production volume': {'amount': 20}, 'code': 'f'} ] }, { 'name': '', 'code': 'd', 'type': 'market group', 'location': 'CN', 'exchanges': [{ 'name': '', 'type': 'reference product', 'production volume': {}, }], 'suppliers': [ {'production volume': {'amount': 30}, 'code': 'g'} ] }] update_market_production_volumes(given, 'market group') assert production_volume(given[0]) == 60 assert production_volume(given[1]) == 30 assert production_volume(given[2]) == 20 assert production_volume(given[3]) == 30