-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new file to test import of doorstop when not installed.
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
"""Unit tests for the doorstop.__init__ module.""" | ||
import unittest | ||
from importlib import reload | ||
from importlib.metadata import PackageNotFoundError | ||
from unittest.mock import patch | ||
|
||
import doorstop | ||
|
||
|
||
class InitTestCase(unittest.TestCase): | ||
"""Init test class for server tests.""" | ||
|
||
@patch("importlib.metadata.version") | ||
def test_import(self, mock_version): | ||
"""Verify the doorstop package can be imported as a local version. | ||
This test is a bit of a hack. It is intended to verify that the | ||
doorstop package can be imported as a local version. This is | ||
necessary because if the doorstop package is not installed in the | ||
test environment, the version shall be set to "(local)". The patch | ||
ensures that the version lookup will fail. | ||
""" | ||
mock_version.side_effect = PackageNotFoundError() | ||
|
||
# Reload the doorstop package to allow import of the patched version. | ||
reload(doorstop) | ||
from doorstop import VERSION | ||
|
||
# Assert that the version number is correct. | ||
self.assertEqual("Doorstop v(local)", VERSION) |