testingfix-unit-tests
Refactor unit test files by aligning strings, renaming methods, and factoring out common test code
소스 정보
- 저장소
- causify-ai/helpers
- 최근 소스 활동
- 2026년 3월 18일 15:30
- 감지된 SKILL.md 언어
- 영어
- 스타
- 146
- 포크
- 162
설치 방법
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
소스 파일 검토
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
SKILL.md 표시 중
SKILL.md
소스 지침 · 읽기 전용 미리보기- name
- testing.fix_unit_tests
- description
- Refactor unit test files by aligning strings, renaming methods, and factoring out common test code
- When I pass you a test file apply the following transformations to the code,
making sure that there is no change in behavior.
## Align Strings to the Code
- Instead of this
```python
def hello()
...
content = """<start:file1.txt>
Content for file1
<start:file2.txt>
Content for file2
"""
```
align the content of the string to the rest of the code
```python
def hello()
...
content = """
<start:file1.txt>
Content for file1
<start:file2.txt>
Content for file2
"""
content = hprint.dedent(content)
```
## Rename the Test Methods as `test1`, `test2`, ...
## Factor Out Common Coded
- Aggressively factor out common code in helper code so that each test method
sets the inputs and the expected value and then calls the helper function with
the common code
- Instead of:
```python
def test_first_line(self) -> None:
"""
Test position in first line returns line 1.
"""
# Prepare inputs.
content = "Line 1\nLine 2\nLine 3"
position = 3
# Run test.
actual = dshctsifi._get_line_number(content, position)
# Check outputs.
expected = 1
self.assertEqual(actual, expected)
def test_second_line(self) -> None:
"""
Test position in second line returns line 2.
"""
# Prepare inputs.
content = "Line 1\nLine 2\nLine 3"
position = 10
# Run test.
actual = dshctsifi._get_line_number(content, position)
# Check outputs.
expected = 2
self.assertEqual(actual, expected)
```
- Do
```python
def helper(self, content: str, position: int, expected: int) -> None:
# Run test.
actual = dshctsifi._get_line_number(content, position)
# Check outputs.
self.assertEqual(actual, expected)
def test1(self) -> None:
"""
Test position in first line returns line 1.
"""
# Prepare inputs.
content = "Line 1\nLine 2\nLine 3"
position = 3
expected = 1
# Run test.
self.helper(content, position, expected)
def test2(self) -> None:
"""
Test position in second line returns line 2.
"""
# Prepare inputs.
content = "Line 1\nLine 2\nLine 3"
position = 10
expected = 2
# Run test.
self.helper(content, position, expected)
```
## Avoid Replicated Assignment
- If a variable `var` and `expected` need to always be the same (e.g., to show
that a variable doesn't change), instead of replicating the assignment, do an
assignment
```python
expected = var
```
- **Bad**
```python
def test2(self) -> None:
"""
Test indented code block with correct indentation.
"""
# Prepare inputs.
txt = """
- Delete unused reference files
```bash
> rm Dockerfile.ubuntu
```
"""
# Expected: no changes needed.
expected = """
- Delete unused reference files
```bash
> rm Dockerfile.ubuntu
```
"""
# Run test.
self.helper(txt, expected)
```
- **Good**
```python
def test2(self) -> None:
"""
Test indented code block with correct indentation.
"""
# Prepare inputs.
txt = """
- Delete unused reference files
```bash
> rm Dockerfile.ubuntu
```
"""
# Expected: no changes needed.
expected = txt
# Run test.
self.helper(txt, expected)
```
# Important
- For all the code you must follow the instructions in
@.claude/skills/coding.format_rules/SKILL.md
GitHub에서 보기