Skip to content

Add unit tests for pure functions #4

@TheTrustedAdvisor

Description

@TheTrustedAdvisor

Problem

The project has zero test coverage. However, several functions are pure (no I/O, no side effects) and immediately testable:

  • parse_weekplan_html(html) — HTML → structured data
  • parse_favorites_html(html) — HTML → structured data
  • parse_shopping_ingredients(shopping_data) — dict → ingredient list
  • format_time(seconds) — int → string
  • seconds_to_minutes(seconds) — int → int
  • format_cookie_header(cookies) — dict → string
  • extract_category_name(recipe_data, category_id) — dict → string

Proposed Solution

Add a tests/ directory with pytest tests:

# tests/test_parsing.py
def test_format_time_minutes():
    assert format_time(1800) == "30 Min"

def test_format_time_hours():
    assert format_time(5400) == "1h 30min"

def test_format_time_none():
    assert format_time(None) == ""

def test_parse_shopping_deduplication():
    data = {"recipes": [
        {"title": "R1", "recipeIngredientGroups": [
            {"ingredientNotation": "Salz", "quantity": {"value": 1}, "unitNotation": "TL", ...}
        ]},
        {"title": "R2", "recipeIngredientGroups": [
            {"ingredientNotation": "Salz", "quantity": {"value": 2}, "unitNotation": "TL", ...}
        ]},
    ]}
    ingredients = parse_shopping_ingredients(data)
    salt = [i for i in ingredients if i["name"] == "Salz"]
    assert len(salt) == 1
    assert salt[0]["quantity"] == 3

Impact

  • Effort: Low (pure functions, no mocking needed)
  • Value: Catches regressions in the parsing logic, enables confident refactoring

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions