|
2 | 2 | from pathlib import Path |
3 | 3 | from typing import cast |
4 | 4 |
|
| 5 | +import pytest |
| 6 | + |
5 | 7 | import codeclone.report as report_mod |
6 | 8 | from codeclone.report import ( |
7 | 9 | build_block_groups, |
@@ -510,60 +512,36 @@ def test_segment_prepare_missing_file(tmp_path: Path) -> None: |
510 | 512 | assert "seg|mod:f" in filtered |
511 | 513 |
|
512 | 514 |
|
513 | | -def test_segment_prepare_syntax_error_file(tmp_path: Path) -> None: |
514 | | - bad = tmp_path / "bad.py" |
515 | | - bad.write_text("def f(:\n pass\n", "utf-8") |
516 | | - group = { |
517 | | - "seg|mod:f": [ |
518 | | - { |
519 | | - "segment_sig": "sig", |
520 | | - "segment_hash": "hash", |
521 | | - "qualname": "mod:f", |
522 | | - "filepath": str(bad), |
523 | | - "start_line": 1, |
524 | | - "end_line": 2, |
525 | | - "size": 2, |
526 | | - } |
527 | | - ] |
528 | | - } |
529 | | - filtered, suppressed = prepare_segment_report_groups(group) |
530 | | - assert suppressed == 0 |
531 | | - assert "seg|mod:f" in filtered |
532 | | - |
533 | | - |
534 | | -def test_segment_prepare_missing_function(tmp_path: Path) -> None: |
535 | | - f = tmp_path / "a.py" |
536 | | - f.write_text("def g():\n return 1\n", "utf-8") |
537 | | - group = { |
538 | | - "seg|mod:f": [ |
539 | | - { |
540 | | - "segment_sig": "sig", |
541 | | - "segment_hash": "hash", |
542 | | - "qualname": "mod:f", |
543 | | - "filepath": str(f), |
544 | | - "start_line": 1, |
545 | | - "end_line": 2, |
546 | | - "size": 2, |
547 | | - } |
548 | | - ] |
549 | | - } |
550 | | - filtered, suppressed = prepare_segment_report_groups(group) |
551 | | - assert suppressed == 0 |
552 | | - assert "seg|mod:f" in filtered |
553 | | - |
| 515 | +@pytest.mark.parametrize( |
| 516 | + ("case", "start_line", "end_line"), |
| 517 | + [ |
| 518 | + ("syntax_error", 1, 2), |
| 519 | + ("missing_function", 1, 2), |
| 520 | + ("empty_range", 10, 12), |
| 521 | + ], |
| 522 | +) |
| 523 | +def test_segment_prepare_unresolvable_cases( |
| 524 | + tmp_path: Path, case: str, start_line: int, end_line: int |
| 525 | +) -> None: |
| 526 | + if case == "syntax_error": |
| 527 | + f = tmp_path / "bad.py" |
| 528 | + f.write_text("def f(:\n pass\n", "utf-8") |
| 529 | + elif case == "missing_function": |
| 530 | + f = tmp_path / "a.py" |
| 531 | + f.write_text("def g():\n return 1\n", "utf-8") |
| 532 | + else: |
| 533 | + f = tmp_path / "a.py" |
| 534 | + f.write_text("def f():\n x = 1\n", "utf-8") |
554 | 535 |
|
555 | | -def test_segment_prepare_empty_range(tmp_path: Path) -> None: |
556 | | - f = tmp_path / "a.py" |
557 | | - f.write_text("def f():\n x = 1\n", "utf-8") |
558 | 536 | group = { |
559 | 537 | "seg|mod:f": [ |
560 | 538 | { |
561 | 539 | "segment_sig": "sig", |
562 | 540 | "segment_hash": "hash", |
563 | 541 | "qualname": "mod:f", |
564 | 542 | "filepath": str(f), |
565 | | - "start_line": 10, |
566 | | - "end_line": 12, |
| 543 | + "start_line": start_line, |
| 544 | + "end_line": end_line, |
567 | 545 | "size": 2, |
568 | 546 | } |
569 | 547 | ] |
|
0 commit comments