Skip to content

Commit

Permalink
Add test for entry points (#77)
Browse files Browse the repository at this point in the history
* Fix blank lines after jinja

* Add tests for entry points
  • Loading branch information
marcelotrevisani authored Mar 1, 2020
1 parent 4c3c371 commit 05506f1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
13 changes: 7 additions & 6 deletions grayskull/base/base_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, name=None, version=None, load_recipe: str = ""):
self._yaml = yaml.load(yaml_file)
else:
self._yaml = yaml.load(
f'{{% set name = "{name}" %}}\n\n\n'
f'{{% set name = "{name}" %}}\n'
"package:\n name: {{ name|lower }}\n"
)
for section in self.ALL_SECTIONS[1:]:
Expand Down Expand Up @@ -98,13 +98,13 @@ def add_jinja_var(self, name: str, value: Any):
else:
self._yaml.ca.comment = [None, []]

self._yaml.ca.comment[1] += [
self._yaml.ca.comment[1].append(
CommentToken(
f'#% set {name} = "{value}" %}}\n\n\n',
f'#% set {name} = "{value}" %}}',
start_mark=CommentMark(0),
end_mark=CommentMark(0),
)
]
)

def update_all_recipe(self):
for section in self.ALL_SECTIONS:
Expand Down Expand Up @@ -208,8 +208,9 @@ def get_clean_yaml(self, recipe_yaml: CommentedMap) -> CommentedMap:
def _add_new_lines_after_section(self, recipe_yaml: CommentedMap) -> CommentedMap:
for section in recipe_yaml.keys():
if section == "package":
continue
recipe_yaml.yaml_set_comment_before_after_key(section, "\n")
recipe_yaml.yaml_set_comment_before_after_key(section, "\n\n\n")
else:
recipe_yaml.yaml_set_comment_before_after_key(section, "\n")
return recipe_yaml

def _clean_yaml(self, recipe_yaml: CommentedMap):
Expand Down
14 changes: 13 additions & 1 deletion grayskull/pypi/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,13 +462,15 @@ def print_req(name, list_req: List):
print_req("Host", all_requirements["host"])
print_req("run", all_requirements["run"])

test_entry_points = PyPi._get_test_entry_points(metadata.get("entry_points"))

return {
"package": {"name": name, "version": metadata["version"]},
"build": {"entry_points": metadata.get("entry_points")},
"requirements": all_requirements,
"test": {
"imports": pypi_metadata["name"].replace("-", "_"),
"commands": "pip check",
"commands": ["pip check"] + test_entry_points,
"requires": "pip",
},
"about": {
Expand All @@ -482,6 +484,16 @@ def print_req(name, list_req: List):
"source": metadata.get("source", {}),
}

@staticmethod
def _get_test_entry_points(entry_points: Union[List, str]) -> List:
if entry_points:
if isinstance(entry_points, str):
entry_points = [entry_points]
test_entry_points = [
f"{ep.split('=')[0].strip()} --help" for ep in entry_points
]
return test_entry_points

@staticmethod
def _discover_license(metadata: dict) -> Optional[ShortLicense]:
"""Based on the metadata this method will try to discover what is the
Expand Down
12 changes: 12 additions & 0 deletions tests/test_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ def test_pytest_recipe_entry_points():
assert recipe["build"]["skip"].values[0].value
assert recipe["build"]["skip"].values[0].selector == "py2k"
assert not recipe["build"]["noarch"]
assert sorted(recipe["test"]["commands"].values) == sorted(
["py.test --help", "pytest --help", "pip check"]
)


def test_cythongsl_recipe_build():
Expand Down Expand Up @@ -373,3 +376,12 @@ def test_generic_py_ver_to():
def test_botocore_recipe_license_name():
recipe = PyPi(name="botocore", version="1.15.8")
assert recipe["about"]["license"] == "Apache-2.0"


def test_get_test_entry_points():
assert PyPi._get_test_entry_points("grayskull = grayskull.__main__:main") == [
"grayskull --help"
]
assert PyPi._get_test_entry_points(
["pytest = py.test:main", "py.test = py.test:main"]
) == ["pytest --help", "py.test --help"]

0 comments on commit 05506f1

Please sign in to comment.