Skip to content

Commit

Permalink
wip: lint recipe 1
Browse files Browse the repository at this point in the history
we need to replace unittest first
  • Loading branch information
hulkoba committed Jul 2, 2024
1 parent 23666de commit 2354226
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 27 deletions.
66 changes: 66 additions & 0 deletions tests/__snapshots__/test_lint_recipe.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# serializer version: 1
# name: test_osx_hint[run]
list([
'You\'re setting a constraint on the `__osx` virtual package directly; this should now be done by adding a build dependence on `{{ stdlib("c") }}`, and overriding `c_stdlib_version` in `recipe/conda_build_config.yaml` for the respective platform as necessary. For further details, please see https://github.com/conda-forge/conda-forge.github.io/issues/2102.',
])
# ---
# name: test_osx_hint[run_constrained]
list([
'You\'re setting a constraint on the `__osx` virtual package directly; this should now be done by adding a build dependence on `{{ stdlib("c") }}`, and overriding `c_stdlib_version` in `recipe/conda_build_config.yaml` for the respective platform as necessary. For further details, please see https://github.com/conda-forge/conda-forge.github.io/issues/2102.',
])
# ---
# name: test_osx_noarch_hint[run]
list([
])
# ---
# name: test_osx_noarch_hint[run_constrained]
list([
])
# ---
# name: test_stdlib_hint[c]
list([
'This recipe is using a compiler, which now requires adding a build dependence on `{{ stdlib("c") }}` as well. Note that this rule applies to each output of the recipe using a compiler. For further details, please see https://github.com/conda-forge/conda-forge.github.io/issues/2102.',
])
# ---
# name: test_stdlib_hint[cxx]
list([
'This recipe is using a compiler, which now requires adding a build dependence on `{{ stdlib("c") }}` as well. Note that this rule applies to each output of the recipe using a compiler. For further details, please see https://github.com/conda-forge/conda-forge.github.io/issues/2102.',
])
# ---
# name: test_stdlib_hint[fortran]
list([
'This recipe is using a compiler, which now requires adding a build dependence on `{{ stdlib("c") }}` as well. Note that this rule applies to each output of the recipe using a compiler. For further details, please see https://github.com/conda-forge/conda-forge.github.io/issues/2102.',
])
# ---
# name: test_stdlib_hint[m2w64_c]
list([
'This recipe is using a compiler, which now requires adding a build dependence on `{{ stdlib("c") }}` as well. Note that this rule applies to each output of the recipe using a compiler. For further details, please see https://github.com/conda-forge/conda-forge.github.io/issues/2102.',
])
# ---
# name: test_stdlib_hint[m2w64_cxx]
list([
'This recipe is using a compiler, which now requires adding a build dependence on `{{ stdlib("c") }}` as well. Note that this rule applies to each output of the recipe using a compiler. For further details, please see https://github.com/conda-forge/conda-forge.github.io/issues/2102.',
])
# ---
# name: test_stdlib_hint[m2w64_fortran]
list([
'This recipe is using a compiler, which now requires adding a build dependence on `{{ stdlib("c") }}` as well. Note that this rule applies to each output of the recipe using a compiler. For further details, please see https://github.com/conda-forge/conda-forge.github.io/issues/2102.',
])
# ---
# name: test_stdlib_hint[rust]
list([
'This recipe is using a compiler, which now requires adding a build dependence on `{{ stdlib("c") }}` as well. Note that this rule applies to each output of the recipe using a compiler. For further details, please see https://github.com/conda-forge/conda-forge.github.io/issues/2102.',
])
# ---
# name: test_stdlib_hints_multi_output
list([
'This recipe is using a compiler, which now requires adding a build dependence on `{{ stdlib("c") }}` as well. Note that this rule applies to each output of the recipe using a compiler. For further details, please see https://github.com/conda-forge/conda-forge.github.io/issues/2102.',
'You\'re setting a requirement on sysroot_linux-<arch> directly; this should now be done by adding a build dependence on `{{ stdlib("c") }}`, and overriding `c_stdlib_version` in `recipe/conda_build_config.yaml` for the respective platform as necessary. For further details, please see https://github.com/conda-forge/conda-forge.github.io/issues/2102.',
'You\'re setting a constraint on the `__osx` virtual package directly; this should now be done by adding a build dependence on `{{ stdlib("c") }}`, and overriding `c_stdlib_version` in `recipe/conda_build_config.yaml` for the respective platform as necessary. For further details, please see https://github.com/conda-forge/conda-forge.github.io/issues/2102.',
])
# ---
# name: test_sysroot_hint
list([
'You\'re setting a requirement on sysroot_linux-<arch> directly; this should now be done by adding a build dependence on `{{ stdlib("c") }}`, and overriding `c_stdlib_version` in `recipe/conda_build_config.yaml` for the respective platform as necessary. For further details, please see https://github.com/conda-forge/conda-forge.github.io/issues/2102.',
])
# ---
41 changes: 14 additions & 27 deletions tests/test_lint_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ def tmp_directory():
"comp_lang",
["c", "cxx", "fortran", "rust", "m2w64_c", "m2w64_cxx", "m2w64_fortran"],
)
def test_stdlib_hint(comp_lang):
expected_message = "This recipe is using a compiler"

