@@ -459,56 +459,87 @@ def test_bad_regex_search(tmp_path: Path, caplog) -> None:
459
459
assert "Invalid regex" in caplog .text
460
460
461
461
462
- def test_datafileupdater_replaces_key (tmp_path : Path , fixtures_path : Path ) -> None :
463
- """A key specific key is replaced and nothing else is touched."""
464
- # Arrange
465
- config_path = tmp_path / "pyproject.toml"
466
- fixture_path = fixtures_path / "partial_version_strings.toml"
467
- shutil .copy (fixture_path , config_path )
462
+ class TestDataFileUpdater :
463
+ """Tests for the DataFileUpdater class."""
468
464
469
- contents_before = config_path .read_text ()
470
- conf = config .get_configuration (config_file = config_path , files = [{"filename" : str (config_path )}])
471
- version_config = VersionConfig (conf .parse , conf .serialize , conf .search , conf .replace , conf .parts )
472
- current_version = version_config .parse (conf .current_version )
473
- new_version = current_version .bump ("minor" , version_config .order )
474
- datafile_config = FileChange (
475
- filename = str (config_path ),
476
- key_path = "tool.bumpversion.current_version" ,
477
- search = conf .search ,
478
- replace = conf .replace ,
479
- regex = conf .regex ,
480
- ignore_missing_version = conf .ignore_missing_version ,
481
- serialize = conf .serialize ,
482
- parse = conf .parse ,
483
- )
465
+ def test_update_file_does_not_modify_non_toml_files (self , tmp_path : Path ) -> None :
466
+ """A non-TOML file is not modified."""
467
+ # Arrange
468
+ version_path = tmp_path / "VERSION"
469
+ version_path .write_text ("1.2.3" )
484
470
485
- # Act
486
- files .DataFileUpdater (datafile_config , version_config .part_configs ).update_file (
487
- current_version , new_version , get_context (conf )
488
- )
471
+ overrides = {"current_version" : "1.2.3" , "files" : [{"filename" : str (version_path )}]}
472
+ conf , version_config , current_version = get_config_data (overrides )
473
+ new_version = current_version .bump ("patch" , version_config .order )
474
+ datafile_config = FileChange (
475
+ filename = str (version_path ),
476
+ key_path = "" ,
477
+ search = conf .search ,
478
+ replace = conf .replace ,
479
+ regex = conf .regex ,
480
+ ignore_missing_version = conf .ignore_missing_version ,
481
+ serialize = conf .serialize ,
482
+ parse = conf .parse ,
483
+ )
489
484
490
- # Assert
491
- contents_after = config_path .read_text ()
492
- toml_data = tomlkit .parse (config_path .read_text ()).unwrap ()
493
- actual_difference = list (
494
- context_diff (
495
- contents_before .splitlines (),
496
- contents_after .splitlines (),
497
- fromfile = "before" ,
498
- tofile = "after" ,
499
- n = 0 ,
500
- lineterm = "" ,
485
+ # Act
486
+ files .DataFileUpdater (datafile_config , version_config .part_configs ).update_file (
487
+ current_version , new_version , get_context (conf )
501
488
)
502
- )
503
- expected_difference = [
504
- "*** before" ,
505
- "--- after" ,
506
- "***************" ,
507
- "*** 28 ****" ,
508
- '! current_version = "0.0.2"' ,
509
- "--- 28 ----" ,
510
- '! current_version = "0.1.0"' ,
511
- ]
512
- assert actual_difference == expected_difference
513
- assert toml_data ["tool" ]["pdm" ]["dev-dependencies" ]["lint" ] == ["ruff==0.0.292" ]
514
- assert toml_data ["tool" ]["bumpversion" ]["current_version" ] == "0.1.0"
489
+
490
+ # Assert
491
+ assert version_path .read_text () == "1.2.3"
492
+
493
+ def test_update_replaces_key (self , tmp_path : Path , fixtures_path : Path ) -> None :
494
+ """A key specific key is replaced and nothing else is touched."""
495
+ # Arrange
496
+ config_path = tmp_path / "pyproject.toml"
497
+ fixture_path = fixtures_path / "partial_version_strings.toml"
498
+ shutil .copy (fixture_path , config_path )
499
+
500
+ contents_before = config_path .read_text ()
501
+ conf = config .get_configuration (config_file = config_path , files = [{"filename" : str (config_path )}])
502
+ version_config = VersionConfig (conf .parse , conf .serialize , conf .search , conf .replace , conf .parts )
503
+ current_version = version_config .parse (conf .current_version )
504
+ new_version = current_version .bump ("minor" , version_config .order )
505
+ datafile_config = FileChange (
506
+ filename = str (config_path ),
507
+ key_path = "tool.bumpversion.current_version" ,
508
+ search = conf .search ,
509
+ replace = conf .replace ,
510
+ regex = conf .regex ,
511
+ ignore_missing_version = conf .ignore_missing_version ,
512
+ serialize = conf .serialize ,
513
+ parse = conf .parse ,
514
+ )
515
+
516
+ # Act
517
+ files .DataFileUpdater (datafile_config , version_config .part_configs ).update_file (
518
+ current_version , new_version , get_context (conf )
519
+ )
520
+
521
+ # Assert
522
+ contents_after = config_path .read_text ()
523
+ toml_data = tomlkit .parse (config_path .read_text ()).unwrap ()
524
+ actual_difference = list (
525
+ context_diff (
526
+ contents_before .splitlines (),
527
+ contents_after .splitlines (),
528
+ fromfile = "before" ,
529
+ tofile = "after" ,
530
+ n = 0 ,
531
+ lineterm = "" ,
532
+ )
533
+ )
534
+ expected_difference = [
535
+ "*** before" ,
536
+ "--- after" ,
537
+ "***************" ,
538
+ "*** 28 ****" ,
539
+ '! current_version = "0.0.2"' ,
540
+ "--- 28 ----" ,
541
+ '! current_version = "0.1.0"' ,
542
+ ]
543
+ assert actual_difference == expected_difference
544
+ assert toml_data ["tool" ]["pdm" ]["dev-dependencies" ]["lint" ] == ["ruff==0.0.292" ]
545
+ assert toml_data ["tool" ]["bumpversion" ]["current_version" ] == "0.1.0"
0 commit comments