Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/__pycache__/
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ contribution. These files are created from the database using the script `script
The Processing application's contribution manager reads in a `contribs.txt` file.
This file is created from the database using the script `scripts/to_contribs_txt.py`.

These artifacts are created and released via Github Actions.

## Contributing

Thanks for your interest in contributing to this repository.
The scripts are currently written in Python.

Because much of this repository is workflows and automation, we recommend to run the workflows on your fork before
creating pull requests.

## Contributors

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ruamel.yaml
tenacity~=9.0.0
requests~=2.32.3
pydantic~=2.9.2
pydantic~=2.11
javaproperties~=0.8.2
pytest
Empty file added scripts/__init__.py
Empty file.
20 changes: 6 additions & 14 deletions scripts/parse_and_validate_properties_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
Reads a properties txt file from a library's release artifacts,
and validates the contents. If valid, it returns the contents
as an object.

TODO: write tests for validation
"""
import json
import argparse
Expand All @@ -13,38 +11,32 @@
import re
import os
from typing import Optional, Union
from pydantic import BaseModel, Field, ConfigDict, field_validator
from pydantic import BaseModel, Field, ConfigDict, field_validator, AliasChoices
import javaproperties as jp



class PropertiesBase(BaseModel):
name: str
authors: str
authors: str = Field(validation_alias=AliasChoices('authors','authorList'))
url: str
categories: Optional[str] = Field(None)
categories: Optional[str] = Field(None, validation_alias=AliasChoices('categories','category'))
sentence: str
paragraph: Optional[str] = None
version: int
prettyVersion: str
minRevision: int = Field(0)
maxRevision: int = Field(0)
modes: Optional[str] = Field(None, alias='compatibleModesList')
modes: Optional[str] = Field(None, validation_alias=AliasChoices('modes','compatibleModesList'))

model_config = ConfigDict(
extra='allow',
)

class PropertiesExisting(PropertiesBase):
authors: str = Field(alias='authorList')
categories: Optional[str] = Field(None, alias='category')
version: Union[int, str]
prettyVersion: Optional[str] = None

model_config = ConfigDict(
extra='allow',
populate_by_name=True,
)

@field_validator('minRevision', 'maxRevision', mode='before')
def default_on_error(cls, v):
if v.isdigit():
Expand All @@ -54,7 +46,7 @@ def default_on_error(cls, v):


class LibraryPropertiesNew(PropertiesBase):
categories: str
categories: str = Field(validation_alias=AliasChoices('categories','category'))


@retry(stop=stop_after_attempt(3),
Expand Down
Empty file added tests/__init__.py
Empty file.
Empty file added tests/unit/__init__.py
Empty file.
132 changes: 132 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import pytest


# Test Fixtures
@pytest.fixture
def valid_properties_data():
"""Complete valid data for PropertiesExisting"""
return {
"name": "Test Library",
"authors": "John Doe, Jane Smith",
"url": "https://example.com/library",
"categories": "utility,helper",
"sentence": "A helpful test library for demonstrations",
"paragraph": "This is a more detailed description of the test library.",
"version": "1",
"prettyVersion": "1.0.0",
"minRevision": "5",
"maxRevision": "10",
"modes": "standard,debug"
}


@pytest.fixture
def valid_properties_data_aliases():
"""Complete valid data for PropertiesExisting"""
return {
"name": "Test Library",
"authorList": "John Doe, Jane Smith",
"url": "https://example.com/library",
"category": "utility,helper",
"sentence": "A helpful test library for demonstrations",
"paragraph": "This is a more detailed description of the test library.",
"version": "1",
"prettyVersion": "1.0.0",
"minRevision": "5",
"maxRevision": "10",
"compatibleModesList": "standard,debug"
}


@pytest.fixture
def minimal_properties_base_data():
"""Minimal required data for PropertiesExisting"""
return {
"name": "Minimal Library",
"authors": "Test Author",
"url": "https://minimal.com",
"sentence": "A minimal test case",
"version": "1",
"prettyVersion": "1.0"
}


@pytest.fixture
def minimal_properties_base_data_aliases():
"""Minimal required data for PropertiesExisting"""
return {
"name": "Minimal Library",
"authorList": "Test Author",
"url": "https://minimal.com",
"sentence": "A minimal test case",
"version": "1",
"prettyVersion": "1.0"
}


@pytest.fixture
def minimal_properties_existing_data():
"""Minimal required data for PropertiesExisting"""
return {
"name": "Minimal Library",
"authors": "Test Author",
"url": "https://minimal.com",
"sentence": "A minimal test case",
"version": "1",
}


@pytest.fixture
def minimal_properties_existing_data_aliases():
"""Minimal required data for PropertiesExisting"""
return {
"name": "Minimal Library",
"authorList": "Test Author",
"url": "https://minimal.com",
"sentence": "A minimal test case",
"version": "1",
}


@pytest.fixture
def minimal_properties_library_data():
"""Minimal required data for PropertiesExisting"""
return {
"name": "Minimal Library",
"authors": "Test Author",
"url": "https://minimal.com",
"categories": "minimal,library",
"sentence": "A minimal test case",
"version": "1",
"prettyVersion": "1.0"
}


@pytest.fixture
def minimal_properties_library_data_aliases():
"""Minimal required data for PropertiesExisting"""
return {
"name": "Minimal Library",
"authorList": "Test Author",
"url": "https://minimal.com",
"category": "minimal,library",
"sentence": "A minimal test case",
"version": "1",
"prettyVersion": "1.0"
}


@pytest.fixture
def properties_with_extra_fields():
"""Data with extra fields (should be allowed due to extra='allow')"""
return {
"name": "Extra Fields Library",
"authors": "Extra Author",
"url": "https://extra.com",
"categories": "extra,fields",
"sentence": "Library with extra fields",
"version": "2",
"prettyVersion": "2.0",
"customField": "custom value",
"anotherExtra": "42"
}
Loading