From 03894fe14778ee0293e38588d73426a39ca64547 Mon Sep 17 00:00:00 2001 From: sigma67 Date: Mon, 29 Jul 2024 12:35:59 +0200 Subject: [PATCH] fix coverage gaps --- src/towncrier/_project.py | 2 +- src/towncrier/test/test_project.py | 59 ++++++++++++++++-------------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/towncrier/_project.py b/src/towncrier/_project.py index 8d00aa03..7b3a98c8 100644 --- a/src/towncrier/_project.py +++ b/src/towncrier/_project.py @@ -61,7 +61,7 @@ def get_version(package_dir: str, package: str) -> str: Try to extract the version from the distribution version metadata that matches `package`, then fall back to looking for the package in `package_dir`. """ - version: str + version: str | None # First try to get the version from the package metadata. if version := _get_metadata_version(package): diff --git a/src/towncrier/test/test_project.py b/src/towncrier/test/test_project.py index 4f1e638e..43928c5c 100644 --- a/src/towncrier/test/test_project.py +++ b/src/towncrier/test/test_project.py @@ -44,34 +44,37 @@ def test_tuple(self): version = get_version(temp, "mytestproja") self.assertEqual(version, "1.3.12") - def test_incremental(self): - """ - An incremental-like Version __version__ is picked up. - """ - temp = self.mktemp() - os.makedirs(temp) - os.makedirs(os.path.join(temp, "mytestprojinc")) - - with open(os.path.join(temp, "mytestprojinc", "__init__.py"), "w") as f: - f.write( - """ - class Version: - ''' - This is emulating a Version object from incremental. - ''' - - def __init__(self, *version_parts): - self.version = version_parts - - def base(self): - return '.'.join(map(str, self.version)) - - - __version__ = Version(1, 3, 12, "rc1") - """ - ) - version = get_version(temp, "mytestprojinc") - self.assertEqual(version, "1.3.12rc1") + def test_incremental(self): + """ + An incremental-like Version __version__ is picked up. + """ + temp = self.mktemp() + os.makedirs(temp) + os.makedirs(os.path.join(temp, "mytestprojinc")) + + with open(os.path.join(temp, "mytestprojinc", "__init__.py"), "w") as f: + f.write( + """ +class Version: + ''' + This is emulating a Version object from incremental. + ''' + + def __init__(self, *version_parts): + self.version = version_parts + + def base(self): + return '.'.join(map(str, self.version)) + +__version__ = Version(1, 3, 12, "rc1") + """ + ) + + version = get_version(temp, "mytestprojinc") + self.assertEqual(version, "1.3.12rc1") + + project = get_project_name(temp, "mytestprojinc") + self.assertEqual(project, "Mytestprojinc") def test_not_incremental(self): """