Skip to content

Commit

Permalink
add an installed-only test of get_version
Browse files Browse the repository at this point in the history
  • Loading branch information
altendky committed Dec 20, 2020
1 parent 08c9e79 commit 221b5d9
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/towncrier/test/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,35 @@ def test_already_installed_import(self):
os.makedirs(os.path.join(sys_path_temp, project_name))

with open(os.path.join(sys_path_temp, project_name, "__init__.py"), "w") as f:
f.write("__version__ = (1, 3, 13)")
f.write("__version__ = (2, 1, 5)")

sys.path.insert(0, sys_path_temp)
self.addCleanup(sys.path.pop, 0)

version = get_version(temp, project_name)

self.assertEqual(version, "1.3.13")
self.assertEqual(version, "2.1.5")

def test_installed_package_found_when_no_source_present(self):
"""
The version from the installed package is returned when there is no
package present at the provided source directory.
"""
project_name = "mytestproj_only_installed"

sys_path_temp = self.mktemp()
os.makedirs(sys_path_temp)
os.makedirs(os.path.join(sys_path_temp, project_name))

with open(os.path.join(sys_path_temp, project_name, "__init__.py"), "w") as f:
f.write("__version__ = (3, 14)")

sys.path.insert(0, sys_path_temp)
self.addCleanup(sys.path.pop, 0)

version = get_version("some non-existent directory", project_name)

self.assertEqual(version, "3.14")


class InvocationTests(TestCase):
Expand Down

0 comments on commit 221b5d9

Please sign in to comment.