@@ -1540,7 +1540,7 @@ def test_copy_readme_to_docs(mocker):
15401540 mock_os_islink .assert_any_call (expected_destination )
15411541 mock_os_islink .assert_any_call (expected_docs_path )
15421542 mock_os_remove .assert_not_called ()
1543- mock_makedirs .assert_called_once_with ( expected_docs_path , exist_ok = True )
1543+ mock_makedirs .assert_called_with ( Path ( expected_docs_path ) , exist_ok = True )
15441544 mock_open .assert_any_call (expected_destination , "w" )
15451545 mock_open ().write .assert_called_once_with ("dummy content" )
15461546
@@ -1575,7 +1575,7 @@ def islink_side_effect(path):
15751575 mock_os_islink .assert_any_call (expected_destination )
15761576 mock_os_islink .assert_any_call (expected_docs_path )
15771577 mock_os_remove .assert_called_once_with (expected_docs_path )
1578- mock_makedirs .assert_called_once_with ( expected_docs_path , exist_ok = True )
1578+ mock_makedirs .assert_called_with ( Path ( expected_docs_path ) , exist_ok = True )
15791579 mock_open .assert_any_call (expected_destination , "w" )
15801580 mock_open ().write .assert_called_once_with ("dummy content" )
15811581
@@ -1621,81 +1621,67 @@ def test_copy_readme_to_docs_source_not_exists(mocker):
16211621
16221622
16231623def test_copy_changelog_to_docs_handles_symlink (mocker ):
1624- """Tests that the CHANGELOG.md is copied to the docs directory, handling symlinks."""
1625- mock_makedirs = mocker .patch ("os.makedirs" )
1626- mock_shutil_copy = mocker .patch ("shutil.copy" )
1627- mock_os_remove = mocker .patch ("os.remove" )
1628- mock_os_lexists = mocker .patch ("os.path.lexists" , return_value = True )
1629- mock_open = mocker .patch ("builtins.open" , mocker .mock_open (read_data = "dummy content" ))
1624+ """Tests that the CHANGELOG.md is created if it does not exist."""
1625+ mock_os_lexists = mocker .patch ("os.path.lexists" , return_value = False )
1626+ mock_open = mocker .patch ("builtins.open" , mocker .mock_open ())
1627+ mocker .patch ("cli._copy_file_to_docs" ) # Mock the call to _copy_file_to_docs
16301628
16311629 output = "output"
16321630 library_id = "google-cloud-language"
16331631 expected_source = f"{ output } /packages/{ library_id } /CHANGELOG.md"
1634- expected_docs_path = f"{ output } /packages/{ library_id } /docs"
1635- expected_destination = f"{ expected_docs_path } /CHANGELOG.md"
1636-
1637- def islink_side_effect (path ):
1638- if path == expected_destination :
1639- return False
1640- if path == expected_docs_path :
1641- return True
1642- return False
1643-
1644- mock_os_islink = mocker .patch ("os.path.islink" , side_effect = islink_side_effect )
16451632
16461633 _copy_changelog_to_docs (output , library_id )
16471634
16481635 mock_os_lexists .assert_called_once_with (expected_source )
1649- mock_open .assert_any_call (expected_source , "r" )
1650- mock_os_islink .assert_any_call (expected_destination )
1651- mock_os_islink .assert_any_call (expected_docs_path )
1652- mock_os_remove .assert_called_once_with (expected_docs_path )
1653- mock_makedirs .assert_called_once_with (expected_docs_path , exist_ok = True )
1654- mock_open .assert_any_call (expected_destination , "w" )
1655- mock_open ().write .assert_called_once_with ("dummy content" )
1636+ mock_open .assert_called_once_with (expected_source , "w" )
1637+ mock_open ().write .assert_called_once_with ("# Changelog\n " )
16561638
16571639
16581640def test_copy_changelog_to_docs_source_not_exists (mocker ):
1659- """Tests that the function returns early if the source CHANGELOG.md does not exist."""
1660- mock_makedirs = mocker .patch ("os.makedirs" )
1661- mock_shutil_copy = mocker .patch ("shutil.copy" )
1662- mock_os_islink = mocker .patch ("os.path.islink" )
1663- mock_os_remove = mocker .patch ("os.remove" )
1641+ """Tests that the function creates CHANGELOG.md with correct content if it does not exist."""
16641642 mock_os_lexists = mocker .patch ("os.path.lexists" , return_value = False )
1665- mock_open = mocker .patch ("builtins.open" , mocker .mock_open (read_data = "dummy content" ))
1643+ mock_open = mocker .patch ("builtins.open" , mocker .mock_open ())
1644+ mocker .patch ("cli._copy_file_to_docs" ) # Mock the call to _copy_file_to_docs
16661645
16671646 output = "output"
16681647 library_id = "google-cloud-language"
1669- _copy_changelog_to_docs ( output , library_id )
1648+ expected_source = f" { output } /packages/ { library_id } /CHANGELOG.md"
16701649
1671- expected_source = " output/packages/google-cloud-language/CHANGELOG.md"
1650+ _copy_changelog_to_docs ( output , library_id )
16721651
16731652 mock_os_lexists .assert_called_once_with (expected_source )
1674- mock_open .assert_not_called ()
1675- mock_os_islink .assert_not_called ()
1676- mock_os_remove .assert_not_called ()
1677- mock_makedirs .assert_not_called ()
1678- mock_shutil_copy .assert_not_called ()
1653+ mock_open .assert_called_once_with (expected_source , "w" )
1654+ mock_open ().write .assert_called_once_with ("# Changelog\n " )
16791655
16801656
16811657def test_copy_changelog_to_docs_destination_path_is_symlink (mocker ):
16821658 """Tests that the CHANGELOG.md is copied to the docs directory, handling destination_path being a symlink."""
16831659 mock_makedirs = mocker .patch ("os.makedirs" )
16841660 mock_shutil_copy = mocker .patch ("shutil.copy" )
1685- mock_os_islink = mocker .patch ("os.path.islink" , return_value = True )
16861661 mock_os_remove = mocker .patch ("os.remove" )
16871662 mock_os_lexists = mocker .patch ("os.path.lexists" , return_value = True )
1688- mock_open = mocker .patch ("builtins.open" , mocker .mock_open (read_data = "dummy content " ))
1663+ mock_open = mocker .patch ("builtins.open" , mocker .mock_open (read_data = "# Changelog \n " ))
16891664
16901665 output = "output"
16911666 library_id = "google-cloud-language"
1692- _copy_changelog_to_docs (output , library_id )
1693-
16941667 expected_destination = "output/packages/google-cloud-language/docs/CHANGELOG.md"
1695- mock_os_remove . assert_called_once_with ( expected_destination )
1668+ expected_docs_path = "output/packages/google-cloud-language/docs"
16961669
1670+ def islink_side_effect (path ):
1671+ if path == expected_destination :
1672+ return True
1673+ if path == expected_docs_path :
1674+ return False
1675+ return False
16971676
1698- def test_copy_readme_to_docs_source_not_exists (mocker ):
1677+ mock_os_islink = mocker .patch ("os.path.islink" , side_effect = islink_side_effect )
1678+
1679+ _copy_changelog_to_docs (output , library_id )
1680+
1681+ mock_os_remove .assert_called_once_with (expected_destination )
1682+ mock_makedirs .assert_called_with (Path (expected_docs_path ), exist_ok = True )
1683+ mock_open .assert_any_call (expected_destination , "w" )
1684+ mock_open ().write .assert_called_with ("# Changelog\n " )
16991685 """Tests that the function returns early if the source README.rst does not exist."""
17001686 mock_makedirs = mocker .patch ("os.makedirs" )
17011687 mock_shutil_copy = mocker .patch ("shutil.copy" )
0 commit comments