Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
CHANGELOG_PATH_FMT = "changelogs/{version}.yaml"
CHANGELOG_CURRENT_PATH = "changelogs/current.yaml"
CHANGELOG_CURRENT_DIR_PATH = "changelogs/current"
CHANGELOG_CURRENT_PLACEHOLDER = "PLACEHOLDER.txt"
CHANGELOG_ENTRY_GLOB = "*/*.rst"
CHANGELOG_CONFIG_PATH = "changelogs/changelogs.yaml"
ENTRY_SEPARATOR = "__"
Expand Down Expand Up @@ -296,6 +297,10 @@ def current_path(self) -> pathlib.Path:
def current_dir_path(self) -> pathlib.Path:
return self.project.path.joinpath(self.rel_current_dir_path)

@property
def current_placeholder_path(self) -> pathlib.Path:
return self.current_dir_path.joinpath(CHANGELOG_CURRENT_PLACEHOLDER)

@cached_property
def current_tpl(self) -> jinja2.Template:
return jinja2.Template(CHANGELOG_CURRENT_TPL)
Expand Down Expand Up @@ -483,6 +488,7 @@ def write_changelog(self, version: _version.Version, text: str) -> None:
def write_current(self) -> None:
if self.entries_layout:
self.current_dir_path.mkdir(parents=True, exist_ok=True)
self.current_placeholder_path.touch()
else:
sections = {
k: v.get("description")
Expand Down Expand Up @@ -514,6 +520,7 @@ def write_version(self, version: _version.Version) -> None:
version_file.write_text(self.dump_yaml(data))
shutil.rmtree(self.current_dir_path)
self.current_dir_path.mkdir()
self.current_placeholder_path.touch()
else:
version_file.write_text(
self.current_path.read_text())
Expand Down
54 changes: 50 additions & 4 deletions py/envoy.base.utils/tests/test_abstract_project_changelogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,25 @@ def test_abstract_changelogs_current_dir_path(patches):
assert "current_dir_path" not in changelogs.__dict__


def test_abstract_changelogs_current_placeholder_path(patches):
changelogs = DummyChangelogs("PROJECT")
patched = patches(
"CHANGELOG_CURRENT_PLACEHOLDER",
("AChangelogs.current_dir_path",
dict(new_callable=PropertyMock)),
prefix="envoy.base.utils.abstract.project.changelog")

with patched as (m_name, m_dir_path):
assert (
changelogs.current_placeholder_path
== m_dir_path.return_value.joinpath.return_value)

assert (
m_dir_path.return_value.joinpath.call_args
== [(m_name, ), {}])
assert "current_placeholder_path" not in changelogs.__dict__


def test_abstract_changelogs_current_tpl(patches):
changelogs = DummyChangelogs("PROJECT")
patched = patches(
Expand Down Expand Up @@ -1185,6 +1204,8 @@ def test_abstract_changelogs_write_current(iters, patches, entries_layout):
dict(new_callable=PropertyMock)),
("AChangelogs.current_dir_path",
dict(new_callable=PropertyMock)),
("AChangelogs.current_placeholder_path",
dict(new_callable=PropertyMock)),
("AChangelogs.current_path",
dict(new_callable=PropertyMock)),
("AChangelogs.current_tpl",
Expand All @@ -1195,7 +1216,13 @@ def test_abstract_changelogs_write_current(iters, patches, entries_layout):
sections = iters(dict, cb=lambda x: (f"K{x}", MagicMock()), count=10)
sections["changes"] = MagicMock()

with patched as (m_entries, m_dir_path, m_path, m_tpl, m_sections):
with patched as (
m_entries,
m_dir_path,
m_placeholder,
m_path,
m_tpl,
m_sections):
m_entries.return_value = entries_layout
m_sections.return_value.items.return_value = sections.items()
assert not changelogs.write_current()
Expand All @@ -1204,11 +1231,15 @@ def test_abstract_changelogs_write_current(iters, patches, entries_layout):
assert (
m_dir_path.return_value.mkdir.call_args
== [(), dict(parents=True, exist_ok=True)])
assert (
m_placeholder.return_value.touch.call_args
== [(), {}])
assert not m_path.return_value.write_text.called
assert not m_dir_path.return_value.__truediv__.called
assert not m_tpl.called
assert not m_sections.called
else:
assert not m_placeholder.return_value.touch.called
assert (
m_path.return_value.write_text.call_args
== [(m_tpl.return_value.render.return_value.lstrip.return_value, ),
Expand Down Expand Up @@ -1311,6 +1342,8 @@ def test_abstract_changelogs_write_version(patches, exists, entries_layout):
dict(new_callable=PropertyMock)),
("AChangelogs.current_dir_path",
dict(new_callable=PropertyMock)),
("AChangelogs.current_placeholder_path",
dict(new_callable=PropertyMock)),
("AChangelogs.datestamp",
dict(new_callable=PropertyMock)),
("AChangelogs.current_path",
Expand All @@ -1321,7 +1354,7 @@ def test_abstract_changelogs_write_version(patches, exists, entries_layout):
version = MagicMock()

with patched as (m_shutil, m_entries, m_clogclass, m_dir_path,
m_datestamp, m_path, m_clog_path, m_dump):
m_placeholder, m_datestamp, m_path, m_clog_path, m_dump):
m_entries.return_value = entries_layout
m_clog_path.return_value.exists.return_value = exists
entries_data = {}
Expand All @@ -1345,6 +1378,7 @@ def test_abstract_changelogs_write_version(patches, exists, entries_layout):
== f"Version file ({m_clog_path.return_value}) already exists")
assert not m_clog_path.return_value.write_text.called
assert not m_path.called
assert not m_placeholder.return_value.touch.called
return
if entries_layout:
assert (
Expand All @@ -1364,7 +1398,11 @@ def test_abstract_changelogs_write_version(patches, exists, entries_layout):
assert (
m_dir_path.return_value.mkdir.call_args
== [(), {}])
assert (
m_placeholder.return_value.touch.call_args
== [(), {}])
else:
assert not m_placeholder.return_value.touch.called
assert (
m_clog_path.return_value.write_text.call_args
== [(m_path.return_value.read_text.return_value, ), {}])
Expand All @@ -1384,6 +1422,8 @@ def test_abstract_changelogs_write_version_entries_parse_error(patches):
dict(new_callable=PropertyMock)),
("AChangelogs.current_dir_path",
dict(new_callable=PropertyMock)),
("AChangelogs.current_placeholder_path",
dict(new_callable=PropertyMock)),
("AChangelogs.current_path",
dict(new_callable=PropertyMock)),
"AChangelogs.changelog_path",
Expand All @@ -1392,7 +1432,7 @@ def test_abstract_changelogs_write_version_entries_parse_error(patches):
version = MagicMock()

with patched as (m_shutil, m_entries, m_clogclass, m_dir_path,
m_path, m_clog_path, m_dump):
m_placeholder, m_path, m_clog_path, m_dump):
m_entries.return_value = True
m_clog_path.return_value.exists.return_value = False
m_clogclass.return_value.get_data_from_entries.side_effect = (
Expand All @@ -1404,6 +1444,7 @@ def test_abstract_changelogs_write_version_entries_parse_error(patches):
assert not m_path.return_value.write_text.called
assert not m_shutil.rmtree.called
assert not m_dir_path.return_value.mkdir.called
assert not m_placeholder.return_value.touch.called


def test_abstract_changelogs_yaml_change_presenter():
Expand Down Expand Up @@ -1826,7 +1867,12 @@ async def execute(func, *args):
version_data["bug_fixes"]
== [{"area": "jwt", "change": "Fixed jwt.\n"}])
assert changelogs.current_dir_path.exists()
assert not list(changelogs.current_dir_path.rglob("*.rst"))
assert changelogs.current_placeholder_path.exists()
assert changelogs.current_placeholder_path.is_file()
assert changelogs.current_placeholder_path.read_text() == ""
assert (
sorted(changelogs.current_dir_path.iterdir())
== [changelogs.current_placeholder_path])


async def test_abstract_changelog_release_date(patches):
Expand Down