Ver Fonte

Add endpoint module to environment and modify tests

stephenjboyle há 8 meses atrás
pai
commit
1d0b11e7bf
4 ficheiros alterados com 15 adições e 18 exclusões
  1. 1 0
      environment.yml
  2. 1 1
      scripts/map_prodcom.dlog
  3. 5 7
      tests/test_prodcom.py
  4. 8 10
      tests/test_prodcom_new.py

+ 1 - 0
environment.yml

@@ -11,6 +11,7 @@ dependencies:
       # These github links can be replaced with plain names/versions once the
       # modules are published
       - git+https://github.com/probs-lab/probs-module-data-conversion.git@a06ddb4ea45274f49ad98fff6b5a5a5f829d14ef#egg=probs-module-data-conversion
+      - git+https://github.com/probs-lab/probs-module-endpoint.git@b5988ede2aa085670563794bca57bf5f9735609b#egg=probs-module-endpoint
       - git+https://github.com/probs-lab/probs-ontology.git@6384788d8ba83810713d8253400ef0f0280a9d4f#egg=probs-module-ontology
       - https://github.com/ukfires/probs-runner/archive/3ddadd094d31ea5d3a62f5d1aae39509e78f3fbd.zip
 

+ 1 - 1
scripts/map_prodcom.dlog

@@ -16,7 +16,7 @@
 
         # TODO Fix the prefix with the year
         BIND(IRI(CONCAT(STR(?DataPrefix), "Observation-", SHA256(?IDstring))) AS ?ID) ,
-        BIND(IRI(CONCAT(STR(?ObjectPrefix), "Object-", SHA256(?PRCCODEstring))) AS ?PRCCode) ,
+        BIND(IRI(CONCAT(STR(?ObjectPrefix), "Object-", ?PRCCODEstring)) AS ?PRCCode) ,
         BIND(IRI(CONCAT(STR(:), "Unit-", SHA256(?QNTUNIT))) AS ?UnitID) .
 
 # if ?PRODQNT is not "absent"

+ 5 - 7
tests/test_prodcom.py

@@ -16,7 +16,6 @@ def assert_exact_results(result, expected_value):
     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)
@@ -24,7 +23,6 @@ def assert_no_measurement(result):
 def assert_no_result(result):
     assert len(result) == 0
 
-
 def obj_id(obj_code):
     return ("Object-" + sha256(obj_code.encode('utf-8')).hexdigest())
 
@@ -49,7 +47,7 @@ class TestProdcom2016Data:
             GEONAMES["2635167"],
             metric,
             PROBS.SoldProduction,
-            object_=PRODCOM2016[obj_id(code)]
+            object_=PRODCOM2016["Object-" + code]
         )
         assert_exact_results(result, expected_value)
 
@@ -66,7 +64,7 @@ class TestProdcom2016Data:
             GEONAMES["2635167"] ,
             metric,
             PROBS.SoldProduction,
-            object_=PRODCOM2016[obj_id(code)],
+            object_=PRODCOM2016["Object-" + code],
         )
         assert_no_measurement(result)
 
@@ -81,7 +79,7 @@ class TestProdcom2016Data:
             GEONAMES["2635167"] ,
             metric,
             PROBS.SoldProduction,
-            object_=PRODCOM2016[obj_id(code)],
+            object_=PRODCOM2016["Object-" + code],
         )
         assert_no_result(result)
 
@@ -106,7 +104,7 @@ class TestProdcom2017Data:
             GEONAMES["2635167"],
             metric,
             PROBS.SoldProduction,
-            object_=PRODCOM2017[obj_id(code)]
+            object_=PRODCOM2017["Object-" + code]
         )
         assert_exact_results(result, expected_value)
 
@@ -131,6 +129,6 @@ class TestProdcom2018Data:
             GEONAMES["2635167"],
             metric,
             PROBS.SoldProduction,
-            object_=PRODCOM2017[obj_id(code)]
+            object_=PRODCOM2017["Object-" + code]
         )
         assert_exact_results(result, expected_value)

+ 8 - 10
tests/test_prodcom_new.py

@@ -16,7 +16,6 @@ def assert_exact_results(result, expected_value):
     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)
@@ -24,7 +23,6 @@ def assert_no_measurement(result):
 def assert_no_result(result):
     assert len(result) == 0
 
-
 def obj_id(obj_code):
     return ("Object-" + sha256(obj_code.encode('utf-8')).hexdigest())
 
@@ -53,11 +51,11 @@ class TestProdcom2016Data:
         )
         assert_exact_results(result, expected_value)
 
-    @pytest.mark.skip(reason="need to update rules so missing observations are still converted")
+#    @pytest.mark.skip(reason="need to update rules so missing observations are still converted")
     @pytest.mark.parametrize("code,metric", [
-        ("14391090", QUANTITYKIND.AmountOfSubstance),
-        ("20141325", QUANTITYKIND.Mass),
-        # This one has no measurement or data at all, so is loaded with metric "Unknown"
+        ("14391090", QUANTITYKIND.AmountOfSubstance),  # No measurement value - No PRDQNT and PQNTFLAG = :C
+        ("20141325", QUANTITYKIND.Mass),               # No measurement value - No PRDQNT and PQNTFLAG = :C
+        # This one has no data at all                    No PRDQNT and PQNTFLAG = -
         ("20421975", QUANTITYKIND.Unknown),
     ])
     def test_missing_measurements(self, rdfox, code, metric):
@@ -69,7 +67,7 @@ class TestProdcom2016Data:
             PROBS.SoldProduction,
             object_=PRODCOM2017["Object-" + code],
         )
-        assert_no_measurement(result)
+        assert_no_result(result)
 
     @pytest.mark.parametrize("code,metric", [
         ("14391090", QUANTITYKIND.Mass),
@@ -87,7 +85,7 @@ class TestProdcom2016Data:
         assert_no_result(result)
 
 
-class TestProdcom2017Data:
+class TesProdcom2017Data:
     """Test PRODCOM2017 DATA conversion.
 
     Just include a few expected values, since other behaviour is tested for the 2016 data.
@@ -108,7 +106,7 @@ class TestProdcom2017Data:
             metric,
             PROBS.SoldProduction,
             # object_code=code
-            object_=PRODCOM2017[obj_id(code)]
+            object_=PRODCOM2017["Object-" + code]
         )
         assert_exact_results(result, expected_value)
 
@@ -133,6 +131,6 @@ class TestProdcom2018Data:
             GEONAMES["2635167"],
             metric,
             PROBS.SoldProduction,
-            object_=PRODCOM2017[obj_id(code)]
+            object_=PRODCOM2017["Object-" + code]
         )
         assert_exact_results(result, expected_value)