Skip to content

Commit

Permalink
Added new file to test import of doorstop when not installed.
Browse files Browse the repository at this point in the history
  • Loading branch information
neerdoc committed Jan 25, 2024
1 parent 6834d6a commit aabbe88
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions doorstop/tests/test_init.py
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)

0 comments on commit aabbe88

Please sign in to comment.