-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
49a8945
commit ce816e2
Showing
6 changed files
with
67 additions
and
27 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
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
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,41 @@ | ||
import sys | ||
from importlib.metadata import DistributionFinder, PathDistribution | ||
from os import path | ||
from pathlib import Path | ||
|
||
|
||
class DummyDistributionFinder(DistributionFinder): | ||
""" | ||
Injects a dummy distribution into the meta path finder, so that we can | ||
pretend like it's been pip installed during unit tests (i.e., so that we | ||
can test ``EntryPointsClassRegistry``), without polluting the persistent | ||
virtualenv. | ||
""" | ||
|
||
DUMMY_PACKAGE_DIR = 'filter_extension.egg-info' | ||
|
||
@classmethod | ||
def install(cls): | ||
for finder in sys.meta_path: | ||
if isinstance(finder, cls): | ||
# If we've already installed an instance of the class, then | ||
# something is probably wrong with our tests. | ||
raise ValueError(f'{cls.__name__} is already installed') | ||
|
||
sys.meta_path.append(cls()) | ||
|
||
@classmethod | ||
def uninstall(cls): | ||
for i, finder in enumerate(sys.meta_path): | ||
if isinstance(finder, cls): | ||
sys.meta_path.pop(i) | ||
return | ||
else: | ||
# If we didn't find an installed instance of the class, then | ||
# something is probably wrong with our tests. | ||
raise ValueError(f'{cls.__name__} was not installed') | ||
|
||
def find_distributions(self, context=...) -> list[PathDistribution]: | ||
return [PathDistribution( | ||
Path(path.join(path.dirname(__file__), self.DUMMY_PACKAGE_DIR)) | ||
)] |
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
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[tox] | ||
envlist = py3{11,10,9} | ||
envlist = py3{12,11,10} | ||
|
||
[testenv] | ||
commands = python -m unittest |