Skip to content

Commit 05506f1

Browse files
Add test for entry points (#77)
* Fix blank lines after jinja * Add tests for entry points
1 parent 4c3c371 commit 05506f1

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

grayskull/base/base_recipe.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self, name=None, version=None, load_recipe: str = ""):
4444
self._yaml = yaml.load(yaml_file)
4545
else:
4646
self._yaml = yaml.load(
47-
f'{{% set name = "{name}" %}}\n\n\n'
47+
f'{{% set name = "{name}" %}}\n'
4848
"package:\n name: {{ name|lower }}\n"
4949
)
5050
for section in self.ALL_SECTIONS[1:]:
@@ -98,13 +98,13 @@ def add_jinja_var(self, name: str, value: Any):
9898
else:
9999
self._yaml.ca.comment = [None, []]
100100

101-
self._yaml.ca.comment[1] += [
101+
self._yaml.ca.comment[1].append(
102102
CommentToken(
103-
f'#% set {name} = "{value}" %}}\n\n\n',
103+
f'#% set {name} = "{value}" %}}',
104104
start_mark=CommentMark(0),
105105
end_mark=CommentMark(0),
106106
)
107-
]
107+
)
108108

109109
def update_all_recipe(self):
110110
for section in self.ALL_SECTIONS:
@@ -208,8 +208,9 @@ def get_clean_yaml(self, recipe_yaml: CommentedMap) -> CommentedMap:
208208
def _add_new_lines_after_section(self, recipe_yaml: CommentedMap) -> CommentedMap:
209209
for section in recipe_yaml.keys():
210210
if section == "package":
211-
continue
212-
recipe_yaml.yaml_set_comment_before_after_key(section, "\n")
211+
recipe_yaml.yaml_set_comment_before_after_key(section, "\n\n\n")
212+
else:
213+
recipe_yaml.yaml_set_comment_before_after_key(section, "\n")
213214
return recipe_yaml
214215

215216
def _clean_yaml(self, recipe_yaml: CommentedMap):

grayskull/pypi/pypi.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,15 @@ def print_req(name, list_req: List):
462462
print_req("Host", all_requirements["host"])
463463
print_req("run", all_requirements["run"])
464464

465+
test_entry_points = PyPi._get_test_entry_points(metadata.get("entry_points"))
466+
465467
return {
466468
"package": {"name": name, "version": metadata["version"]},
467469
"build": {"entry_points": metadata.get("entry_points")},
468470
"requirements": all_requirements,
469471
"test": {
470472
"imports": pypi_metadata["name"].replace("-", "_"),
471-
"commands": "pip check",
473+
"commands": ["pip check"] + test_entry_points,
472474
"requires": "pip",
473475
},
474476
"about": {
@@ -482,6 +484,16 @@ def print_req(name, list_req: List):
482484
"source": metadata.get("source", {}),
483485
}
484486

487+
@staticmethod
488+
def _get_test_entry_points(entry_points: Union[List, str]) -> List:
489+
if entry_points:
490+
if isinstance(entry_points, str):
491+
entry_points = [entry_points]
492+
test_entry_points = [
493+
f"{ep.split('=')[0].strip()} --help" for ep in entry_points
494+
]
495+
return test_entry_points
496+
485497
@staticmethod
486498
def _discover_license(metadata: dict) -> Optional[ShortLicense]:
487499
"""Based on the metadata this method will try to discover what is the

tests/test_pypi.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ def test_pytest_recipe_entry_points():
340340
assert recipe["build"]["skip"].values[0].value
341341
assert recipe["build"]["skip"].values[0].selector == "py2k"
342342
assert not recipe["build"]["noarch"]
343+
assert sorted(recipe["test"]["commands"].values) == sorted(
344+
["py.test --help", "pytest --help", "pip check"]
345+
)
343346

344347

345348
def test_cythongsl_recipe_build():
@@ -373,3 +376,12 @@ def test_generic_py_ver_to():
373376
def test_botocore_recipe_license_name():
374377
recipe = PyPi(name="botocore", version="1.15.8")
375378
assert recipe["about"]["license"] == "Apache-2.0"
379+
380+
381+
def test_get_test_entry_points():
382+
assert PyPi._get_test_entry_points("grayskull = grayskull.__main__:main") == [
383+
"grayskull --help"
384+
]
385+
assert PyPi._get_test_entry_points(
386+
["pytest = py.test:main", "py.test = py.test:main"]
387+
) == ["pytest --help", "py.test --help"]

0 commit comments

Comments
 (0)