From 6d73bc459e33643d302603870f9d818842e0c875 Mon Sep 17 00:00:00 2001 From: Daniel Huppmann Date: Thu, 15 Feb 2024 07:06:24 +0100 Subject: [PATCH 1/7] Add an integration test for consistency with common-definitions --- .github/workflows/integration.yaml | 30 ++++++++++++++++++++++++++++++ tests/test_integration.py | 27 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 .github/workflows/integration.yaml create mode 100644 tests/test_integration.py diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml new file mode 100644 index 0000000..185adbb --- /dev/null +++ b/.github/workflows/integration.yaml @@ -0,0 +1,30 @@ +# This workflow checks that no conflicts exist with the common-definitions repo + +name: Check consistency with common-definitions + +on: + push: + branches: [ main ] + pull_request: + branches: [ '**' ] + schedule: + - cron: '45 5 * * *' + +jobs: + project-validation: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python 3.11 + uses: actions/setup-python@v4 + with: + python-version: 3.11 + + - name: Install requirements + run: pip install nomenclature-iamc pytest + + - name: Run the integration test + run: pytest tests/test_integration.py diff --git a/tests/test_integration.py b/tests/test_integration.py new file mode 100644 index 0000000..24e0e6e --- /dev/null +++ b/tests/test_integration.py @@ -0,0 +1,27 @@ +import pathlib +import yaml + +import nomenclature + + +def test_integration_common_definitions(): + + config_file = "../definitions/nomenclature.yaml" + config = { + "repositories": { + "common-definitions": { + "url": "https://github.com/IAMconsortium/common-definitions.git/" + } + }, + "definitions": { + "region": {"repository": "common-definitions"}, + "variable": {"repository": "common-definitions"}, + }, + } + + with open(config_file, "w") as file: + yaml.dump(config, file) + + nomenclature.DataStructureDefinition("../definitions") + + pathlib.Path(config_file).unlink() From 2cb17779fb44ebec01b702e565c888f8b7d42133 Mon Sep 17 00:00:00 2001 From: Daniel Huppmann Date: Thu, 15 Feb 2024 07:18:21 +0100 Subject: [PATCH 2/7] Add rootdir --- .github/workflows/integration.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 185adbb..31fd42b 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -27,4 +27,4 @@ jobs: run: pip install nomenclature-iamc pytest - name: Run the integration test - run: pytest tests/test_integration.py + run: pytest tests/test_integration.py --rootdir='tests' From b86aa6a3c986d655903f1fdc846fdb003670fe8d Mon Sep 17 00:00:00 2001 From: Daniel Huppmann Date: Thu, 15 Feb 2024 08:08:36 +0100 Subject: [PATCH 3/7] Fix paths --- tests/test_integration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_integration.py b/tests/test_integration.py index 24e0e6e..cc2a71c 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -6,7 +6,7 @@ def test_integration_common_definitions(): - config_file = "../definitions/nomenclature.yaml" + config_file = "nomenclature.yaml" config = { "repositories": { "common-definitions": { @@ -22,6 +22,6 @@ def test_integration_common_definitions(): with open(config_file, "w") as file: yaml.dump(config, file) - nomenclature.DataStructureDefinition("../definitions") + nomenclature.DataStructureDefinition("definitions") pathlib.Path(config_file).unlink() From 16cb7cf807da5fb1af3aa5e995d9c33be40fff7e Mon Sep 17 00:00:00 2001 From: Daniel Huppmann Date: Thu, 15 Feb 2024 08:09:12 +0100 Subject: [PATCH 4/7] Add nomenclature.yaml to gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 259f1a5..fd001a3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ ### common-definitions ### common-definitions +nomenclature.yaml + ### IntelliJ PyCharm ### .idea/ From e2d310d5f0603867760b62ffd8370174ff889f48 Mon Sep 17 00:00:00 2001 From: Daniel Huppmann Date: Thu, 15 Feb 2024 09:48:11 +0100 Subject: [PATCH 5/7] Add try-finally --- tests/test_integration.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_integration.py b/tests/test_integration.py index cc2a71c..6a06fa3 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -22,6 +22,8 @@ def test_integration_common_definitions(): with open(config_file, "w") as file: yaml.dump(config, file) - nomenclature.DataStructureDefinition("definitions") + try: + nomenclature.DataStructureDefinition("definitions") - pathlib.Path(config_file).unlink() + finally: + pathlib.Path(config_file).unlink() From ed4e359313e16c2bc08a05218c1391e46968869b Mon Sep 17 00:00:00 2001 From: Daniel Huppmann Date: Thu, 15 Feb 2024 09:49:07 +0100 Subject: [PATCH 6/7] Remove GDP variables --- definitions/variable/variable.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/definitions/variable/variable.yaml b/definitions/variable/variable.yaml index 0ae2768..56bb2fa 100644 --- a/definitions/variable/variable.yaml +++ b/definitions/variable/variable.yaml @@ -513,12 +513,6 @@ - Consumption: definition: total consumption of all goods, by all consumers in a region unit: billion US$2010/yr -- GDP|MER: - definition: GDP at market exchange rate - unit: billion US$2010/yr -- GDP|PPP: - definition: GDP converted to International $ using purchasing power parity (PPP) - unit: billion US$2010/yr - Value Added|Agriculture: definition: value added of the agricultural sector unit: billion US$2010/yr From 2990faa34fe767a979d124b59b0b1816beceacf3 Mon Sep 17 00:00:00 2001 From: Daniel Huppmann Date: Thu, 15 Feb 2024 10:24:32 +0100 Subject: [PATCH 7/7] Implement suggestion by @phackstock Co-authored-by: Philip Hackstock <20710924+phackstock@users.noreply.github.com> --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index fd001a3..95f691e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ ### common-definitions ### common-definitions -nomenclature.yaml ### IntelliJ PyCharm ### .idea/