|
4 | 4 | import zipimport
|
5 | 5 |
|
6 | 6 | import pkg_resources
|
| 7 | +import pytest |
7 | 8 |
|
8 | 9 | from pex.finders import ChainedFinder
|
9 | 10 | from pex.finders import _add_finder as add_finder
|
10 | 11 | from pex.finders import _remove_finder as remove_finder
|
11 |
| -from pex.finders import find_eggs_in_zip, get_script_from_egg |
| 12 | +from pex.finders import find_eggs_in_zip, get_entry_point_from_console_script, get_script_from_egg |
12 | 13 |
|
13 | 14 | try:
|
14 | 15 | import mock
|
@@ -118,3 +119,32 @@ def test_get_script_from_egg():
|
118 | 119 |
|
119 | 120 | assert location is None
|
120 | 121 | assert content is None
|
| 122 | + |
| 123 | + |
| 124 | +class FakeDist(object): |
| 125 | + def __init__(self, key, console_script_entry): |
| 126 | + self.key = key |
| 127 | + script = console_script_entry.split('=')[0].strip() |
| 128 | + self._entry_map = {'console_scripts': {script: console_script_entry}} |
| 129 | + |
| 130 | + def get_entry_map(self): |
| 131 | + return self._entry_map |
| 132 | + |
| 133 | + |
| 134 | +def test_get_entry_point_from_console_script(): |
| 135 | + dists = [FakeDist(key='fake', console_script_entry='bob= bob.main:run'), |
| 136 | + FakeDist(key='fake', console_script_entry='bob =bob.main:run')] |
| 137 | + assert 'bob.main:run' == get_entry_point_from_console_script('bob', dists) |
| 138 | + |
| 139 | + |
| 140 | +def test_get_entry_point_from_console_script_conflict(): |
| 141 | + dists = [FakeDist(key='bob', console_script_entry='bob= bob.main:run'), |
| 142 | + FakeDist(key='fake', console_script_entry='bob =bob.main:run')] |
| 143 | + with pytest.raises(RuntimeError): |
| 144 | + get_entry_point_from_console_script('bob', dists) |
| 145 | + |
| 146 | + |
| 147 | +def test_get_entry_point_from_console_script_dne(): |
| 148 | + dists = [FakeDist(key='bob', console_script_entry='bob= bob.main:run'), |
| 149 | + FakeDist(key='fake', console_script_entry='bob =bob.main:run')] |
| 150 | + assert None is get_entry_point_from_console_script('jane', dists) |
0 commit comments