1414import os
1515sys .path .insert (0 , os .path .dirname (__file__ ))
1616
17- from update_dependency_changes import merge_changes , render_section , normalize_version , extract_preamble
17+ from update_dependency_changes import merge_changes , render_section , normalize_version , extract_preamble , bump_patch_if_released
1818
1919
2020def test_update_then_revert ():
@@ -438,6 +438,55 @@ def test_normalize_version_stable():
438438 print ("✓ Passed: stable versions unchanged\n " )
439439
440440
441+ def test_bump_patch_no_tag ():
442+ """Test: version tag does not exist, should return as-is."""
443+ print ("Test 23: bump_patch_if_released - no tag exists" )
444+ tag_exists = lambda t : False
445+ assert bump_patch_if_released ("10.3.0" , tag_exists ) == "10.3.0"
446+ assert bump_patch_if_released ("10.2.0" , tag_exists ) == "10.2.0"
447+ print ("✓ Passed: version unchanged when tag does not exist\n " )
448+
449+
450+ def test_bump_patch_tag_exists ():
451+ """Test: version tag exists, should bump patch."""
452+ print ("Test 24: bump_patch_if_released - tag exists" )
453+ existing_tags = {"10.3.0" }
454+ tag_exists = lambda t : t in existing_tags
455+ assert bump_patch_if_released ("10.3.0" , tag_exists ) == "10.3.1" , \
456+ f"Expected '10.3.1', got: { bump_patch_if_released ('10.3.0' , tag_exists )} "
457+ print ("✓ Passed: version bumped to 10.3.1\n " )
458+
459+
460+ def test_bump_patch_multiple_tags ():
461+ """Test: multiple consecutive tags exist, should bump past all."""
462+ print ("Test 25: bump_patch_if_released - multiple tags exist" )
463+ existing_tags = {"10.3.0" , "10.3.1" , "10.3.2" }
464+ tag_exists = lambda t : t in existing_tags
465+ assert bump_patch_if_released ("10.3.0" , tag_exists ) == "10.3.3" , \
466+ f"Expected '10.3.3', got: { bump_patch_if_released ('10.3.0' , tag_exists )} "
467+ print ("✓ Passed: version bumped past all existing tags\n " )
468+
469+
470+ def test_bump_patch_prerelease_skipped ():
471+ """Test: pre-release versions should not be bumped."""
472+ print ("Test 26: bump_patch_if_released - pre-release skipped" )
473+ tag_exists = lambda t : True # all tags "exist"
474+ assert bump_patch_if_released ("10.3.0-rc.1" , tag_exists ) == "10.3.0-rc.1"
475+ assert bump_patch_if_released ("10.3.0-rc.2" , tag_exists ) == "10.3.0-rc.2"
476+ assert bump_patch_if_released ("10.3.0-preview" , tag_exists ) == "10.3.0-preview"
477+ print ("✓ Passed: pre-release versions not bumped\n " )
478+
479+
480+ def test_bump_patch_non_zero_patch ():
481+ """Test: version with non-zero patch, tag exists, should bump."""
482+ print ("Test 27: bump_patch_if_released - non-zero patch version" )
483+ existing_tags = {"10.3.1" }
484+ tag_exists = lambda t : t in existing_tags
485+ assert bump_patch_if_released ("10.3.1" , tag_exists ) == "10.3.2" , \
486+ f"Expected '10.3.2', got: { bump_patch_if_released ('10.3.1' , tag_exists )} "
487+ print ("✓ Passed: non-zero patch correctly bumped\n " )
488+
489+
441490def run_all_tests ():
442491 """Run all test cases."""
443492 print ("=" * 70 )
@@ -466,9 +515,14 @@ def run_all_tests():
466515 test_normalize_version_preview ()
467516 test_normalize_version_rc ()
468517 test_normalize_version_stable ()
518+ test_bump_patch_no_tag ()
519+ test_bump_patch_tag_exists ()
520+ test_bump_patch_multiple_tags ()
521+ test_bump_patch_prerelease_skipped ()
522+ test_bump_patch_non_zero_patch ()
469523
470524 print ("=" * 70 )
471- print ("All 22 tests passed! ✓" )
525+ print ("All 27 tests passed! ✓" )
472526 print ("=" * 70 )
473527 print ("\n Test coverage summary:" )
474528 print (" ✓ Basic scenarios (update, add, remove)" )
@@ -478,6 +532,7 @@ def run_all_tests():
478532 print (" ✓ Document format validation" )
479533 print (" ✓ Preamble extraction (SEO block, no preamble, no heading)" )
480534 print (" ✓ Version normalization (preview -> rc.1)" )
535+ print (" ✓ Patch version bump when tag already released" )
481536 print ("=" * 70 )
482537
483538
0 commit comments