Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New method for verifying naming conventions #268

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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