Files
mlflow--mlflow/dev/clint/tests/rules/test_unknown_mlflow_function.py
2026-07-13 13:22:34 +08:00

69 lines
1.5 KiB
Python

from pathlib import Path
import pytest
from clint.config import Config
from clint.index import SymbolIndex
from clint.linter import Position, Range, lint_file
from clint.rules.unknown_mlflow_function import UnknownMlflowFunction
def test_unknown_mlflow_function(index: SymbolIndex) -> None:
code = '''
def bad():
"""
.. code-block:: python
import mlflow
mlflow.foo()
"""
def good():
"""
.. code-block:: python
import mlflow
mlflow.log_param("k", "v")
"""
'''
config = Config(select={UnknownMlflowFunction.name}, example_rules=[UnknownMlflowFunction.name])
violations = lint_file(Path("test.py"), code, config, index)
assert len(violations) == 1
assert all(isinstance(v.rule, UnknownMlflowFunction) for v in violations)
assert violations[0].range == Range(Position(7, 8))
@pytest.mark.parametrize("suffix", [".md", ".mdx"])
def test_unknown_mlflow_function_markdown(index: SymbolIndex, suffix: str) -> None:
code = """
# Bad
```python
import mlflow
mlflow.foo()
```
# Good
```python
import mlflow
mlflow.log_param("k", "v")
```
"""
config = Config(
select={UnknownMlflowFunction.name},
example_rules=[UnknownMlflowFunction.name],
)
violations = lint_file(Path("test").with_suffix(suffix), code, config, index)
assert len(violations) == 1
assert all(isinstance(v.rule, UnknownMlflowFunction) for v in violations)
assert violations[0].range == Range(Position(6, 0))