|
| 1 | +"""Tests for the TranscriptEntry class.""" |
| 2 | + |
| 3 | +from datetime import datetime |
| 4 | +from openproficiency import TranscriptEntry, ProficiencyScore, ProficiencyScoreName |
| 5 | + |
| 6 | + |
| 7 | +class TestTranscriptEntry: |
| 8 | + |
| 9 | + # Initializers |
| 10 | + def test_init_required_params(self): |
| 11 | + """Create a transcript entry with required fields.""" |
| 12 | + |
| 13 | + # Arrange |
| 14 | + user_id = "user-123" |
| 15 | + topic_id = "git-commit" |
| 16 | + score = 0.8 |
| 17 | + issuer = "github-learn" |
| 18 | + |
| 19 | + # Act |
| 20 | + entry = TranscriptEntry( |
| 21 | + user_id=user_id, |
| 22 | + topic_id=topic_id, |
| 23 | + score=score, |
| 24 | + issuer=issuer |
| 25 | + ) |
| 26 | + |
| 27 | + # Assert |
| 28 | + assert entry.user_id == user_id |
| 29 | + assert entry._proficiency_score.topic_id == topic_id |
| 30 | + assert entry._proficiency_score.score == score |
| 31 | + assert entry.issuer == issuer |
| 32 | + assert entry.timestamp is not None |
| 33 | + |
| 34 | + def test_init_with_optional_params(self): |
| 35 | + """Create a transcript entry with optional parameters.""" |
| 36 | + |
| 37 | + # Arrange |
| 38 | + user_id = "user-123" |
| 39 | + topic_id = "git-commit" |
| 40 | + score = 0.8 |
| 41 | + issuer = "github-learn" |
| 42 | + timestamp = datetime(2024, 1, 15, 10, 30, 0) |
| 43 | + |
| 44 | + # Act |
| 45 | + entry = TranscriptEntry( |
| 46 | + user_id=user_id, |
| 47 | + topic_id=topic_id, |
| 48 | + score=score, |
| 49 | + issuer=issuer, |
| 50 | + timestamp=timestamp |
| 51 | + ) |
| 52 | + |
| 53 | + # Assert |
| 54 | + assert entry.timestamp == timestamp |
| 55 | + |
| 56 | + def test_init_default_timestamp(self): |
| 57 | + """Test that timestamp defaults to current time.""" |
| 58 | + |
| 59 | + # Arrange |
| 60 | + user_id = "user-123" |
| 61 | + topic_id = "git-commit" |
| 62 | + score = 0.8 |
| 63 | + issuer = "github-learn" |
| 64 | + |
| 65 | + # Act |
| 66 | + before = datetime.now() |
| 67 | + entry = TranscriptEntry( |
| 68 | + user_id=user_id, |
| 69 | + topic_id=topic_id, |
| 70 | + score=score, |
| 71 | + issuer=issuer |
| 72 | + ) |
| 73 | + after = datetime.now() |
| 74 | + |
| 75 | + # Assert |
| 76 | + assert entry.timestamp >= before |
| 77 | + assert entry.timestamp <= after |
| 78 | + |
| 79 | + # Properties |
| 80 | + def test_proficiency_score(self): |
| 81 | + """Test that proficiency_score topic and score.""" |
| 82 | + |
| 83 | + # Arrange |
| 84 | + entry = TranscriptEntry( |
| 85 | + user_id="user-123", |
| 86 | + topic_id="git-commit", |
| 87 | + score=0.8, |
| 88 | + issuer="github-learn" |
| 89 | + ) |
| 90 | + |
| 91 | + # Act |
| 92 | + topic_id = entry.proficiency_score.topic_id |
| 93 | + score = entry.proficiency_score.score |
| 94 | + |
| 95 | + # Assert |
| 96 | + assert topic_id == "git-commit" |
| 97 | + assert score == 0.8 |
| 98 | + |
| 99 | + # Debugging |
| 100 | + def test_repr(self): |
| 101 | + """Test string representation of TranscriptEntry.""" |
| 102 | + |
| 103 | + # Arrange |
| 104 | + entry = TranscriptEntry( |
| 105 | + user_id="user-123", |
| 106 | + topic_id="git-commit", |
| 107 | + score=0.8, |
| 108 | + issuer="github-learn" |
| 109 | + ) |
| 110 | + |
| 111 | + # Act |
| 112 | + repr_str = repr(entry) |
| 113 | + |
| 114 | + # Assert |
| 115 | + assert "TranscriptEntry" in repr_str |
| 116 | + assert "user-123" in repr_str |
| 117 | + assert "git-commit" in repr_str |
| 118 | + assert "0.8" in repr_str |
| 119 | + assert "github-learn" in repr_str |
0 commit comments