Skip to content

Commit

Permalink
Merge pull request #268 from statisticsnorway/feature/dpmeta-153-chec…
Browse files Browse the repository at this point in the history
…k-dataset-path

New method for verifying naming conventions
  • Loading branch information
JanhSander authored Apr 4, 2024
2 parents 0a99fa3 + 314be44 commit 5c5f5b0
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

- name: Install Poetry
run: |
pipx install --pip-args "-c .github/workflows/constraints.txt" poetry
pipx install --pip-args "-c ${{ github.workspace }}/.github/workflows/constraints.txt" poetry
poetry --version
- name: Set up Python
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ jobs:

- name: Upgrade pip
run: |
pip install -c .github/workflows/constraints.txt pip
pip install -c ${{ github.workspace }}/.github/workflows/constraints.txt pip
pip --version
- name: Install Poetry
run: |
pip install -c .github/workflows/constraints.txt poetry
pip install -c ${{ github.workspace }}/.github/workflows/constraints.txt poetry
poetry --version
- name: Check if there is a parent commit
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:

- name: Upgrade pip
run: |
pip install -c .github/workflows/constraints.txt pip
pip install -c ${{ github.workspace }}/.github/workflows/constraints.txt pip
pip --version
- name: Upgrade pip in virtual environments
Expand All @@ -62,13 +62,13 @@ jobs:
- name: Install Poetry
run: |
pipx install --pip-args "-c .github/workflows/constraints.txt" poetry
pipx install --pip-args "-c ${{ github.workspace }}/.github/workflows/constraints.txt" poetry
poetry --version
- name: Install Nox
run: |
pipx install --pip-args "-c .github/workflows/constraints.txt" nox
pipx inject --pip-args "-c .github/workflows/constraints.txt" nox nox-poetry
pipx install --pip-args "-c ${{ github.workspace }}/.github/workflows/constraints.txt" nox
pipx inject --pip-args "-c ${{ github.workspace }}/.github/workflows/constraints.txt" nox nox-poetry
nox --version
- name: Compute pre-commit cache key
Expand Down Expand Up @@ -131,18 +131,18 @@ jobs:

- name: Upgrade pip
run: |
pip install -c .github/workflows/constraints.txt pip
pip install -c ${{ github.workspace }}/.github/workflows/constraints.txt pip
pip --version
- name: Install Poetry
run: |
pipx install --pip-args "-c .github/workflows/constraints.txt" poetry
pipx install --pip-args "-c ${{ github.workspace }}/.github/workflows/constraints.txt" poetry
poetry --version
- name: Install Nox
run: |
pipx install --pip-args "-c .github/workflows/constraints.txt" nox
pipx inject --pip-args "-c .github/workflows/constraints.txt" nox nox-poetry
pipx install --pip-args "-c ${{ github.workspace }}/.github/workflows/constraints.txt" nox
pipx inject --pip-args "-c ${{ github.workspace }}/.github/workflows/constraints.txt" nox nox-poetry
nox --version
- name: Download coverage data
Expand Down
12 changes: 12 additions & 0 deletions src/datadoc/backend/dapla_dataset_path_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,15 @@ def statistic_short_name(
if i in dataset_path_parts and dataset_path_parts.index(i) != 0:
return dataset_path_parts[dataset_path_parts.index(i) - 1]
return None

def path_complies_with_naming_standard(self) -> bool:
"""Checks if path is valid according to SSB standard."""
if (
self.dataset_state
and self.statistic_short_name
and self.contains_data_from
and self.contains_data_until
and self.dataset_version
):
return True
return False
26 changes: 26 additions & 0 deletions tests/backend/test_dapla_dataset_path_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,29 @@ def test_date_format_correct_end_date(date_format, period, expected):
)
def test_extract_shortname_in_path(data: str, expected: str):
assert DaplaDatasetPathInfo(data).statistic_short_name == expected


@pytest.mark.parametrize(
("data"),
[
"gs://ssb-staging-dapla-felles-data-delt/person_data_p2022_v1.parquet",
"gs://ssb-staging-dapla-felles-data-delt/datadoc/person_data_v1.parquet",
"gs://ssb-staging-dapla-felles-data-delt/datadoc/person_data_p2021_v3.parquet",
"gs://ssb-staging-dapla-felles-data-delt/datadoc/utdata/person_data_v1.parquet",
"gs://ssb-staging-dapla-felles-data-delt/datadoc/utdata/person_data_p2021.parquet",
],
)
def test_path_complies_with_naming_standard_invalid_input(data: str):
assert DaplaDatasetPathInfo(data).path_complies_with_naming_standard() is False


@pytest.mark.parametrize(
("data"),
[
"gs://ssb-staging-dapla-felles-data-delt/datadoc/utdata/person_data_p2021_v2.parquet",
"gs://ssb-staging-dapla-felles-data-delt/datadoc/utdata/person_data_p2021_p2022_v2.parquet",
"gs://ssb-staging-dapla-felles-data-delt/datadoc/utdata/undermappe/person_data_p2021_v2.parquet",
],
)
def test_path_complies_with_naming_standard_valid_input(data: str):
assert DaplaDatasetPathInfo(data).path_complies_with_naming_standard() is True

0 comments on commit 5c5f5b0

Please sign in to comment.