|
@@ -1,123 +0,0 @@
|
|
|
-#!/usr/bin/env python3
|
|
|
-import pytest
|
|
|
-from numpy import isnan
|
|
|
-from hashlib import sha256
|
|
|
-
|
|
|
-from rdflib import Namespace
|
|
|
-from probs_runner import PROBS, QUANTITYKIND
|
|
|
-from numpy.testing import assert_allclose
|
|
|
-
|
|
|
-COMTRADE2017 = Namespace("https://ukfires.org/probs/ontology/comtrade/2017/")
|
|
|
-GEONAMES = Namespace("https://sws.geonames.org/")
|
|
|
-
|
|
|
-def assert_exact_results(result, expected_value):
|
|
|
- assert len(result) == 1
|
|
|
- assert result[0].bound == PROBS.ExactBound
|
|
|
- assert_allclose(result[0].measurement, expected_value, rtol=1e-3)
|
|
|
-
|
|
|
-
|
|
|
-def assert_no_measurement(result):
|
|
|
- assert len(result) == 1
|
|
|
- assert isnan(result[0].measurement)
|
|
|
-
|
|
|
-
|
|
|
-def obj_id(obj_code):
|
|
|
-
|
|
|
- return ("Object-" + sha256(obj_code.encode('utf-8')).hexdigest())
|
|
|
-
|
|
|
-
|
|
|
-class TestComtradeImport:
|
|
|
- """Test COMTRADE Import conversion"""
|
|
|
-
|
|
|
- endpoint_data = ["outputs/ct-2018-imports.nt.gz"]
|
|
|
-
|
|
|
- @pytest.mark.parametrize("code,expected_value", [
|
|
|
- ("10121", 1733341),
|
|
|
- ("20110", 31679041),
|
|
|
- ("80310", 41745763),
|
|
|
- ("251120", 1019),
|
|
|
- ("390110", 447125375),
|
|
|
- ("520710", 473405),
|
|
|
- ("620431", 859029),
|
|
|
- ("721590", 19448264),
|
|
|
- ("845969", 5402447)
|
|
|
- ])
|
|
|
-
|
|
|
- def test_expected_measurements(self, rdfox, code, expected_value):
|
|
|
- result = rdfox.get_observations(
|
|
|
- PROBS.TimePeriod_YearOf2018,
|
|
|
- GEONAMES["2635167"] ,
|
|
|
- QUANTITYKIND.Mass,
|
|
|
- PROBS.Import,
|
|
|
- object_=COMTRADE2017[obj_id(code)],
|
|
|
- )
|
|
|
- assert_exact_results(result, expected_value)
|
|
|
-
|
|
|
-
|
|
|
- @pytest.mark.parametrize("code", [
|
|
|
- ("440420"),
|
|
|
- ("722990")
|
|
|
- ])
|
|
|
-
|
|
|
- def test_no_measurements(self, rdfox, code):
|
|
|
- # Test for cases of no data for measurement
|
|
|
- result = rdfox.get_observations(
|
|
|
- PROBS.TimePeriod_YearOf2018,
|
|
|
- GEONAMES["2635167"] ,
|
|
|
- QUANTITYKIND.Mass,
|
|
|
- PROBS.Import,
|
|
|
- object_=COMTRADE2017[obj_id(code)],
|
|
|
- )
|
|
|
- assert_no_measurement(result)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-class TestComtradeExport:
|
|
|
- """Test COMTRADE Export conversion"""
|
|
|
-
|
|
|
- endpoint_data = ["outputs/ct-2018-exports.nt.gz"]
|
|
|
-
|
|
|
-
|
|
|
- @pytest.mark.parametrize("code,expected_value", [
|
|
|
- ("10511", 2316447),
|
|
|
- ("70999", 7979977),
|
|
|
- ("290371", 543901),
|
|
|
- ("440325", 27693018),
|
|
|
- ("540331", 458),
|
|
|
- ("680430", 66781),
|
|
|
- ("790111", 6017177),
|
|
|
- ("851650", 8874060)
|
|
|
- ])
|
|
|
-
|
|
|
-
|
|
|
- def test_expected_measurements(self, rdfox, code, expected_value):
|
|
|
- result = rdfox.get_observations(
|
|
|
- PROBS.TimePeriod_YearOf2018,
|
|
|
- GEONAMES["2635167"] ,
|
|
|
- QUANTITYKIND.Mass,
|
|
|
- PROBS.Export,
|
|
|
- object_=COMTRADE2017[obj_id(code)],
|
|
|
- )
|
|
|
- assert_exact_results(result, expected_value)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- @pytest.mark.parametrize("code", [
|
|
|
- ("140110"),
|
|
|
- ("350211")
|
|
|
- ])
|
|
|
-
|
|
|
- def test_no_measurements(self, rdfox, code):
|
|
|
- # Test for cases of no data for measurement
|
|
|
- result = rdfox.get_observations(
|
|
|
- PROBS.TimePeriod_YearOf2018,
|
|
|
- GEONAMES["2635167"] ,
|
|
|
- QUANTITYKIND.Mass,
|
|
|
- PROBS.Export,
|
|
|
- object_=COMTRADE2017[obj_id(code)],
|
|
|
- )
|
|
|
- assert_no_measurement(result)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|