Skip to content

Commit

Permalink
Merge pull request #431 from twisted/project-coverage
Browse files Browse the repository at this point in the history
Add coverage for _project – 100% coverage baby!
  • Loading branch information
adiroiban committed Sep 23, 2022
2 parents e301d67 + c36426f commit d394d77
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
Empty file.
54 changes: 54 additions & 0 deletions src/towncrier/test/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@
import sys

from subprocess import check_output
from unittest import skipIf

from twisted.trial.unittest import TestCase

from .._project import get_project_name, get_version
from .helpers import write


try:
from importlib.metadata import version
except ImportError:
version = None


class VersionFetchingTests(TestCase):
Expand Down Expand Up @@ -40,6 +48,52 @@ def test_tuple(self):
version = get_version(temp, "mytestproja")
self.assertEqual(version, "1.3.12")

@skipIf(version is None, "Needs importlib.metadata.")
def test_incremental(self):
"""
An incremental Version __version__ is picked up.
"""
pkg = "../src"

self.assertEqual(version("towncrier"), get_version(pkg, "towncrier"))
self.assertEqual("towncrier", get_project_name(pkg, "towncrier"))

def _setup_missing(self):
"""
Create a minimalistic project with missing metadata in a temporary
directory.
"""
tmp_dir = self.mktemp()
pkg = os.path.join(tmp_dir, "missing")
os.makedirs(pkg)
init = os.path.join(tmp_dir, "__init__.py")

write(init, "# nope\n")

return tmp_dir

def test_missing_version(self):
"""
Missing __version__ string leads to an exception.
"""
tmp_dir = self._setup_missing()

with self.assertRaises(Exception) as e:
get_version(tmp_dir, "missing")

self.assertEqual(
("No __version__, I don't know how else to look",), e.exception.args
)

def test_missing_version_project_name(self):
"""
Missing __version__ string leads to the package name becoming the
project name.
"""
tmp_dir = self._setup_missing()

self.assertEqual("Missing", get_project_name(tmp_dir, "missing"))

def test_unknown_type(self):
"""
A __version__ of unknown type will lead to an exception.
Expand Down

0 comments on commit d394d77

Please sign in to comment.