def test_stdlib_hint(comp_lang, snapshot):
with tmp_directory() as recipe_dir:
with io.open(os.path.join(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
Expand All @@ -51,12 +49,10 @@ def test_stdlib_hint(comp_lang):
)

_, hints = linter.main(recipe_dir, return_hints=True)
assert any(h.startswith(expected_message) for h in hints)

assert hints == snapshot()

def test_sysroot_hint():
expected_message = "You're setting a requirement on sysroot"

def test_sysroot_hint(snapshot):
with tmp_directory() as recipe_dir:
with io.open(os.path.join(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
Expand All @@ -70,13 +66,12 @@ def test_sysroot_hint():
)

_, hints = linter.main(recipe_dir, return_hints=True)
assert any(h.startswith(expected_message) for h in hints)
assert hints == snapshot


@pytest.mark.parametrize("where", ["run", "run_constrained"])
def test_osx_hint(where):
expected_message = "You're setting a constraint on the `__osx` virtual"

@pytest.mark.parametrize("where", ["run", "run_constrained"])
def test_osx_hint(where, snapshot):
with tmp_directory() as recipe_dir:
with io.open(os.path.join(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
Expand All @@ -91,12 +86,11 @@ def test_osx_hint(where):
)

_, hints = linter.main(recipe_dir, return_hints=True)
assert any(h.startswith(expected_message) for h in hints)
assert hints == snapshot


def test_stdlib_hints_multi_output():
expected_message = "You're setting a requirement on sysroot"

def test_stdlib_hints_multi_output(snapshot):
with tmp_directory() as recipe_dir:
with io.open(os.path.join(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
Expand Down Expand Up @@ -132,20 +126,13 @@ def test_stdlib_hints_multi_output():
)

_, hints = linter.main(recipe_dir, return_hints=True)
exp_stdlib = "This recipe is using a compiler"
exp_sysroot = "You're setting a requirement on sysroot"
exp_osx = "You're setting a constraint on the `__osx`"
assert any(h.startswith(exp_stdlib) for h in hints)
assert any(h.startswith(exp_sysroot) for h in hints)
assert any(h.startswith(exp_osx) for h in hints)
assert hints == snapshot


@pytest.mark.parametrize("where", ["run", "run_constrained"])
def test_osx_noarch_hint(where):
def test_osx_noarch_hint(where, snapshot):
# don't warn on packages that are using __osx as a noarch-marker, see
# https://conda-forge.org/docs/maintainer/knowledge_base/#noarch-packages-with-os-specific-dependencies
avoid_message = "You're setting a constraint on the `__osx` virtual"

with tmp_directory() as recipe_dir:
with io.open(os.path.join(recipe_dir, "meta.yaml"), "w") as fh:
fh.write(
Expand All @@ -159,7 +146,7 @@ def test_osx_noarch_hint(where):
)

_, hints = linter.main(recipe_dir, return_hints=True)
assert not any(h.startswith(avoid_message) for h in hints)
assert hints == snapshot


@pytest.mark.parametrize(
Expand Down Expand Up @@ -276,9 +263,9 @@ def test_pin_compatible_in_run_exports(self):
"run_exports": ["compatible_pin apackage"],
},
}
lints, hints = linter.lintify_meta_yaml(meta)
lints, _ = linter.lintify_meta_yaml(meta)
expected = "pin_subpackage should be used instead"
self.assertTrue(any(lint.startswith(expected) for lint in lints))
self.assertTrueTrue(any(lint.startswith(expected) for lint in lints))

def test_pin_compatible_in_run_exports_output(self):
meta = {
Expand All @@ -294,7 +281,7 @@ def test_pin_compatible_in_run_exports_output(self):
}
],
}
lints, hints = linter.lintify_meta_yaml(meta)
lints, _ = linter.lintify_meta_yaml(meta)
expected = "pin_compatible should be used instead"
self.assertTrue(any(lint.startswith(expected) for lint in lints))

Expand Down

0 comments on commit 2354226

Please sign in to comment.