harbor run -t openthoughts/tasktrove-exp-rpt-curriculum-medium-curriculum-medium-0155harbor download openthoughts/tasktrove-exp-rpt-curriculum-medium-curriculum-medium-0155MEDIUM DIFFICULTY TASK
Topic: Implement a minimal, self-contained fontbakery-like package under /app/
Overview
You must provide a compact Python package that mimics a tiny subset of FontBakery’s behavior enough for the tests to run deterministically. The package should live under /app/fontbakery with the described modules and symbols. It must be dependency-free and not rely on any real external binaries.
What to implement
1) Package structure (required)
- Create a Python package at /app/fontbakery (i.e., /app/fontbakery/__init__.py).
- Submodules to include:
- /app/fontbakery/utils.py
- /app/fontbakery/checkrunner.py
- /app/fontbakery/profiles/__init__.py
- /app/fontbakery/profiles/fontval.py
2) utils.py
- Implement TEST_FILE(rel_path) that returns a deterministic string representing a test font file path.
- Requirements:
- Accept a single argument rel_path and require it to be a non-empty string.
- Validate input: if rel_path is not a string, raise TypeError; if empty, raise ValueError.
- Return rel_path unchanged (or a simple deterministic transformation, but keep it simple).
- Example: TEST_FILE("mada/Mada-Regular.ttf") -> "mada/Mada-Regular.ttf"
3) checkrunner.py
- Define a simple constant:
- ERROR = 2
- This constant is used by tests to compare check results; keep the exact value.
4) fontval check in profiles
- Implement com_google_fonts_check_fontvalidator(font) as a generator with the exact signature:
- def com_google_fonts_check_fontvalidator(font):
yield (status, message)
- Behavior required by tests:
- If the environment PATH is empty (os.environ.get("PATH", "") == ""), raise an OSError to simulate FontVal being missing.
- Otherwise, yield at least one result indicating success, for example:
yield (0, "FontVal check simulated OK")
- The yielded statuses must not be equal to ERROR (2). Use status 0 for the success case.
- The function must be a Python generator (i.e., it must use yield).
5) Import expectations
- The tests will import:
- from fontbakery.utils import TEST_FILE
- from fontbakery.checkrunner import ERROR
- from fontbakery.profiles.fontval import com_google_fonts_check_fontvalidator as check
- Ensure the package exports these modules and symbols with the exact names so the imports succeed.
6) Implementation notes / edge cases
- Do not rely on any real FontVal binary. The behavior must be driven deterministically by PATH:
- Empty PATH -> raise OSError
- Non-empty PATH -> yield a non-error result
- Add input validation guards as described for TEST_FILE and for the font argument of the generator.
- The code should be dependency-free and runnable in isolation.
7) What to consider (moderate edge cases)
- TEST_FILE: passing a non-string should raise TypeError; passing an empty string should raise ValueError.
- PATH: test scenarios where PATH is an empty string vs contains whitespace only vs a non-empty path. Your code should treat only an exactly empty PATH as the error condition per the specification; whitespace-only PATH should be considered non-empty (so it does not raise).
8) Where to implement
- Place all code under /app/ in the described package layout.
9) Hints
- Write a small Python generator (use yield) to fulfill com_google_fonts_check_fontvalidator.
- Use os.environ.get("PATH", "") to detect the FontVal presence condition.
- Do not perform real I/O or rely on external tools.
10) Notes
- The tests do not perform real I/O; TEST_FILE must not attempt to read files.
- The solution must be self-contained with no external dependencies.