Skip to content

Commit

Permalink
test lint recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
hulkoba committed Jun 10, 2024
1 parent 9120625 commit b0f1640
Showing 1 changed file with 37 additions and 37 deletions.
74 changes: 37 additions & 37 deletions tests/test_lint_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_stdlib_hint(comp_lang):
expected_message = "This recipe is using a compiler"

with tmp_directory() as recipe_dir:
with io.open(Path(recipe_dir) / "meta.yaml", "w") as fh:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
f"""
package:
Expand All @@ -59,7 +59,7 @@ def test_sysroot_hint():
expected_message = "You're setting a requirement on sysroot"

with tmp_directory() as recipe_dir:
with io.open(Path(recipe_dir).joinpath("meta.yaml"), "w") as fh:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
"""
package:
Expand All @@ -79,7 +79,7 @@ def test_osx_hint(where):
expected_message = "You're setting a constraint on the `__osx` virtual"

with tmp_directory() as recipe_dir:
with io.open(Path(recipe_dir) / "meta.yaml", "w") as fh:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
f"""
package:
Expand All @@ -102,7 +102,7 @@ def test_osx_noarch_hint(where):
avoid_message = "You're setting a constraint on the `__osx` virtual"

with tmp_directory() as recipe_dir:
with io.open(Path(recipe_dir) / "meta.yaml", "w") as fh:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
f"""
package:
Expand Down Expand Up @@ -164,9 +164,9 @@ def test_osx_noarch_hint(where):
)
def test_cbc_osx_hints(with_linux, reverse_arch, macdt, v_std, sdk, exp_hint):
with tmp_directory() as rdir:
with open(Path(rdir).joinpath("meta.yaml"), "w") as fh:
with open(Path(rdir, "meta.yaml"), "w") as fh:
fh.write("package:\n name: foo")
with open(Path(rdir).joinpath("conda_build_config.yaml"), "w") as fh:
with open(Path(rdir, "conda_build_config.yaml"), "w") as fh:
if macdt is not None:
fh.write(
f"""\
Expand Down Expand Up @@ -203,7 +203,7 @@ def test_cbc_osx_hints(with_linux, reverse_arch, macdt, v_std, sdk, exp_hint):
# run the linter
_, hints = linter.main(rdir, return_hints=True)
# show CBC/hints for debugging
with open(Path(rdir).joinpath("conda_build_config.yaml"), "r") as fh:
with open(Path(rdir, "conda_build_config.yaml"), "r") as fh:
print("".join(fh.readlines()))
print(hints)
# validate against expectations
Expand Down Expand Up @@ -414,7 +414,7 @@ def test_test_section_with_recipe(self):
lints, hints = linter.lintify_meta_yaml({}, recipe_dir)
self.assertIn(expected_message, lints)

with io.open(Path(recipe_dir).joinpath("run_test.py"), "w") as fh:
with io.open(Path(recipe_dir, "run_test.py"), "w") as fh:
fh.write("# foo")
lints, hints = linter.lintify_meta_yaml({}, recipe_dir)
self.assertNotIn(expected_message, lints)
Expand All @@ -427,7 +427,7 @@ def test_jinja2_vars(self):
)

with tmp_directory() as recipe_dir:
with io.open(Path(recipe_dir).joinpath("meta.yaml"), "w") as fh:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
"""
package:
Expand Down Expand Up @@ -458,7 +458,7 @@ def test_selectors(self):
with tmp_directory() as recipe_dir:

def assert_selector(selector, is_good=True):
with io.open(Path(recipe_dir).joinpath("meta.yaml"), "w") as fh:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
"""
package:
Expand Down Expand Up @@ -499,7 +499,7 @@ def assert_pyXY_selector(meta_string, is_good=False, kind="lint"):
expected_start = "Old-style Python selectors (py27, py34, py35, py36) are deprecated"
else:
expected_start = "Old-style Python selectors (py27, py35, etc) are only available"
with io.open(Path(recipe_dir).joinpath("meta.yaml"), "w") as fh:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(meta_string)
lints, hints = linter.main(recipe_dir, return_hints=True)
if is_good:
Expand Down Expand Up @@ -609,7 +609,7 @@ def test_noarch_selectors(self):
with tmp_directory() as recipe_dir:

def assert_noarch_selector(meta_string, is_good=False):
with io.open(Path(recipe_dir).joinpath("meta.yaml"), "w") as fh:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(meta_string)
lints = linter.main(recipe_dir)
if is_good:
Expand Down Expand Up @@ -757,7 +757,7 @@ def test_suggest_noarch(self):
with tmp_directory() as recipe_dir:

def assert_noarch_hint(meta_string, is_good=False):
with io.open(Path(recipe_dir).joinpath("meta.yaml"), "w") as fh:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(meta_string)
lints, hints = linter.main(recipe_dir, return_hints=True)
if is_good:
Expand Down Expand Up @@ -828,7 +828,7 @@ def test_jinja_os_environ(self):
# Test that we can use os.environ in a recipe. We don't care about
# the results here.
with tmp_directory() as recipe_dir:
with io.open(Path(recipe_dir).joinpath("meta.yaml"), "w") as fh:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
"""
{% set version = os.environ.get('WIBBLE') %}
Expand All @@ -843,14 +843,14 @@ def test_jinja_load_file_regex(self):
# Test that we can use load_file_regex in a recipe. We don't care about
# the results here.
with tmp_directory() as recipe_dir:
with io.open(Path(recipe_dir).joinpath("sha256"), "w") as fh:
with io.open(Path(recipe_dir, "sha256"), "w") as fh:
fh.write(
"""
d0e46ea5fca7d4c077245fe0b4195a828d9d4d69be8a0bd46233b2c12abd2098 iwftc_osx.zip
8ce4dc535b21484f65027be56263d8b0d9f58e57532614e1a8f6881f3b8fe260 iwftc_win.zip
"""
)
with io.open(Path(recipe_dir).joinpath("meta.yaml"), "w") as fh:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
"""
{% set sha256_osx = load_file_regex(load_file="sha256",
Expand All @@ -869,7 +869,7 @@ def test_jinja_load_file_data(self):
# renders conda-build functions to just function stubs to pass the linting.
# TODO: add *args and **kwargs for functions used to parse the file.
with tmp_directory() as recipe_dir:
with io.open(Path(recipe_dir).joinpath("meta.yaml"), "w") as fh:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
"""
{% set data = load_file_data("IDONTNEED", from_recipe_dir=True, recipe_dir=".") %}
Expand All @@ -886,7 +886,7 @@ def test_jinja_load_setup_py_data(self):
# renders conda-build functions to just function stubs to pass the linting.
# TODO: add *args and **kwargs for functions used to parse the file.
with tmp_directory() as recipe_dir:
with io.open(Path(recipe_dir).joinpath("meta.yaml"), "w") as fh:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
"""
{% set data = load_setup_py_data("IDONTNEED", from_recipe_dir=True, recipe_dir=".") %}
Expand All @@ -903,7 +903,7 @@ def test_jinja_load_str_data(self):
# renders conda-build functions to just function stubs to pass the linting.
# TODO: add *args and **kwargs for functions used to parse the data.
with tmp_directory() as recipe_dir:
with io.open(Path(recipe_dir).joinpath("meta.yaml"), "w") as fh:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
"""
{% set data = load_str_data("IDONTNEED", "json") %}
Expand All @@ -917,7 +917,7 @@ def test_jinja_load_str_data(self):
def test_jinja_os_sep(self):
# Test that we can use os.sep in a recipe.
with tmp_directory() as recipe_dir:
with io.open(Path(recipe_dir).joinpath("meta.yaml"), "w") as fh:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
"""
package:
Expand All @@ -933,7 +933,7 @@ def test_target_platform(self):
# Test that we can use target_platform in a recipe. We don't care about
# the results here.
with tmp_directory() as recipe_dir:
with io.open(Path(recipe_dir).joinpath("meta.yaml"), "w") as fh:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
"""
package:
Expand Down Expand Up @@ -1173,7 +1173,7 @@ def test_end_empty_line(self):
bad_contents + [valid_content], [0, 0, 0, 2, 2, 2, 3, 3, 3, 1]
):
with tmp_directory() as recipe_dir:
with io.open(Path(recipe_dir).joinpath("meta.yaml"), "w") as f:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as f:
f.write(content)
lints, hints = linter.lintify_meta_yaml(
{}, recipe_dir=recipe_dir
Expand All @@ -1198,7 +1198,7 @@ def test_end_empty_line(self):

def test_cb3_jinja2_functions(self):
lints = linter.main(
Path(_thisdir).joinpath("recipes", "cb3_jinja2_functions", "recipe")
Path(_thisdir, "recipes", "cb3_jinja2_functions", "recipe")
)
assert not lints

Expand Down Expand Up @@ -1454,19 +1454,19 @@ def test_examples(self):

def test_multiple_sources(self):
lints = linter.main(
Path(_thisdir).joinpath("recipes", "multiple_sources")
Path(_thisdir, "recipes", "multiple_sources")
)
assert not lints

def test_noarch_platforms(self):
lints = linter.main(
Path(_thisdir).joinpath("recipes", "noarch_platforms", "recipe")
Path(_thisdir, "recipes", "noarch_platforms", "recipe")
)
assert not lints

def test_noarch_selector_variants(self):
lints = linter.main(
Path(_thisdir).joinpath("recipes", "noarch_selector_variants")
Path(_thisdir, "recipes", "noarch_selector_variants")
)
assert not lints

Expand Down Expand Up @@ -1583,7 +1583,7 @@ def test_r_base_requirements(self):
)
def test_build_sh_with_shellcheck_findings(self):
lints, hints = linter.main(
Path(_thisdir).joinpath("recipes", "build_script_with_findings"),
Path(_thisdir, "recipes", "build_script_with_findings"),
return_hints=True,
)
assert any(
Expand Down Expand Up @@ -1622,7 +1622,7 @@ def test_mpl_base_hint_outputs(self):
class TestCLI_recipe_lint(unittest.TestCase):
def test_cli_fail(self):
with tmp_directory() as recipe_dir:
with io.open(Path(recipe_dir).joinpath("meta.yaml"), "w") as fh:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
textwrap.dedent(
"""
Expand All @@ -1642,7 +1642,7 @@ def test_cli_fail(self):

def test_cli_success(self):
with tmp_directory() as recipe_dir:
with io.open(Path(recipe_dir).joinpath("meta.yaml"), "w") as fh:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
textwrap.dedent(
"""
Expand Down Expand Up @@ -1673,7 +1673,7 @@ def test_cli_success(self):

def test_cli_environ(self):
with tmp_directory() as recipe_dir:
with io.open(Path(recipe_dir).joinpath("meta.yaml"), "w") as fh:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
textwrap.dedent(
"""
Expand Down Expand Up @@ -1710,7 +1710,7 @@ def test_unicode(self):
"""
with tmp_directory() as recipe_dir:
with io.open(
Path(recipe_dir).joinpath("meta.yaml"), "wt", encoding="utf-8"
Path(recipe_dir, "meta.yaml"), "wt", encoding="utf-8"
) as fh:
fh.write(
"""
Expand Down Expand Up @@ -1740,7 +1740,7 @@ def test_jinja_variable_def(self):
with tmp_directory() as recipe_dir:

def assert_jinja(jinja_var, is_good=True):
with io.open(Path(recipe_dir).joinpath("meta.yaml"), "w") as fh:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
"""
{{% set name = "conda-smithy" %}}
Expand Down Expand Up @@ -1777,13 +1777,13 @@ def test_lint_no_builds():
expected_message = "The feedstock has no `.ci_support` files and "

with tmp_directory() as feedstock_dir:
ci_support_dir = Path(feedstock_dir).joinpath(".ci_support")
ci_support_dir = Path(feedstock_dir, ".ci_support")
ci_support_dir.mkdir(parents=True, exist_ok=True)
with io.open(Path(ci_support_dir).joinpath("README"), "w") as fh:
with io.open(Path(ci_support_dir, "README"), "w") as fh:
fh.write("blah")
recipe_dir = Path(feedstock_dir).joinpath("recipe")
recipe_dir = Path(feedstock_dir, "recipe")
recipe_dir.mkdir(parents=True, exist_ok=True)
with io.open(Path(recipe_dir).joinpath("meta.yaml"), "w") as fh:
with io.open(Path(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
"""
package:
Expand All @@ -1794,7 +1794,7 @@ def test_lint_no_builds():
lints = linter.main(recipe_dir, conda_forge=True)
assert any(lint.startswith(expected_message) for lint in lints)

with io.open(Path(ci_support_dir).joinpath("blah.yaml"), "w") as fh:
with io.open(Path(ci_support_dir, "blah.yaml"), "w") as fh:
fh.write("blah")

lints = linter.main(recipe_dir, conda_forge=True)
Expand Down

0 comments on commit b0f1640

Please sign in to comment.