Files
ai-workflow-course/modules/13-testing-in-the-ai-era/lab/solution/reference_test_tasks.py
T
claude fbec36cb67 feat(course): build out all 27 modules, capstone, scaffold, and conventions
Scaffold the course repo and author the full curriculum in dependency-chain
order, following the settled build decisions in handoff.md.

- Scaffold: course README, vendor-neutral AGENTS.md (dogfoods Module 5),
  _TEMPLATE.md (the fixed 9-section module shape), root .gitignore, ship config.
- Modules 1-2: reference exemplars (locked for tone/depth/lab style).
- Modules 3-27: full lessons + runnable labs, each following the template,
  respecting the chain, vendor/model-agnostic, with "feel the pain" labs.
- Module 8 hosting comparison web-researched and date-stamped (as of 2026-06-22),
  not written from memory; expansion-zone modules carry Verify-before-publish.
- Capstone: the full loop end to end on the running tasks-app example.

Lab code syntax-checked (Python/shell/YAML); every module has the 7 core
template sections.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TfzV5QvtPDz8LJS3Pu5VLT
2026-06-22 12:18:30 -04:00

76 lines
2.4 KiB
Python

"""Reference test suite for the Module 13 lab. Peek only after you've tried it yourself.
Named `reference_test_tasks.py` (not `test_*.py`) on purpose, so `python -m unittest discover`
does NOT pick it up automatically. To run it directly from the tasks-app folder:
python -m unittest path/to/reference_test_tasks.py
It assumes `tasks.py` is importable (run it from the tasks-app directory, or copy it there).
The point of this file is to show the difference between a test that asserts CURRENT BEHAVIOR
(a tautology that passes against the bug) and a test that encodes INTENT (and fails until the
bug is fixed).
"""
import unittest
from tasks import TaskList
class TestTaskBasics(unittest.TestCase):
def test_add_appends_a_task(self):
tl = TaskList()
tl.add("write the tests")
self.assertEqual(len(tl.tasks), 1)
self.assertEqual(tl.tasks[0].title, "write the tests")
self.assertFalse(tl.tasks[0].done)
def test_complete_marks_done(self):
tl = TaskList()
tl.add("a")
tl.complete(0)
self.assertTrue(tl.tasks[0].done)
def test_pending_excludes_completed(self):
tl = TaskList()
tl.add("a")
tl.add("b")
tl.complete(0)
self.assertEqual([t.title for t in tl.pending()], ["b"])
class TestPendingCount(unittest.TestCase):
def test_count_with_nothing_done_is_a_tautology(self):
# This passes even with the bug, because when nothing is completed
# "total" and "pending" are the same number. It proves almost nothing.
tl = TaskList()
tl.add("a")
tl.add("b")
self.assertEqual(tl.pending_count(), 2)
def test_count_reflects_intent_after_completing_one(self):
# This encodes what `count` is FOR: how many tasks are still pending.
# It FAILS against the planted bug (pending_count returns len(self.tasks)),
# and passes once pending_count returns len(self.pending()).
tl = TaskList()
tl.add("a")
tl.add("b")
tl.complete(0)
self.assertEqual(tl.pending_count(), 1)
def test_count_of_all_done_is_zero(self):
tl = TaskList()
tl.add("a")
tl.complete(0)
self.assertEqual(tl.pending_count(), 0)
# The fix, for reference:
#
# def pending_count(self) -> int:
# return len(self.pending())
if __name__ == "__main__":
unittest.main()