From dc0e79d3d3c741932980b2184e435b89749ae0bc Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Tue, 18 Jul 2023 18:45:34 -0400 Subject: [PATCH] test: add a test for pr #101 --- .../20230718_185443_nedbat_add_101_test.rst | 8 +++++ tests/test_collect.py | 33 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 changelog.d/20230718_185443_nedbat_add_101_test.rst diff --git a/changelog.d/20230718_185443_nedbat_add_101_test.rst b/changelog.d/20230718_185443_nedbat_add_101_test.rst new file mode 100644 index 0000000..c9563e4 --- /dev/null +++ b/changelog.d/20230718_185443_nedbat_add_101_test.rst @@ -0,0 +1,8 @@ +Fixed +..... + +- Changelogs with non-version headings now produce an understandable error + message in ``scriv collect``, thanks to `James Gerity `_. + +.. _pull 101: https://github.com/nedbat/scriv/pull/101 + diff --git a/tests/test_collect.py b/tests/test_collect.py index 897cefb..1be7cb7 100644 --- a/tests/test_collect.py +++ b/tests/test_collect.py @@ -545,3 +545,36 @@ def test_duplicate_version_with_v(cli_invoke, changelog_d, temp_dir): str(result.exception) == "Entry 'v12.34.56 — 2022-09-18' already uses version '12.34.56'." ) + + +def test_unparsable_version(cli_invoke, changelog_d, temp_dir): + (changelog_d / "scriv.ini").write_text("[scriv]\nversion = 12.34.56\n") + (temp_dir / "CHANGELOG.rst").write_text( + textwrap.dedent( + """\ + Preamble that doesn't count + + v12.34.57 — 2022-09-19 + ====================== + + A quick fix. + + Not a version at all. + ===================== + + Good stuff. + """ + ), + encoding="utf-8", + ) + + # Make a new fragment, and collect again without changing the version. + (changelog_d / "20170617_nedbat.rst").write_text(FRAG2) + with freezegun.freeze_time("2022-09-18T16:18:19"): + result = cli_invoke(["collect"], expect_ok=False) + assert result.exit_code == 1 + assert str(result.exception) == ( + "Entry 'Not a version at all.' is not a valid version! " + + "If scriv should ignore this heading, add " + + "'scriv-end-here' somewhere before it." + )